Logging

By default, logging is disabled when rendering documents. You can log to a file.

To log to a text file, use the FileLogger class.

The log contains the following four types of messages:

  • Error means unrecoverable exceptions
  • Warning means recoverable/expected exceptions
  • Debug means debug information
  • Trace means general information

The following code snippet shows how to log to a file using the FileLogger class:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.ViewerSettings;
import com.groupdocs.viewer.logging.FileLogger;
import com.groupdocs.viewer.options.HtmlViewOptions;
import com.groupdocs.viewer.options.ViewOptions;
// ...

// Create logger and specify the output file
FileLogger fileLogger = new FileLogger("output.log");

// Create ViewerSettings and specify FileLogger
ViewerSettings viewerSettings = new ViewerSettings(fileLogger);

try (Viewer viewer = new Viewer("sample.pdf", viewerSettings)) {
    ViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources("result.html");

    viewer.view(viewOptions);
}

The following image shows the output.log file: