1 /*----------------------------------------------------------------------------
  2 Name:      Log4cplus.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 -----------------------------------------------------------------------------*/
  6 
  7 #ifndef _ORG_XMLBLASTER_UTIL_LOG4CPLUS_H
  8 #define _ORG_XMLBLASTER_UTIL_LOG4CPLUS_H
  9 
 10 #if XMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN==1
 11 
 12 #include <util/xmlBlasterDef.h>
 13 #include <string>
 14 #include <map>
 15 #include <util/I_LogFactory.h>
 16 #include <util/I_Log.h>
 17 #include <log4cplus/logger.h>
 18 
 19 namespace org { namespace xmlBlaster { namespace util {
 20    
 21 /**
 22  * Embed log4cpp logging library in xmlBlaster. 
 23  * <p />
 24  * This embedding class replaces the xmlBlaster native logging
 25  * facility by log4cplus (http://log4cplus.sourceforge.net/)
 26  * <p />
 27  * You need to compile it with this define:
 28  * <pre>
 29  * build -DXMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN=1 cpp
 30  * </pre>
 31  * <p>
 32  *  We are forwarding all <tt>xmlBlaster.properties</tt> and command line settings to log4cplus,
 33  *  so you could configure everything in <tt>xmlBlaster.properties</tt> instead of a
 34  *  separate <tt>log4cplus.properties</tt>
 35  *  (see the example file <tt>xmlBlaster/config/log4cplus.properties</tt>).<br />
 36  *  Log4cplus is extended to do ${xy} variable replacement not only from environment
 37  *  but from itself as well (recursion depth is one).
 38  * </p>
 39  * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>
 40  * @see http://log4cplus.sourceforge.net/
 41  * @see http://logging.apache.org/log4j/docs/manual.html
 42  */
 43 class Dll_Export Log4cplusFactory : public I_LogFactory
 44 {
 45    public:
 46       typedef std::map<std::string, org::xmlBlaster::util::I_Log *> LogMap;
 47    private:
 48      LogMap logMap_;
 49    public:
 50       Log4cplusFactory();
 51       virtual ~Log4cplusFactory();
 52       void initialize(const PropMap& propMap);
 53       I_Log& getLog(const std::string& name="");
 54       void releaseLog(const std::string& name="");
 55 }; // end of class Log4cplus
 56 
 57 
 58 /**
 59  * Embed log4cpp logging library in xmlBlaster. 
 60  * <p />
 61  * Map our internal logging calls to log4cpp logging calls.
 62  * <p />
 63  * You need to compile it with this define:
 64  * <pre>
 65  * build -DXMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN=1 cpp
 66  * </pre>
 67  * <p />
 68  * The following command line arguments allows to specify the logging configuration file:
 69  * <pre>
 70  * -xmlBlaster/logging/configFileName log4cplus.properties
 71  *
 72  * -xmlBlaster/logging/debug true
 73  * </pre>
 74  * <p />
 75  * Here is an example for a <code>log4cplus.properties</code> configuration:
 76  * <pre>
 77 log4cplus.rootLogger=INFO, STDOUT, R
 78 log4cplus.logger.test.a.b.c=WARN
 79 log4cplus.logger.filelogger=WARN, R
 80 log4cplus.additivity.filelogger=FALSE
 81 
 82 log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
 83 log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
 84 log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
 85 
 86 log4cplus.appender.R=log4cplus::RollingFileAppender
 87 log4cplus.appender.R.File=xmlBlaster_CPP_${ENV_VAR}.log
 88 log4cplus.appender.R.MaxFileSize=500KB
 89 log4cplus.appender.R.MaxBackupIndex=5
 90 log4cplus.appender.R.layout=log4cplus::TTCCLayout
 91  * </pre>
 92  * You can set in your environment a variable and reference it here with ${}, see ENV_VAR
 93  *
 94  * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>
 95  * @see http://log4cplus.sourceforge.net/
 96  * @see http://logging.apache.org/log4j/docs/manual.html
 97  */
 98 class Dll_Export Log4cplusLog : public I_Log
 99 {
100   private:
101    std::string logName_;
102    log4cplus::Logger logger_;
103 
104   public:
105    Log4cplusLog(std::string logName);
106    void info(const std::string &instance, const std::string &text);
107    void warn(const std::string &instance, const std::string &text);
108    void error(const std::string &instance, const std::string &text);
109    void panic(const std::string &instance, const std::string &text);
110    void trace(const std::string &instance, const std::string &text);
111    void call(const std::string &instance, const std::string &text);
112    std::string usage() const;
113 };
114 
115 
116 }}} // end of namespace util
117 
118 #endif // XMLBLASTER_COMPILE_LOG4CPLUS_PLUGIN
119 
120 #endif // _ORG_XMLBLASTER_UTIL_LOG4CPLUS_H


syntax highlighted by Code2HTML, v. 0.9.1