| Back | Main view

Logging in IMiS/Storage Connector JAVA

Product:IMiS/Storage Connector JAVA
Release:3.1.1204
Date:05/09/2012

Case: IMiS/Storage Connector JAVA implements it's own logging with the use of either internal log handler or custom log handler(s). This article explains internal logging, the use of custom log handlers, logging level and output formating.

Description:

Internal logging

IMiS/Storage Connector JAVA provides internal logging that can be enabled with a call of logInternal() method on an instance of the com.imis.storageconnector.StorageConnector class with parameter true. IMiS/Storage Connector uses java.util.logging.FileHandler to create the rotating log files IMiS.StorageConnector.X.log in:
* the system temporary folder on Windows systems (ie. System.getProperty("java.io.tmpdir"))
* the user home folder otherwise (ie. System.getProperty("user.home")).

JAVA

// Get an instance of the IMiS/Storage Connector
com.imis.storageconnector.StorageConnector sc = com.imis.storageconnector.StorageConnector.getInstance();

// Enable internal logger
sc.logInternal(true);
Custom log handlers

Users can enable IMiS/Storage Connector JAVA logging with a custom log handler (i.e. classes derived from java.util.logging.Handler class) attached to the IMiS/Storage Connector logger using com.imis.storageconnector.StorageConnector.logAddHandler() method. Output is determined by the log handler. Log messages can be written to a file, send to network logging service, outputted to console, or whatever.

For example, to create a file log, you can use java.util.logging.FileHandler instance as the log handler.

JAVA

// Get an instance of the IMiS/Storage Connector
com.imis.storageconnector.StorageConnector sc = com.imis.storageconnector.StorageConnector.getInstance();

// Create custom log handler
java.util.logging.FileHandler fileLog = new java.util.logging.FileHandler("/isc.log", 1000000, 10, true); // file handler that outputs to rotating file log

// Add log handler to IMiS/Storage Connector logger
sc.logAddHandler(fileLog);
Logging level & output formatting

Users can set the logging level of the IMiS/Storage Connector JAVA logger with the com.imis.storageconnector.StorageConnector.logSetLevel() method. Use one of the java.util.logging.Level values to control logging output to log handlers. Enabling logging at a given level also enables logging at all higher levels. For example, setting logging level to java.util.logging.Level.INFO will also log warning and error messages.

Users can also set logging level on a custom log handler. For example, you can set the logging level of the IMiS/Storage Connector logger to java.util.logging.Level.INFO and the logging level on a log handler to java.util.logging.Level.SEVERE.

Custom log handler's output formatting can be done with the help of a custom formatter (i.e. class derived from java.util.logging.Formatter class), which is assigned to a log handler with the java.util.logging.Handler.setFormatter() method. For example, IMiS/Storage Connector internal logging uses formatter for detailed output that includes log entry date, time, thread, class and method name, followed by the message.

JAVA

// Get an instance of the IMiS/Storage Connector
com.imis.storageconnector.StorageConnector sc = com.imis.storageconnector.StorageConnector.getInstance();

// Set logging level of IMiS/Storage Connector logger
sc.logSetLevel(java.util.logging.Level.FINEST);

// Create custom log handler
java.util.logging.FileHandler fileLog = new java.util.logging.FileHandler("/isc.log", 1000000, 10, true); // file handler that outputs to rotating file log
fileLog.setFormatter(new com.imis.util.logging.DetailedFormatter(fileLog)); // set a formatter for the file handler
fileLog.setLevel(java.util.logging.Level.INFO); // set logging level of the log handler

// Add log handler to IMiS/Storage Connector logger
sc.logAddHandler(fileLog);
Related Documents:



| Back | Main view