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 "Shuvalov, Andrew V" <An...@gs.com> on 2004/05/07 14:48:00 UTC

Extending LoggingEvent

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.


Re: Extending LoggingEvent

Posted by Michaël CATANZARITI <mc...@free.fr>.
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:
http://logging.apache.org/log4cxx/manual/group__LoggingMacros.html

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.

Michaël

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.
>