By default logging is disabled when processing documents, but the product provides a way to pass your own logger implementation and use it while processing documents.
There is an interface that we can utilize:
ILogger - defines the interface for logging different process event like errors, warnings and information messages (traces).
There are 3 types of messages in the log file:
Error - for unrecoverable exceptions
Warning - for recoverable/expected/known exceptions
Trace - for general information
Implementing custom logger
To make your logger you should implement ILogger interface.
For trace messages - implement the public void trace(String message) method For warning messages - implement the public void warning(String message) method For error messages - implement the public void error(String message, Exception exception) method
Which of the three methods are called depends on the log level set with the setLogLevel method of SignatureSettings. See Set up logging.
In this example, we’ll implement a logger that writes messages in its own format. Replace the postMessage method to send them to a log file, a logging framework or an API endpoint.
// Create the custom logger
CustomLoggerlogger=newCustomLogger();// Create SignatureSettings and specify the custom logger
SignatureSettingssettings=newSignatureSettings(logger);Signaturesignature=newSignature("sample.docx",settings);try{QrCodeSignOptionsoptions=newQrCodeSignOptions("JohnSmith");// sign document to file
signature.sign(outputFilePath,options);}finally{signature.dispose();}/**
* Writes log messages in a custom format. Replace postMessage to send them
* to a log file, a logging framework or an API endpoint.
*/publicstaticclassCustomLoggerimplementsILogger{privatefinalObjectlock=newObject();/**
* Error log messages provide information about unrecoverable events in application flow.
*/publicvoiderror(Stringmessage,Exceptionexception){if(message==null)thrownewIllegalArgumentException("message");if(exception==null)thrownewIllegalArgumentException("exception");postMessage(LogLevel.Error,message+". Exception: "+exception);}/**
* Trace log messages provide generally useful information about application flow.
*/publicvoidtrace(Stringmessage){if(message==null)thrownewIllegalArgumentException("message");postMessage(LogLevel.Trace,message);}/**
* Warning log messages provide information about the unexpected and recoverable event in application flow.
*/publicvoidwarning(Stringmessage){if(message==null)thrownewIllegalArgumentException("message");postMessage(LogLevel.Warning,message);}privatevoidpostMessage(intlevel,Stringmessage){Stringheader="INFO";switch(level){caseLogLevel.Warning:header="WARNING";break;caseLogLevel.Error:header="ERROR";break;}Stringdate=newSimpleDateFormat("MM/dd/yyyy hh:mm a").format(newDate());Stringline="GroupDocs.Signature "+header+" ["+date+"]. Message: "+message;synchronized(lock){System.out.println(line);}}}
The CustomLogging class of the Java examples uses this logger.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.