logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Wrapper around Log4cxx
Date Fri, 18 Jan 2008 17:13:54 GMT

On Jan 18, 2008, at 5:35 AM, Srinivas Chamarthi wrote:

> Hi,
> I am from java background and new to c++ development. I have a  
> requirement to use logger in my project and I have decided to go  
> with log4cxx. Can some one point me any examples or code that has  
> wrapper around log4cxx ? if I want to change to a different logger  
> in future, the wrapper should just support me to do that.
> appreciate your help in advance.
> thx,
> -Srinivas Chamarthi

For most apps, a very large majority of the modules would only do  
three things using log4cxx:

#include <myclass.h>
#include <log4cxx/logger.h>
static log4cxx::LoggerPtr logger("loggername");

void MyClass::foo() {
     LOG4CXX_INFO(logger, "Hello, World");

Then there could be some small fraction of code that does more  
intricate stuff.

If you code using log4cxx in the boiler-plate stuff, converting to  
another framework would involve doing some global search and replaces  
and then rewrite the intricate stuff.

If you want to write with some abstraction, you could define your own  
header file that defines macros that delegate to log4cxx, something  

//    com/example/logger.h
#include <log4cxx/logger.h>
#define DECLARE_LOG(var, name) \
static log4cxx::LoggerPtr var(name)
#define LOG_TRACE(logger, msg) LOG4CXX_TRACE(logger, msg)
#define LOG_DEBUG(logger, msg) LOG4CXX_DEBUG(logger, msg)
#define LOG_INFO(logger, msg) LOG4CXX_INFO(logger, msg)
#define LOG_WARN(logger, msg) LOG4CXX_WARN(logger, msg)
#define LOG_ERROR(logger, msg) LOG4CXX_ERROR(logger, msg)
#define LOG_FATAL(logger, msg) LOG4CXX_FATAL(logger, msg)

So with that type of header, most code that makes log requests would  
look like:

#include <myclass.h>
#include <com/example/logger.h>
DECLARE_LOG(logger, "loggername");

void MyClass::foo() {
     LOG_INFO(logger, "Hello, World");

View raw message