logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "log4cxx" <log4...@gallandfamily.com>
Subject re: PatternLayouts
Date Wed, 21 Nov 2007 16:47:05 GMT
Hi Srikanth,

Just because you have a wrapper class does not mean you cannot use a macro. We wrap the logger
class, and also use macros:

Hopefully this code snippet comes across well enough for you to read it. I've simplified the
macro a little. But logger is an object of our wrapper class, where we have implemented pass
thrus for isInfoEnabled (and the others) and forcedLog. The important part is the inclusion
of __FILE__ and __LINE__. In our forcedLog function we process the level passed in (here it
is 4) to get the log4cxx level (::log4cxx::Level::getInfo()), then we create a Location info
from the __FILE__ and __LINE__:
::log4cxx::spi::LocationInfo(fileName, NULL, lineNumber)

#define OurLogInfo(logger, message) 				\
	if (logger.isInfoEnabled()) {					\
		OurCriticalSectionAutoLocker lock(CLog::GetLock());			\
		CLog::logging_stream& buf = CLog::GetGlobalLoggingStream();	\
		buf << message << std::ends;			\
		logger.forcedLog(4, buf.str(), __FILE__, __LINE__);			\
	}

Hope this helps,
Andy

You wrote: 
=======================
Hi,
I have a question regarding if the following is supported:

o I have wrapper that uses LOG4CXX API to print log messages.  I would like to print the messages
optionally with the file and line #. 
o Using it this way, prints the file, line number where log4cxx API is invoked and NOT where
the wrapper was invoked, which is the actual place where the message originated.  Note that
I cannot use a macro or such for the wrapper.  It is a class in itself.

o Does LOG4CXX provide the following API
   - Is print the file/line number option enabled ?
   - (If so), set the file/line number provided(which I can pass to the wrapper).

Thanks!
--Srikanth


Mime
View raw message