You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Beni Bilme <be...@gmail.com> on 2008/03/29 00:32:40 UTC

Newbie Usage Question: Compile Error 'getError is not a member of log4cxx::Level'

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.

#ifndef LOG_H
#define LOG_H

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

#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

#include <sstream>
#include <iosfwd>

#ifndef LOG4CXX_LOCATION
#define LOG4CXX_LOCATION __FILE__, __LINE__
#endif

#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::getDebug() )

#define log_xxxx(level, expr) \
       do { \
       if (logger->isEnabledFor(::log4cxx::Level::level)) \
{ \
       std::ostringstream _msg_; \
       _msg_ << expr; \
       logger->log( \
       ::log4cxx::Level::level, \
       _msg_.str(), \
       LOG4CXX_LOCATION); \
} \
       } while (false)

#define log_fatal(expr)  log_xxxx(getFatal(), expr)
#define log_error(expr)  log_xxxx(getError(), expr)
#define log_warn(expr)   log_xxxx(getWarn(), expr)
#define log_info(expr)   log_xxxx(getInfo(), expr)
#define log_debug(expr)  log_xxxx(getDebug(), expr)
#define log_trace(expr)  log_xxxx(getDebug(), expr)

#endif //#if !_USE_LOG4CXX

#endif // LOG_H


Re: Newbie Usage Question: Compile Error 'getError is not a member of log4cxx::Level'

Posted by Beni Bilme <be...@gmail.com>.
I have download the latest version via subversion. The solution you
provided worked under ubuntu gutsy. I compiled the project with
autogen.sh generated configure script. Ant build failed. It somehow
thinks that it is building under windows. I do not why. I tried to run
windress somewhere and failed.

Thanks for the helpful and fast response.


Curt Arnold wrote:
>
> 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
>
>>
>


Re: Newbie Usage Question: Compile Error 'getError is not a member of log4cxx::Level'

Posted by Curt Arnold <ca...@apache.org>.
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

>