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 Robert Haschke <rh...@techfak.uni-bielefeld.de> on 2004/09/08 14:38:09 UTC

Question on logger hierarchy

Dear developers,

I'm new to log4* and I'm wondering how I can achieve the following goal:

I want to have a top level logger, logging to cerr with a level WARNING.
Below may be several other loggers with their own appenders, layouts and
logging levels. If I trigger an error or warning on these descendant
loggers, the message (if enabled at all) should be forwarded to the
top-level logger, logging to cerr. I think, this is the purpose of the
logger hierarchy.
My attempt to this failed, because all messages enabled at the
descendant loggers are forwarded to its ancestors, which do not check
the log level anymore. Why should this behaviour be useful? Why should I
use a logger hierarchy, if I cannot influence the logging through the
different log levels?

How can I achive my goal?


In future releases, it would be very convenient to have logger methods,
which allow printf-like formatting.


Yours sincerly,

Robert Haschke


--------------------------------------------------------------------------
Dipl.-Inform. Robert Haschke
Faculty of Technology, Neuroinformatics Group, M7-123
University of Bielefeld
33501 Bielefeld, Germany
phone: +49-521-106 6066, fax: +49-521-106 6011


Re: Question regarding FileAppender...

Posted by Mike SG <mi...@yahoo.com>.
Renny & Christophe,
 
Thanks for the information. 
 
-Mike

Christophe de VIENNE <cd...@alphacent.com> wrote:
Mike SG wrote:

> Have I done something wrong? Can I use fileappender in a multiprocess 
> application? Do I need to set something?
>
> What options do I have?
>
The simplest option you have is to use simplesocketserver from the
package. In your application send all the logs to a socket appender
which send you log events to a simple server, which itself send
everything to FileAppender.
The final output should be the one you expect.

Regards,

Christophe



		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

Re: Question regarding FileAppender...

Posted by Christophe de VIENNE <cd...@alphacent.com>.
Mike SG wrote:

> Have I done something wrong? Can I use fileappender in a multiprocess 
> application? Do I need to set something?
>
> What options do I have?
>
The simplest option you have is to use simplesocketserver from the
package. In your application send all the logs to a socket appender
which send you log events to a simple server, which itself send
everything to FileAppender.
The final output should be the one you expect.

Regards,

Christophe



Re: Question regarding FileAppender...

Posted by Mike SG <mi...@yahoo.com>.
Thanks Arnold for the information.
 
-Mike.

Curt Arnold <ca...@apache.org> wrote:
log4cxx follows log4j and log4j does not attempt to synchronize file 
I/O across multiple processes. This is addressed in Chapter 10 of "The 
complete manual log4j".

Q 10.3 Can multiple Java Virtual Machines log to the same file using 
log4j?

No, there is no way for log4j to coordinate the access for a system 
resource, for example a file, between multiple JVMs....

The following FAQ describes the common method of addressing situations 
where that is necessary by using SocketAppenders and a daemon that 
receives the log requests and writes to a file: 
http://logging.apache.org/log4j/docs/faq.html#3.3


On Sep 10, 2004, at 3:46 PM, Mike SG wrote:

> Hi,
>
> I compiled successfully the log4cxx on solaris and I am trying to run 
> a small example which uses FileAppender. Our project is a multi 
> process system. So I created a small example which has 2 processes 
> writing to a file. I used the FileAppender for this. But when I see 
> the output I see that it not process safe. The output is mixed up. 
> Does this works only for threads in a single application.
>
> Have I done something wrong? Can I use fileappender in a multiprocess 
> application? Do I need to set something?
>
> What options do I have?
>
> Can somebody please help me on this.
>
> Thanks a lot,
>
> -Mike.
>
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.

		
---------------------------------
Do you Yahoo!?
Express yourself with Y! Messenger! Free. Download now.

Re: Question regarding FileAppender...

Posted by Curt Arnold <ca...@apache.org>.
log4cxx follows log4j and log4j does not attempt to synchronize file 
I/O across multiple processes.  This is addressed in Chapter 10 of "The 
complete manual log4j".

Q 10.3 Can multiple Java Virtual Machines log to the same file using 
log4j?

No, there is no way for log4j to coordinate the access for a system 
resource, for example a file, between multiple JVMs....

The following FAQ describes the common method of addressing situations 
where that is necessary by using SocketAppenders and a daemon that 
receives the log requests and writes to a file: 
http://logging.apache.org/log4j/docs/faq.html#3.3


