Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

Qmms::Log::PropertyConfigurator Class Reference

Class of static methods that configures the qmmslog system from a properties file. More...

#include <log.hh>

Inheritance diagram for Qmms::Log::PropertyConfigurator::

Qmms::Log::BasicConfigurator List of all members.

Public Methods

 PropertyConfigurator ()
 Constructor does nothing. More...

 ~PropertyConfigurator ()
 Destructor does nothing. More...


Static Public Methods

void configure ()
 Configures the qmmslog system from the file whose name is held in the const static string DEFAULT_PROPERTIES. More...

void configure (const QString filename)
 Same as configure(), except it reads the given properties file. More...

void configureWQt ()
 Configures the qmmslog system from the default properties, and routes Qt debugging output (qDebug, qWarn, qFatal) through qmmslog. More...

void configureWQt (const QString filename)
 Same as configureWQt(), but uses the given filename for the configuration. More...

void summarize ()

Static Protected Methods

void parseFile (const QString filename)
 Parses the given file into a StrListMap. More...

void addLevels ()
 Iterates through the propMap, looking for the "qmmslog.level" key. More...

void parseAppenders ()
 Iterates through the propMap and creates the specified appenders. More...

bool verifyAppenderExists (QString name)
 Checks whether the named appender is in the QDict of appenders. More...

void configureRoot ()
 Creates and configures the Root Category. More...

void parseCategories ()
 Creates and configures all the Categories (except for Root). More...

void configureInternalLogging ()
 Configure internal logging system (LogLog). More...


Static Protected Attributes

AppDict apdrDict
 A QDict of appenders used to store pointers to all the Appenders created by PropertyConfigurator. More...

StrListMap propMap
 A QMap with QStrings as keys, and QStringLists as values. More...


Static Private Attributes

const QString CATEGORY_PREFIX
 The string "qmmslog.category". More...

const QString ROOTCATEGORY_PREFIX
 The string "qmmslog.rootCategory". More...

const QString APPENDER_PREFIX
 The string "qmmslog.appender". More...

const QString LEVEL_PREFIX
 The string "qmmslog.level". More...

const QString DEFAULT_PROPERTIES
 The string ".qmmslogrc". More...

const QString DEBUG_PREFIX
 The string "qmmslog.debug". More...


Detailed Description

Class of static methods that configures the qmmslog system from a properties file.

This file must be in the following format:

 qmmslog.appender.<appenderName>=<fully-qualified-appender-class-name>
 qmmslog.appender.<appenderName>.layout=<fully-qualified-layout-class-name>
 qmmslog.appender.<appenderName>.layout.pattern=<pattern string>
 qmmslog.appender.<appenderName>.filename=<file-to-log-to>[, <file-to-log-to>, ...]
 qmmslog.appender.<appenderName>.threshold=<threshold>

 (etc for any other appenders)

 qmmslog.rootCategory=[<level>, <appender-name>, <appender-name> , ...]
 qmmslog.category.<category-name>=[level,]<appender-name>, <appender-name>, ...
 
Note that one need not specify the root category, since qmmslog sets the level of the root category to DEBUG and attaches no appenders, by default. Also, appender names are restricted to the chars [a-z], [A-Z], [0-9], while category names can use any char.

E.g., foo.bar is a valid category name and A2 is a valid appender, but the string A:2 is not allowed for an appender name.

After writing a properties file, one need only invoke the static method configure() to setup qmmslog.

What follows is an example .qmmslogrc file.

# Sample qmmslog properties file

# First configure the internal logging system (LogLog) (optional -- default is false)
qmmslog.debug=true

# Then set quietMode for LogLog, if desired (default is false)
qmmslog.debug.quietmode=true

# Then make any additional levels (optional), like this:
# <level-name>, <level-value>, ...
qmmslog.level=BAD_ERROR, 450, BIG_WARN, 350

# Then make an appender, using the fully-qualified class name of
# the appender's class.  The appender's name may contain only
# [a-z], [A-Z], or [0-9].  Here the name is A1.
qmmslog.appender.A1=Qmms::Log::ConsoleAppender

# Then make its layout, again using a FQCN.
qmmslog.appender.A1.layout=Qmms::Log::PatternLayout

# Then set any options necessary for the layout.
qmmslog.appender.A1.layout.pattern=/d /c /p /m /n

# Then set any options for the specific type of layout.
qmmslog.appender.A1.layout.pattern.datetimeformat=dd MMM yyyy hh:mm

# Of course, one could just use a simple layout instead.
# qmmslog.appender.A1.layout=Qmms::Log::SimpleLayout

# Then make the next appender, in the same way.
qmmslog.appender.A2=Qmms::Log::RollingFileAppender

# If this appender allows options, put them next.
qmmslog.appender.A2.filename=/home/max/logs/logfile
qmmslog.appender.A2.maxbackups=3
qmmslog.appender.A2.maxfilesize=100000
qmmslog.appender.A2.threshold=WARN

# After all the appender's options, make its layout.
qmmslog.appender.A2.layout=Qmms::Log::PatternLayout
qmmslog.appender.A2.layout.pattern=/d (/C) /c-/p: /m /n

# Now try a SyslogAppender
qmmslog.appender.A3=Qmms::Log::SyslogAppender

