logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shuvalov, Andrew V" <Andrew.Shuva...@gs.com>
Subject RE: Extending LoggingEvent
Date Mon, 10 May 2004 13:45:40 GMT


Yes, I'm overriding LoggingEvent, but I don't need to touch the Logger:

#define MATRIX_INFO_EXTERNAL(group, message) do { \
        Logger *logger = Logger::getLogger (group).operator->(); \
        if (logger->isInfoEnabled()) {\
            ::log4cxx::StringBuffer oss; \
            oss << message; \
            Matrix::MatrixLoggingEvent *event = \
                new Matrix::MatrixLoggingEvent ("ClassLogger", \
                    logger, Level::INFO, oss.str(), __FILE__, __LINE__); \
            event->setExternalDistributionFlag (true); \
            logger->callAppenders (event); }} while (0)

As you see I use standard Logger with custom Event. So the only
inconvenience is that I pass the message in constructor and can't change it

But it's really no problem. If you feel that's not safe to change then let
it be like that. It is very optional.


-----Original Message-----
From: Michaël CATANZARITI [mailto:mcatan@free.fr] 
Sent: Saturday, May 08, 2004 9:43 AM
To: Log4CXX User
Subject: Re: Extending LoggingEvent

Hello Andrew,

I'm not sure to understand what you want to do.

If you want to pass parameters to a logger, you can use logging macros, See:

If you want to override the class LoggingEvent, you have to override the 
class Logger in order to instanciate your LoggingEvent class in 
Logger::forcedLog. But it's not advised for you won't be able to use the 
SocketAppender anymore.


Shuvalov, Andrew V wrote:

> Hi,
> I'm trying to subclass the LoggingEvent to use it in my own macros,
> but apparently I don't have that much control over it. In particular, 
> I have to supply the message in constructor, and after that it is 
> read-only. Let me explain why do I need access to write into the message.
> I want to pass arbitrary parameters to my LoggingEvent in the log
> macros. For example, I want to write:
> MY_ERROR ("my.code", "Can't format the hard drive" << ErrorCode(5));
> Here I can pass optional parameter ErrorCode in the stream. To do so,
> I need to make my LoggingEvent to be ostream itself. But in order to 
> do so, I need to instantiate it with empty message first. So I'd like 
> to see a protected method "setMessage(const String &msg)".
> Is it possible?
> Thanks
> Andrew
> P.S. Please don't forget my recent Solaris socket patch.

View raw message