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

Qmms::Log::Category Class Reference

The most important class in the qmmslog package. More...

#include <log.hh>

Inheritance diagram for Qmms::Log::Category::

Qmms::Log::BaseCategory Qmms::Log::RootCategory List of all members.

Public Methods

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

bool isCategory ()
Category * getParent () const
 Accessor method. More...

void setParent (Category *p)
 Accessor method. More...

QString getFQN () const
 Accessor method. More...

void setFQN (const QString fqn)
 Accessor method. More...

bool getAdditivity () const
 Accessor method. More...

void setAdditivity (const bool atv)
 Accessor method. More...

void setLevel (const QString lvl)
 Accessor method. More...

QString getChainedLevel ()
 Returns the inherited category of this category. More...

bool isEnabledFor (const QString lvl)
 Checks whether the category is enabled for the given level. More...

void addAppender (const AppenderSkeleton *apdr)
 Adds the given appender to this category. More...

AppenderSkeleton * getAppender (const QString name) const
 Accessor method. More...

bool removeAppender (AppenderSkeleton *apdr)
 Removes the appender from this category's QDict of appenders. More...

bool removeAppender (QString name)
 Removes the named appender from this category's QDict of appenders. More...

bool contains (const AppenderSkeleton *apdr) const
 Checks if named appender is contained in the QDict of appenders. More...

bool contains (const QString &name) const
 Checks if named appender is contained in the QDict of attached appenders. More...

void callAppenders (LoggingEvent *evnt)
 Appends the given LoggingEvent to all the appenders attached to this Category and all its ancestors, if the category's additivity flag is set. More...

void closeAllAppenders ()
 Calls close() on each appender attached to this category. More...

void removeAllAppenders ()
 Calls removeAppender() on all Appenders attached to this category. More...

AppDict * getAppenderList ()
 Accessor method. More...

void logWithLevel (QString lvl, QString msg)
 Creates a LoggingEvent from the given message and logs it with the given level. More...

void debug (QString msg)
 Calls logWithLevel() with the DEBUG level. More...

void info (QString msg)
 Calls logWithLevel() with the INFO level. More...

void notice (QString msg)
 Calls logWithLevel() with the NOTICE level. More...

void warn (QString msg)
 Calls logWithLevel() with the WARN level. More...

void error (QString msg)
 Calls logWithLevel() with the ERROR level. More...

void fatal (QString msg)
 Calls logWithLevel() with the FATAL level. More...


Static Public Methods

Category * getInstance (const QString name, const QString fqn)
 Static method used to get an instance of a named category. More...

Category * getInstance (const QString name)
 Same as above, but with one less argument. More...

Hierarchy * getDefaultHierarchy ()
 Static method that returns a pointer to the default Hierarchy. More...

Category * getRootCat ()
 Static method that returns a pointer to the root category. More...

void shutdown ()
 Calls shutdown() in class Hierarchy. More...


Protected Methods

 Category ()
 Default constructor does nothing. More...

 Category (const QString name, const QString fqn)
 The constructor is protected because Categories are never instantiated this way. More...

 Category (const Category &rhs)
 Copy constructor is also private. More...

QString getLevel () const
 Accessor method. More...


Protected Attributes

Category * parent
 Pointer to parent category of this category. More...

QString FQN
 Fully-qualified classname of class calling the category. More...

QString level
 The assigned loglevel of this category can be null, in which case the category inherits a level from its ancestor(s) in the hierarchy. More...

AppDict appenderList
 QDict of appenders attached to this category. More...

bool additive
 Additivity is set to true by default. More...

bool hasLevel
 Flag to indicate whether this category has a LogLevel explicitly set. More...


Static Protected Attributes

Hierarchy * defaultHierarchy
 The hierarchy the categories are in. More...


Friends

class Hierarchy
 Hierarchy is a friend class because it needs to call the constructor. More...


Detailed Description

The most important class in the qmmslog package.

Categories are instantiated using the static method getInstance() and NEVER by invoking the constructor directly. (Aside: constructors are private for this reason.) Having getInstance() handle Category instances ensures that the Hierarchy of categories is maintained properly. Specifically, descendants can be created before their ancestors. Some examples would probably be beneficial.

Here is a typical way to use the qmmslog system.


include <iostream>
include <qmms/log.hh>
using namespace std;
using namespace Qmms::Log;

class CatTest
   {
   public:
      Category* cat;
      Category* catfoo;
      Category* catfoobar;
      
      CatTest()
         {
         cout << "Creating CatTest" << endl;
         catfoobar = Category::getInstance( "cat.foo.bar", typeid(this).name );
         cat = Category::getInstance( "cat" );
         catfoo = Category::getInstance( "cat.foo", typeid(this).name );
         }
      
      ~CatTest()
         {
         cout << "Deleting CatTest" << endl;
         }
      
      void test()
         {
         catfoobar->debug( "This is a debug" ); 
         cat->warn( "This is a warn" );
         catfoo->info( "This is an info" );
         cat->fatal( "This is a fatal" );
         }
   };

int main( int argc, char** argv )
   { 
   BasicConfigurator::configure();      

   CatTest ct;
   ct.test();
   Category::shutdown();

   return 0;
   }
 
This code can be found in main.cpp, included with this package.


Constructor & Destructor Documentation

Qmms::Log::Category::Category (    )  [protected]
 

Default constructor does nothing.

Qmms::Log::Category::Category (  const QString    name,
const QString    fqn
)  [protected]
 

The constructor is protected because Categories are never instantiated this way.

Use the static method getInstance() instead.

Parameters:
name  the name of this Category

Qmms::Log::Category::Category (  const Category &    rhs )  [protected]
 

Copy constructor is also private.

Does not copy the appender list.

Qmms::Log::Category::~Category (    ) 
 

Destructor does nothing.


Member Function Documentation

void Qmms::Log::Category::addAppender (  const AppenderSkeleton *    apdr ) 
 

Adds the given appender to this category.

Parameters:
apdr  the appender to add

void Qmms::Log::Category::callAppenders (  LoggingEvent *    evnt ) 
 

Appends the given LoggingEvent to all the appenders attached to this Category and all its ancestors, if the category's additivity flag is set.

This method is thread-safe.

Parameters:
evnt  the LoggingEvent to append

void Qmms::Log::Category::closeAllAppenders (    ) 
 

Calls close() on each appender attached to this category.

bool Qmms::Log::Category::contains (  const QString &    name )  const
 

Checks if named appender is contained in the QDict of attached appenders.

Parameters:
name  reference to name of appender
Returns:
true if appender is in QDict, false otherwise

bool Qmms::Log::Category::contains (  const AppenderSkeleton *    apdr )  const
 

Checks if named appender is contained in the QDict of appenders.

Parameters:
apdr  pointer to the appender for whose existence we are checking
Returns:
true if apdr is in the QDict of appenders, false otherwise

void Qmms::Log::Category::debug (  QString    msg ) 
 

Calls logWithLevel() with the DEBUG level.

Parameters:
msg  the message to log

void Qmms::Log::Category::error (  QString    msg ) 
 

Calls logWithLevel() with the ERROR level.

Parameters:
msg  the message to log

void Qmms::Log::Category::fatal (  QString    msg ) 
 

Calls logWithLevel() with the FATAL level.

Parameters:
msg  the message to log

bool Qmms::Log::Category::getAdditivity (    )  const
 

Accessor method.

Returns:
the additivity flag

AppenderSkeleton* Qmms::Log::Category::getAppender (  const QString    name )  const
 

Accessor method.

Parameters:
name  the name of the desired appender
Returns:
a pointer to the named appender

AppDict* Qmms::Log::Category::getAppenderList (    ) 
 

Accessor method.

Returns:
the QDict of appenders

QString Qmms::Log::Category::getChainedLevel (    ) 
 

Returns the inherited category of this category.

Examines this category and all its ancestors until one is found with a loglevel explicitly set. The root category always has a level, so this method always returns a value.

Returns:
the inherited level

Hierarchy* Qmms::Log::Category::getDefaultHierarchy (    )  [static]
 

Static method that returns a pointer to the default Hierarchy.

Returns:
pointer to the default hierarchy

QString Qmms::Log::Category::getFQN (    )  const
 

Accessor method.

Returns:
the fully-qualified class name of the category

Category* Qmms::Log::Category::getInstance (  const QString    name )  [static]
 

Same as above, but with one less argument.

Parameters:
name  the name of the desired category
Returns:
a pointer to the desired Category

Category* Qmms::Log::Category::getInstance (  const QString    name,
const QString    fqn
)  [static]
 

Static method used to get an instance of a named category.

It simply calls the static method getCatInstance() in class Hierarchy, thus keeping the Hierarchy invisible to the user.

