Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Introduction to HydraExpress
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.4 Creating and Using Custom Loggers

There are two approaches to using a custom logger:

6.4.1 Defining Your Logger

The first step is to define your logger in <installdir>\conf\loggers.xml. Here is an example:

//1Defines a logger named mylog that writes to the file c:\logs\mylog.log.
//2Defines essentially a new logger, based on the file logger just defined, which writes log messages at the level INFO and above. You could define yet another logger, say mylog.error, which wrote messages only at the ERROR or FATAL levels.

6.4.2 Using Your Logger

You can either make your logger an Agent default logger, or a separate logger for logging just your messages.

6.4.2.1 Making Your Logger a Default Logger

The easiest way to do this is by adding your logger to the splitter definition in loggers.xml that defines the multiple outputs for the Agent default logger. A splitter definition can only name two loggers in its properties, so you must either replace one of the existing properties, or create a secondary splitter.

Here is how you would make your logger the alternative to writing log output to <installdir>\logs\agent.log:

If you still want Agent output written to agent.log, but want it also to go to your log file, you must create a secondary splitter that is referenced from the main one:

With these definitions in place, you would now write your messages to the default Agent logger exactly as described in Section 6.3.

6.4.2.2 Separating Your Log Messages from the Agent Messages

To log your messages separately from Agent messages, you need to define your logger as described in Section 6.4.1, but you do not have to add anything else to loggers.xml.

To use a custom logger named mylog.info in a custom C++ service, do the following:

All messages logged with logger go to the output file defined for mylog.info. These messages do not go to the outputs defined for Agent messages, and Agent messages do not go to the output file defined for your logger.

6.4.3 Creating a Rotating Log File

A rotating log is one that allows you to set a file size limitation, limit the number of timestamped files, and perform cleanup on old timestamped files as specified. It maintains log entries across Agent restarts. You can designate the maximum size of files to maintain, the number of old timestamped files to keep in a directory, and whether or not to cleanup old timestamped entries.

The properties and their available values are:

mode

append or overwrite

measurement

bit, byte, kb, mb, gb

measuresize

Any number corresponding to the measurement type

cleanup

y or n

logfilenum

The number of timestamped log files to keep in a directory.

logdir

The name of the directory used to maintain log files.

To use the rotating log functionality, remove the comment tags from this section of the loggers.xml file and set the property values as desired.

For example, these settings will produce a maximum of 10 log files in the ${RWSF_HOME}/logs/ directory of up to 1 mb each, for a total of potentially 10 mb of log information at any one time. The value of cleanup is set to y, so that once the number of files or the file size exceeds the specified limit, old timestamped log files will be removed.


WARNING: If cleanup is set to n and mode is set to append, log files will continue to accumulate and user action is required to monitor their size and determine if cleanup is needed.


Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.