Use advanced logging

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Redaction MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

On this page

You can implement ILogger interface from com.groupdocs.redaction.options package. This interface requires to implement three methods. Once implemented, you can use it to track error log records:

public class CustomLogger implements ILogger
{
    private ArrayList<String> _errors = new ArrayList<String>();
    private ArrayList<String> _traces = new ArrayList<String>();
    private ArrayList<String> _warnings = new ArrayList<String>();

    public boolean hasErrors()
    {
        return _errors.size() > 0;
    }

    public void error(String message)
    {
        _errors.add(message);
    }

    public void trace(String message)
    {
        _traces.add(message);
    }

    public void warning(String message)
    {
        _warnings.add(message);
    }
}

CustomLogger logger = new CustomLogger();
final Redactor redactor = new Redactor("sample.docx", new LoadOptions(), new RedactorSettings(logger));
try
{
    // Here we can use document instance to perform redactions
    redactor.apply(new DeleteAnnotationRedaction());
    if (!logger.hasErrors())
    {
        redactor.save();
    }
}
finally { redactor.close(); }

sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 1.2 MB)

Download full output

On this page