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

Note: The samples on this page are Java classes from the GroupDocs.Redaction for Java API. Use them from Node.js via Java by placing the classes on the JVM classpath, or by wrapping the same interfaces with java.newProxy.

You can implement ILogger interface from com.groupdocs.redaction.options package. This interface requires to implement three methods:

import com.groupdocs.redaction.options.ILogger;
import java.util.ArrayList;
/**
 * <p>
 * This is an example of ILogger implementation, tracking count of error messages.
 * </p>
 */
public class CustomLogger implements ILogger
{
    private ArrayList<String> _errors;
    private ArrayList<String> _traces;
    private ArrayList<String> _warnings;
    public boolean hasErrors() 
    { 
        return _errors.size() > 0; 
    }
    public CustomLogger()
    {
        _errors = new ArrayList<String>();
        _traces = new ArrayList<String>();
        _warnings = new ArrayList<String>();
    }
    public void error(String message)
    {
        _errors.add(message);
    }
    public void trace(String message)
    {
        _traces.add(message);
    }
    public void warning(String message)
    {
        _warnings.add(message);
    }
}

Once implemented, you can use it to track error log records:

CustomLogger logger = new CustomLogger();
final Redactor redactor = new Redactor(Constants.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(); }

On this page