On Mar 28, 2008, at 6:32 PM, Beni Bilme wrote:

I am trying to rebuild an application on Ubuntu Linux (Gutsy) which I
developed on Windows XP with VS 2003 C++ compiler some time ago. It is
Qt4 application. I am using log4cxx as well. To ease the usage, once I
posted a question to this forum and a smart fellow sent me his log.h
header file which I provided below.

I receive compile errors both at windows and at linux from the locations
that I use log_xxxx such as log_debug, log_error etc stating that
‘getError’ is not a member of ‘log4cxx::Level’. These are simple macros
as you would see below to save typing and space at the code.

I have used this code before. I have not changed anything in the code.
But I have lost the development environment in windows xp. I rebuild
libraries etc. In Ubuntu, I have just installed the distribution
libraries and tried the compile.

I do not have much knowledge about log4cxx and do not use its many
features. I just use the facilities in this header file provided below.

Note: For each class, I have a data member   'static LoggerPtr logger'
and I initialize it in the correponding cpp file as 'LoggerPtr
Address::logger(Logger::getLogger("ClassName"));'

In the class, I use it like 'log_error("Some error message");'

Any help much appreciated.


I don't see any obvious reason why you'd get a compile error, but the definition of LOG4CXX_LOCATION is out of date and the current SVN HEAD and release candidates have a much more efficient means of formatting messages than using std::ostringstream for simple insertions. Try the following and see if that helps (should work with any log4cxx in the last 6 months or so).


#ifndef LOG_H
#define LOG_H

#include <log4cxx/logger.h>
using namespace log4cxx;

#define _USE_LOG4CXX_ 1

#if !_USE_LOG4CXX_

#define log_fatal_enabled()  0
#define log_error_enabled()  0
#define log_warn_enabled()   0
#define log_info_enabled()   0
#define log_debug_enabled()  0
#define log_trace_enabled()  0

#define log_fatal(expr)
#define log_error(expr)
#define log_warn(expr)
#define log_info(expr)
#define log_debug(expr)
#define log_trace(expr)

#else

#define log_fatal_enabled() logger- >isEnabledFor(::log4cxx::Level::getFatal() ) #define log_error_enabled() logger- >isEnabledFor(::log4cxx::Level::getError() ) #define log_warn_enabled() logger- >isEnabledFor(::log4cxx::Level::getWarn() ) #define log_info_enabled() logger- >isEnabledFor(::log4cxx::Level::getInfo() ) #define log_debug_enabled() logger- >isEnabledFor(::log4cxx::Level::getDebug() ) #define log_trace_enabled() logger- >isEnabledFor(::log4cxx::Level::getTrace() )

#define log_xxxx(level, expr) LOG4CXX_LOG(logger, level, expr)

#define log_fatal(expr)  LOG4CXX_FATAL(logger, expr)
#define log_error(expr)  LOG4CXX_ERROR(logger, expr)
#define log_warn(expr)   LOG4CXX_WARN(logger, expr)
#define log_info(expr)   LOG4CXX_INFO(logger, expr)
#define log_debug(expr)  LOG4CXX_DEBUG(logger, expr)
#define log_trace(expr)  LOG4CXX_TRACE(logger, expr)

#endif //#if !_USE_LOG4CXX

#endif // LOG_H


Reply via email to