Jump to: navigation, search

Setting up logging in Platform SDK

Logging for Java

Setting up log4j logging

The easiest way to set up Platform SDK logging in Java is to use the built-in integration with log4j. There are two possible ways to do this:

  • Using code, by creating a Log4JLoggerFactoryImpl instance and setting it as the global logger factory for Platform SDK at the beginning of your program, like this:
com.genesyslab.platform.commons.log.Log.setLoggerFactory(new Log4JLoggerFactoryImpl());

Or:

  • Using a Java system variable, by setting com.genesyslab.platform.commons.log.loggerFactory to the fully qualified name of the ILoggerFactory implementation class. For example, to set up log4j as the logging implementation you can start your application using the following command:
java -Dcom.genesyslab.platform.commons.log.loggerFactory=com.genesyslab.platform.commons.log.Log4JLoggerFactoryImpl <MyMainClass>

Providing a custom logging implementation

If log4j does not fit your needs, it is also possible to provide your own implementation of logging.

In order to do that, you will need to complete the following steps:

  1. Implement the ILogger interface, which contains the methods that the Platform SDK uses for logging messages, by extending the AbstractLogger class.
  2. Implement the ILoggerFactory interface, which should create instances of your ILogger implementation.
  3. Finally, set up your ILoggerFactory implementation as the global Platform SDK LoggerFactory, as described above.


Logging for .NET

Setting up logging

For .NET development, the EnableLogging method allows logging to be easily set up for any classes that implement the ILogEnabled interface. This includes:

  • All protocol classes: TServerProtocol, StatServerProtocol, etc.
  • The WarmStandbyService class of the Warm Standby Application Block.

For example:

tserverProtocol.EnableLogging(new MyLoggerImpl());

Providing a Custom Logging Implementation

You can provide your custom logging functionality by implementing the ILogger interface. Samples of how to do this are provided in the following section.

Samples

You can download some samples of classes that implement the ILogger interface:

  • AbstractLogger: This class can make it easier to implement a custom logger, by providing a default implementation of ILogger methods.
  • TraceSourceLogger: A logger that uses the .NET TraceSource framework. It adapts the Platform SDK logger hierarchy to the non-hierarchical TraceSource configuration.
  • Log4netLogger: A logger that uses the log4net libraries.
This page was last modified on July 23, 2015, at 04:47.

Feedback

Comment on this article:

blog comments powered by Disqus