dist_tools/

mg_log.pro

MG_LOG is a convenience routine so that the MGffLogger object does not
need to be explicitly stored by the application using the logging. If more
than one logger is required, then named loggers can be used using the NAME
keyword.

The error levels are: critical (level 1), error (level 2), warning
(level 3), informational (level 4), debug (level 5). Only log messages with
a level less than or equal to the current logger level are actually
recorded. So if a logger is set to level 3 (warnings), then log messages
with levels 1 (critical), 2 (error), or 3 (warning) would be displayed, but
log messages with levels 4 (informational) or 5 (debug) would be ignored.

Named subloggers can be created using the NAME keyword. These subloggers
should be used for individual applications or functional areas of an
application.

For example, the following starts the logging framework and creates a
logger object with name "mg_example" returned via the LOGGER keyword:

mg_log, name='mg_example', logger=logger

This logger would next be configured, i.e., set its level, specify a file
for log messages to written to, set a format for log messages, etc. For
example, to log critical errors, errors, and warnings to the file
my_application.log, do:

logger->setProperty, level=3, filename='my_application.log'

Later, messages can be sent to this logger by using the name used
previously:

mg_log, 'A problem occurred!', /warning, name='mg_example'

Further refinement can be done with a hierarchy of names. The following
creates a new sublogger:

mg_log, name='mg_example/gui', logger=gui_logger

This type of hierarchy is useful for applications with subsystems with
independent level values. The effective log level for log messages sent to a
sublogger is the most restrictive log level from all the parent loggers. For
example, if the level of gui_logger was set to "Informational" with:

gui_logger->setProperty, level=4

Then informational log messages would not be logged because the parent
logger, "mg_example", has a level of 3, i.e., "Warning".

Examples

Try the main-level program at the end of this file for a longer example.
To run it, do: