XmlBlaster Logo

REQUIREMENT

client.cpp.logging

XmlBlaster Logo


Type NEW
Priority HIGH
Status CLOSED
Topic C++ client logging configuration
Des
cription

XmlBlaster provides for its C++ client library a simple console based logging implementation. Additionally you can configure during compilation to embed the rich featured logging library log4cplus which supports many features, for example rolling log files.

If you have already an own logging facility in your project you can code xmlBlaster to redirect all logging output to your own logging implementation.

XmlBlaster simple logger

This is the default and automatically compiled if not configured otherwise. Logging output in different levels is sent to the console. On UNIX the logging is colored to easily recognize errors. This logger is coded in the file Log.cpp. Try HelloWorld2 -help to get usage informations.

Embed log4cplus

To simplify life we have added log4cplus (Apache License) from Tad E. Smith to the xmlBlaster distribution. All necessary source files are located under xmlBlaster/src/c++/log4cplus. To configure logging we have added a sample configuration file xmlBlaster/config/log4cplus.properties. Please read the log4j documentation on how to customize it.

To switch on log4cplus logging you need to compile xmlBlaster with the XMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN compiler define, usually just set it to 1 in build.properties:

XMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN=1
     
and compile as usual with the command build cpp (Windows or Unix).

The log4cplus library is embedded by Log4cplus.cpp if you are curious about details.

Lookup of the configuration file

You can take a copy of the example configuration file xmlBlaster/config/log4cplus.properties and customize logging to your needs. The C++ library looks at following locations for the configuration file:

  1. -xmlBlaster/logging/configFileName [pathAndFile].
    You can pass the configuration file on command line or in the xmlBlaster.properties file. Command line has highest priority.
  2. If the file is not found we look into the xmlBlaster/logging/configFileName environment variable.
  3. Now we check the user home directory for a file named log4cplus.properties
  4. Finally the local directory is checked for a file named log4cplus.properties

Configuration

We are forwarding all xmlBlaster.properties and command line settings to log4cplus, so you could configure everything in xmlBlaster.properties instead of having a separate log4cplus.properties.

Command line settings are strongest and overwrite the setting in log4cplus.properties, here we switch on debugging:

PublishDemo -log4cplus.rootLogger "DEBUG, STDOUT, R"
     

Configuration variable replacement

Log4cplus is extended to do ${xy} variable replacement not only from environment but from itself as well (recursion depth is one):

The replacement of the own variables has the recursion
depth of one.

a=b
c=${a}

sets 'c' to 'b' but

a=b
e=${c}
c=${a}

will set 'e' to '${a}' in the worst case, or
depending of the sequence of lookup it could evaluate
'e' to 'b'.
     

Redirect logging to your own logging library

You need to implement two simple C++ abstract classes (a factory and the logging calls) to redirect all logging output to your own code. We do this as well for the above log4cplus support, you can use Log4cplus.cpp as an example implementation.

The first interface you need to implement is I_LogFactory.h which needs to create instances of your logging library (hidden by I_Log):

class I_LogFactory 
  virtual void initialize(const PropMap& propMap) { propMap_ = propMap; };
  virtual I_Log& getLog(const std::string& name="") = 0;
  virtual void releaseLog(const std::string& name="") = 0;
     

The second interface you need to implement is I_Log.h:

class I_Log
   virtual void info(const std::string &instance, const std::string &text)= 0;
   virtual void warn(const std::string &instance, const std::string &text)= 0;
   virtual void error(const std::string &instance, const std::string &text)= 0;
   virtual void trace(const std::string &instance, const std::string &text)= 0;
   virtual void call(const std::string &instance, const std::string &text)= 0;
   virtual std::string usage() const { return ""; }
     

For example if xmlBlaster logs an INFO message it invokes info() and your code does with it what it likes to do.

Configure

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See API LogFactory
See API Log
See CODE Log4cplus
See http://log4cplus.sourceforge.net/
See http://logging.apache.org/log4j/docs/manual.html/
See REQ client.cpp.compile

This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.cpp.logging.xml

Back to overview