# This is the ident parameter in the openlog() call.  Usually it is 
# the name of the program.
qmmslog.appender.A3.syslogname=qmmslog test

# Define its layout and any layout options
qmmslog.appender.A3.layout=Qmms::Log::PatternLayout
qmmslog.appender.A3.layout.pattern=/c-/p: /m /n

# Now make the root category, with its attached appender(s). 
# A loglevel is required (for now).  The following makes the root category
# (and all its children, if their additivity flags are left true)
# log to the console and to syslog any event with level DEBUG or higher (i.e., all).
qmmslog.rootCategory=DEBUG, A1, A3

# Now make the categories, with their attached appenders
# and an optional explicit log level. Note that any char is allowed
# in the category name.  Note tha tthe first keyword must be either 
# "INHERIT" or an explicit loglevel, like "ERROR".

# If we wish to set the loglevel of a category explicitly:
qmmslog.category.cat=WARN

# Else do this.  The keyword INHERIT must be used here.  Note that
# we need not specify an appender, since a category can log to all
# the appenders attached to its ancestor categories, depending on
# whether its additivity flag is set (which it is, by default).
qmmslog.category.cat.foo.bar=INHERIT

# Or do this to set the Category's additivity flag to false, so that it does
# not append to the attached appenders of its parents.  NONADDITIVE may be placed
# anywhere after the first keyword.
qmmslog.category.cat=ERROR,A2,NONADDITIVE
 
The name of this file by default is .qmmslogrc, so when one invokes the configure() method it is this file that is parsed. configure() will also accept a filename, if one wishes to use a differently-named configuration file.


Constructor & Destructor Documentation

Qmms::Log::PropertyConfigurator::PropertyConfigurator  
 

Constructor does nothing.

Qmms::Log::PropertyConfigurator::~PropertyConfigurator  
 

Destructor does nothing.


Member Function Documentation

void Qmms::Log::PropertyConfigurator::addLevels   [static, protected]
 

Iterates through the propMap, looking for the "qmmslog.level" key.

Adds those values to the level QMap.

void Qmms::Log::PropertyConfigurator::configure const QString    filename [static]
 

Same as configure(), except it reads the given properties file.

Parameters:
filename  the name of the file from which to configure the qmmslog system

void Qmms::Log::PropertyConfigurator::configure   [static]
 

Configures the qmmslog system from the file whose name is held in the const static string DEFAULT_PROPERTIES.

Calls the following methods, in order:

 parsefile, addLevels, parseAppenders, configureRoot, parseCategories
 

Reimplemented from Qmms::Log::BasicConfigurator.

void Qmms::Log::PropertyConfigurator::configureInternalLogging   [static, protected]
 

Configure internal logging system (LogLog).

void Qmms::Log::PropertyConfigurator::configureRoot   [static, protected]
 

Creates and configures the Root Category.

void Qmms::Log::PropertyConfigurator::configureWQt const QString    filename [static]
 

Same as configureWQt(), but uses the given filename for the configuration.

Parameters:
filename  file to use for configuration

void Qmms::Log::PropertyConfigurator::configureWQt   [static]
 

Configures the qmmslog system from the default properties, and routes Qt debugging output (qDebug, qWarn, qFatal) through qmmslog.

void Qmms::Log::PropertyConfigurator::parseAppenders   [static, protected]
 

Iterates through the propMap and creates the specified appenders.

void Qmms::Log::PropertyConfigurator::parseCategories   [static, protected]
 

Creates and configures all the Categories (except for Root).

void Qmms::Log::PropertyConfigurator::parseFile const QString    filename [static, protected]
 

Parses the given file into a StrListMap.

Parameters:
filename  name of properties file to parse

void Qmms::Log::PropertyConfigurator::summarize   [static]
 

bool Qmms::Log::PropertyConfigurator::verifyAppenderExists QString    name [static, protected]
 

Checks whether the named appender is in the QDict of appenders.

Parameters:
name  the name of the appender to check for


Member Data Documentation

AppDict Qmms::Log::PropertyConfigurator::apdrDict [static, protected]
 

A QDict of appenders used to store pointers to all the Appenders created by PropertyConfigurator.

const QString Qmms::Log::PropertyConfigurator::APPENDER_PREFIX [static, private]
 

The string "qmmslog.appender".

const QString Qmms::Log::PropertyConfigurator::CATEGORY_PREFIX [static, private]
 

The string "qmmslog.category".

const QString Qmms::Log::PropertyConfigurator::DEBUG_PREFIX [static, private]
 

The string "qmmslog.debug".

const QString Qmms::Log::PropertyConfigurator::DEFAULT_PROPERTIES [static, private]
 

The string ".qmmslogrc".

const QString Qmms::Log::PropertyConfigurator::LEVEL_PREFIX [static, private]
 

The string "qmmslog.level".

StrListMap Qmms::Log::PropertyConfigurator::propMap [static, protected]
 

A QMap with QStrings as keys, and QStringLists as values.

Used to hold the name=values pairs in the properties file read by this class.

const QString Qmms::Log::PropertyConfigurator::ROOTCATEGORY_PREFIX [static, private]
 

The string "qmmslog.rootCategory".


The documentation for this class was generated from the following file:
Generated on Fri Jan 3 15:04:06 2003 for QmmsLog by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001