On Sep 10, 2004, at 3:46 PM, Mike SG wrote:

> Hi,
>
> I compiled successfully the log4cxx on solaris and I am trying to run 
> a small example which uses FileAppender. Our project is a multi 
> process system. So I created a small example which has 2 processes 
> writing to a file. I used the FileAppender for this. But when I see 
> the output I see that it not process safe. The output is mixed up. 
> Does this works only for threads in a single application.
>
>  Have I done something wrong? Can I use fileappender in a multiprocess 
> application? Do I need to set something?
>
> What options do I have?
>
> Can somebody please help me on this.
>
> Thanks a lot,
>
> -Mike.
>
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.

Question regarding FileAppender...

Posted by Mike SG <mi...@yahoo.com>.
Hi,

I compiled successfully the log4cxx on solaris and I am trying to run a small example which uses FileAppender. Our project is a multi process system. So I created a small example which has 2 processes writing to a file. I used the FileAppender for this. But when I see the output I see that it not process safe. The output is mixed up. Does this works only for threads in a single application. 

Have I done something wrong? Can I use fileappender in a multiprocess application? Do I need to set something?

What options do I have?

Can somebody please help me on this.

Thanks a lot,

-Mike.



		
---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

Re: Question on logger hierarchy

Posted by Christophe de VIENNE <cd...@alphacent.com>.
Curt Arnold a écrit :

> On Sep 8, 2004, at 7:38 AM, Robert Haschke wrote:
>
>> In future releases, it would be very convenient to have logger methods,
>> which allow printf-like formatting.
>
> I'd like to keep the LOG4CXX_level macros as simple as possible (and 
> simpler than they are now).  I don't think printf is desirable since 
> so many had things can happen if the format specifiers don't match the 
> arguments.

I personnaly use boost::format to achieve this goal, combined with a 
function _() which is use gettext :

inline boost::format _(const char * s) {
    return boost::format( gettext(s) );
}

Then I can write stuffs like :

LOG4CXX_ERROR(logger, _("Error while opening file '%1%': '%2%'") % 
filename % reason );

I think this is much more preferable than adding printf like functions 
on loggers.

Regards,

Christophe

-- 
Christophe de Vienne



Re: Question on logger hierarchy

Posted by Curt Arnold <ca...@apache.org>.
On Sep 8, 2004, at 7:38 AM, Robert Haschke wrote:

> Dear developers,
>
> I'm new to log4* and I'm wondering how I can achieve the following 
> goal:
>
> I want to have a top level logger, logging to cerr with a level 
> WARNING.
> Below may be several other loggers with their own appenders, layouts 
> and
> logging levels. If I trigger an error or warning on these descendant
> loggers, the message (if enabled at all) should be forwarded to the
> top-level logger, logging to cerr. I think, this is the purpose of the
> logger hierarchy.
> My attempt to this failed, because all messages enabled at the
> descendant loggers are forwarded to its ancestors, which do not check
> the log level anymore. Why should this behaviour be useful?

It allows you to lower the threshold of a specific child logger while 
suppressing all other loggers.  It is an established log4j behavior and 
not subject to change.  The scenario is discussed in the section 
"Setting the level of a logger" (pg 55) of "The complete manual log4j", 
but I didn't see it discussed online.

> Why should I
> use a logger hierarchy, if I cannot influence the logging through the
> different log levels?
>
> How can I achive my goal?
>

You should be able to set the threshold on the appender attached to the 
root logger.

>
> In future releases, it would be very convenient to have logger methods,
> which allow printf-like formatting.
>

I'd like to keep the LOG4CXX_level macros as simple as possible (and 
simpler than they are now).  I don't think printf is desirable since so 
many had things can happen if the format specifiers don't match the 
arguments.  However, making it simple to do logging involving 
operator<< is a worthwhile goal, something like:

LOG4CXX_DEBUG_STREAM(logger, "The current count is " << count);

which would be equivalent to something like:

LOG4CXX_DEBUG(logger, ((std::ostringstream)()  << The current count is 
" << count).str());


Re: Question on logger hierarchy

Posted by Christophe de Vienne <cd...@alphacent.com>.
Robert Haschke wrote:

> In future releases, it would be very convenient to have logger methods,
> which allow printf-like formatting.

I did not look at it carefully yet, but this may be what you want:
http://logging.apache.org/log4cxx/manual/classlog4cxx_1_1Logger.html#a26

Regards,

Christophe