How to enable logging in the Maverick Synergy Java SSH API

The Maverick Synergy Java SSH API uses an internal logging mechanism so that no logging framework is enforced upon developers using the API. This comes with the benefit that logging can easily be isolated for support purposes and then our logging does not complicate or infect your own logging output. 

The following log levels are available to you:

NONEDo not log anything
ERRORLog any errors that are caught during the API operation
WARNPotential configuration problems or harmful situations
INFOInformational messages about API operation suitable for production use
DEBUGFine-grained information for debugging and support purposes
TRACEEven finer-grained information including binary data input/output designed for debugging and support purposes

You can enable logging in a number of ways. The most simple way to enable logging is to programmatically enable it from your own code. For example, to enable logging to the console call:

Log.getDefaultContext().enableConsole(Level.DEBUG);

If you would prefer to log to file, you can call:

Log.getDefaultContext().enableFile(
                       Level.DEBUG, "synergy.log");

Logging Configuration

You can control much more of the logging options by creating a logging configuration file. By default, this should be in a file called logging.properties in the current working directory of the process.

You can override the default location and file name by setting the system property:

-Dmaverick.log.config=synergy.properties

This logging configuration file is watched by the API so any changes you make to the file during runtime will cause the logging configuration to be reloaded. For example, if you experiencing problems during a running application you can enable DEBUG logs simply by editing the logging.properties file. 

Watching the configuration file involves a thread. If you do not want this behavior you can disable it using the maverick.log.nothread property setting it to a value of true. The API installs a shutdown hook to tear this thread down, however, there are circumstances where this is too late and applications like Tomcat Servlet Container can complain about memory leaks. You can alternatively force the shutdown of this thread from your own application using:

Log.shutdown();

If you do not include or set up logging.properties, you can set any of the following properties as System properties on your Java command line.

Logging Options

OptionDefault ValueDescription
maverick.log.consolefalseEnable logging to the console
maverick.log.console.levelINFOSet the level at which the console will log
maverick.log.filefalseEnable logging to file
maverick.log.file.levelINFOSet the level for logging to file
maverick.log.file.pathsynergy.logThe path to the log file
maverick.log.file.maxFiles10The maximum number of rolling log files
maverick.log.file.maxSize20MBThe maximum size of each rolling log file
maverick.log.nothreadfalsePrevent the logging system from creating a watcher thread on logging.properties configuration file.