Parameters:
name  the name of the desired Category
fqn  the fully-qualified class name of the category
Returns:
a pointer to the desired Category

QString Qmms::Log::Category::getLevel (    )  const [protected]
 

Accessor method.

Should be used with care, since it will attempt to return a level even if no level exists. That is, check the boolean attribute hasLevel first.

Returns:
the level of this category

Category* Qmms::Log::Category::getParent (    )  const
 

Accessor method.

Returns:
pointer to parent category of this category

Category* Qmms::Log::Category::getRootCat (    )  [static]
 

Static method that returns a pointer to the root category.

Returns:
pointer to the root category

void Qmms::Log::Category::info (  QString    msg ) 
 

Calls logWithLevel() with the INFO level.

Parameters:
msg  the message to log

bool Qmms::Log::Category::isCategory (    )  [virtual]
 

Returns:
true

Reimplemented from Qmms::Log::BaseCategory.

bool Qmms::Log::Category::isEnabledFor (  const QString    lvl ) 
 

Checks whether the category is enabled for the given level.

It does this by checking that the given level is not less than the inherited level of this category.

Parameters:
lvl  the level to check against the inherited level
Returns:
true if this category is enabled for the given level, false otherwise

void Qmms::Log::Category::logWithLevel (  QString    lvl,
QString    msg
) 
 

Creates a LoggingEvent from the given message and logs it with the given level.

Parameters:
lvl  the level with which to log
msg  the messsage to turn into a LoggingEvent and log

void Qmms::Log::Category::notice (  QString    msg ) 
 

Calls logWithLevel() with the NOTICE level.

Parameters:
msg  the message to log

void Qmms::Log::Category::removeAllAppenders (    ) 
 

Calls removeAppender() on all Appenders attached to this category.

bool Qmms::Log::Category::removeAppender (  QString    name ) 
 

Removes the named appender from this category's QDict of appenders.

Does nothing if named appender does not exist.

Parameters:
name  name of the appender to remove
Returns:
true if appender successfully removed, false otherwise

bool Qmms::Log::Category::removeAppender (  AppenderSkeleton *    apdr ) 
 

Removes the appender from this category's QDict of appenders.

Parameters:
apdr  pointer to the appender to remove
Returns:
true if appender successfully removed, false otherwise

void Qmms::Log::Category::setAdditivity (  const bool    atv ) 
 

Accessor method.

Sets the additivity property.

Parameters:
atv  the value with which to set the additivity flag

void Qmms::Log::Category::setFQN (  const QString    fqn ) 
 

Accessor method.

Sets the fully-qualified class name of the category.

Parameters:
fqn  the fully-qualified class name

void Qmms::Log::Category::setLevel (  const QString    lvl ) 
 

Accessor method.

Explicitly sets the loglevel of this category.

Parameters:
lvl  the level to set

void Qmms::Log::Category::setParent (  Category *    p ) 
 

Accessor method.

Sets the parent of this category.

Parameters:
p  pointer the parent category of this category

void Qmms::Log::Category::shutdown (    )  [static]
 

Calls shutdown() in class Hierarchy.

Use this to close the qmmslog system properly.

void Qmms::Log::Category::warn (  QString    msg ) 
 

Calls logWithLevel() with the WARN level.

Parameters:
msg  the message to log


Friends And Related Function Documentation

friend class Hierarchy [friend]
 

Hierarchy is a friend class because it needs to call the constructor.


Member Data Documentation

bool Qmms::Log::Category::additive [protected]
 

Additivity is set to true by default.

That is, children inherit the appenders of their ancestors by default. If this variable is set to false then the appenders found in the ancestors of this category are not used. However, the children of this category will inherit the category's appenders, unless the children have their additivity flags set to false as well.

AppDict Qmms::Log::Category::appenderList [protected]
 

QDict of appenders attached to this category.

Hierarchy* Qmms::Log::Category::defaultHierarchy [static, protected]
 

The hierarchy the categories are in.

QString Qmms::Log::Category::FQN [protected]
 

Fully-qualified classname of class calling the category.

bool Qmms::Log::Category::hasLevel [protected]
 

Flag to indicate whether this category has a LogLevel explicitly set.

QString Qmms::Log::Category::level [protected]
 

The assigned loglevel of this category can be null, in which case the category inherits a level from its ancestor(s) in the hierarchy.

Category* Qmms::Log::Category::parent [protected]
 

Pointer to parent category of this category.


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