You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Bruno Melloni <Br...@wnco.com> on 2008/09/11 17:52:16 UTC

Logging from appender

What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)
 
Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.  
 
I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.
 
bruno

RE: Logging from appender

Posted by Pa...@xtl.com.
How about calling the subAppend(LoggingEvent) method within your appender?  That
would prevent the append() method from being called recursively since your disk
utilization check is located there.
(Embedded image moved to file: pic15141.jpg)



                                                                                
             "Bruno Melloni"                                                    
             <Bruno.Melloni@wnco                                                
             .com>                                                           To 
                                         "Log4J Users List"                     
             09/11/2008 02:02 PM         <lo...@logging.apache.org>        
                                                                             cc 
                                                                                
              Please respond to                                         Subject 
             "Log4J Users List"          RE: Logging from appender              
             <log4j-user@logging                                                
                .apache.org>                                                    
                                                                                
                                                                                
                                                                                
                                                                                




The disk utilization check is called form inside the 'append' process...
that is why it would be messy.

As I said in the original email, there probably is a specific Log
class/method already in log4j intended for logging from inside an
appender.  It would be consistent with log4j's design.  But I can't seem
to find that class/method.

Thanks for trying anyway.

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com]
Sent: Thursday, September 11, 2008 11:21 AM
To: Log4J Users List
Subject: RE: Logging from appender

I'm using a RollingFileAppender in my logging.  It extends FileAppender,
which extends WriterAppender.  The WriterAppender has an "append" method
which takes a LoggingEvent object as a parameter.  Is your appender a
subclass of WriterAppender or some other class that extends
WriterAppender?  You could maybe call the "append" method and send your
LoggingEvent?

Again, I'm fairly new to log4j.
(Embedded image moved to file: pic11478.jpg)





             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To
                                         "Log4J Users List"

             09/11/2008 12:13 PM         <lo...@logging.apache.org>


cc


              Please respond to
Subject
             "Log4J Users List"          RE: Logging from appender

             <log4j-user@logging

                .apache.org>













Sorry, I think I got misunderstood.  I have no problem with
levels/thresholds when logging from the app.

What I want to do is generate an additional log message from INSIDE the
appender code, WHILE it is about to process an application message.

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com]
Sent: Thursday, September 11, 2008 10:59 AM
To: Log4J Users List
Subject: Re: Logging from appender

I'm not an expert on Log4j, but recently had a similar requirement.  I
didn't want debug messages appearing on the console.  So on my console
appender, I set a threshold like this:

log4j.appender.CA.Threshold=INFO

I got that from somebody else on this list.  This way I only see INFO
messages and above on the console and I see everything in my log file
from debug up.  If you did the same but set the threshold above WARN,
the console will only show messages above WARN, however you won't see
anything less than or equal to WARN on the console.  Don't know if that
helps.  I think the log4j configuration in XML allows for a min and max
threshold.
(Embedded image moved to file: pic17673.jpg)





             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To
                                         "Log4J Users List"

             09/11/2008 11:53 AM         <lo...@logging.apache.org>


cc


              Please respond to
Subject
             "Log4J Users List"          Logging from appender

             <log4j-user@logging

                .apache.org>













What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)

Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.

I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.

bruno


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



RE: Logging from appender

Posted by Bruno Melloni <Br...@wnco.com>.
The disk utilization check is called form inside the 'append' process...
that is why it would be messy.  

As I said in the original email, there probably is a specific Log
class/method already in log4j intended for logging from inside an
appender.  It would be consistent with log4j's design.  But I can't seem
to find that class/method.

Thanks for trying anyway.  

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com] 
Sent: Thursday, September 11, 2008 11:21 AM
To: Log4J Users List
Subject: RE: Logging from appender

I'm using a RollingFileAppender in my logging.  It extends FileAppender,
which extends WriterAppender.  The WriterAppender has an "append" method
which takes a LoggingEvent object as a parameter.  Is your appender a
subclass of WriterAppender or some other class that extends
WriterAppender?  You could maybe call the "append" method and send your
LoggingEvent?

Again, I'm fairly new to log4j.
(Embedded image moved to file: pic11478.jpg)



 

             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To 
                                         "Log4J Users List"

             09/11/2008 12:13 PM         <lo...@logging.apache.org>

 
cc 
 

              Please respond to
Subject 
             "Log4J Users List"          RE: Logging from appender

             <log4j-user@logging

                .apache.org>

 

 

 

 





Sorry, I think I got misunderstood.  I have no problem with
levels/thresholds when logging from the app.

What I want to do is generate an additional log message from INSIDE the
appender code, WHILE it is about to process an application message.

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com]
Sent: Thursday, September 11, 2008 10:59 AM
To: Log4J Users List
Subject: Re: Logging from appender

I'm not an expert on Log4j, but recently had a similar requirement.  I
didn't want debug messages appearing on the console.  So on my console
appender, I set a threshold like this:

log4j.appender.CA.Threshold=INFO

I got that from somebody else on this list.  This way I only see INFO
messages and above on the console and I see everything in my log file
from debug up.  If you did the same but set the threshold above WARN,
the console will only show messages above WARN, however you won't see
anything less than or equal to WARN on the console.  Don't know if that
helps.  I think the log4j configuration in XML allows for a min and max
threshold.
(Embedded image moved to file: pic17673.jpg)





             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To
                                         "Log4J Users List"

             09/11/2008 11:53 AM         <lo...@logging.apache.org>


cc


              Please respond to
Subject
             "Log4J Users List"          Logging from appender

             <log4j-user@logging

                .apache.org>













What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)

Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.

I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.

bruno


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: How does log4j fail?

Posted by Dong Zhang <dz...@seven.com>.
Hi Bruno,

Log4j is designed not to interrupt main application. 

Per you two specific questions, the answer is the same, Log4j would just
print a error to System.err, and die itself. You can review source file
to verify that, it just catch IOException, and print error, retry may
occur. e.g. in SocketAppender.java:

---------------------
  public void append(LoggingEvent event) {
    if(event == null)
      return;

    if(address==null) {
      errorHandler.error("No remote host is set for SocketAppender named
\""+
			this.name+"\".");
      return;
    }

    if(oos != null) {
      try {
	if(locationInfo) {
	   event.getLocationInformation();
	}
	oos.writeObject(event);
	//LogLog.debug("=========Flushing.");
	oos.flush();
	if(++counter >= RESET_FREQUENCY) {
	  counter = 0;
	  // Failing to reset the object output stream every now and
	  // then creates a serious memory leak.
	  //System.err.println("Doing oos.reset()");
	  oos.reset();
	}
      } catch(IOException e) {
	oos = null;
	LogLog.warn("Detected problem with connection: "+e);
	if(reconnectionDelay > 0) {
	  fireConnector();
	}
      }
    }
  }
-------------------------

Best wishes,
Dong

-----Original Message-----
From: Bruno Melloni [mailto:Bruno.Melloni@wnco.com] 
Sent: Wednesday, October 29, 2008 7:11 AM
To: Log4J Users List
Subject: How does log4j fail?

We have an application that does massive logging (about 100GB per day),
and log4j works like a charm.  We manage disk allocation to the log
filesystem fairly well, but nobody is perfect.  Since the application is
mission critical, we want to be 100% sure that logging failures won't
stop it.

So the question is:

When log4j is unable to log, how does it fail?  Does it just stop
logging? (which would be OK) Or does it crash/hang the application?

We'd be very interested in finding the answer for at least two
scenarios:

1) Using a file-based appender and running out of disk space. 
Having the appender (yes, it is custom) check for free space is not a
good option since the app is running on jdk 1.5.  Migrating to jdk 1.6
is no viable at this time, and constantly spawning a Solaris 'df -k
<logPath>' is not very desirable.

2) Delegating logging to a separate box dedicated to logging, and use
something like a SocketAppender or other distributed mechanism.  In such
a scenario we could loose the box, network, etc... So the focus would be
on how would the Appender would die/stop-logging.  This would probably
be easier to custom-code if necessary.

Thanks,

bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


How does log4j fail?

Posted by Bruno Melloni <Br...@wnco.com>.
We have an application that does massive logging (about 100GB per day),
and log4j works like a charm.  We manage disk allocation to the log
filesystem fairly well, but nobody is perfect.  Since the application is
mission critical, we want to be 100% sure that logging failures won't
stop it.

So the question is:

When log4j is unable to log, how does it fail?  Does it just stop
logging? (which would be OK) Or does it crash/hang the application?

We'd be very interested in finding the answer for at least two
scenarios:

1) Using a file-based appender and running out of disk space. 
Having the appender (yes, it is custom) check for free space is not a
good option since the app is running on jdk 1.5.  Migrating to jdk 1.6
is no viable at this time, and constantly spawning a Solaris 'df -k
<logPath>' is not very desirable.

2) Delegating logging to a separate box dedicated to logging, and use
something like a SocketAppender or other distributed mechanism.  In such
a scenario we could loose the box, network, etc... So the focus would be
on how would the Appender would die/stop-logging.  This would probably
be easier to custom-code if necessary.

Thanks,

bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Logging from appender

Posted by Pa...@xtl.com.
I'm using a RollingFileAppender in my logging.  It extends FileAppender, which
extends WriterAppender.  The WriterAppender has an "append" method which takes a
LoggingEvent object as a parameter.  Is your appender a subclass of
WriterAppender or some other class that extends WriterAppender?  You could maybe
call the "append" method and send your LoggingEvent?

Again, I'm fairly new to log4j.
(Embedded image moved to file: pic11478.jpg)



                                                                                
             "Bruno Melloni"                                                    
             <Bruno.Melloni@wnco                                                
             .com>                                                           To 
                                         "Log4J Users List"                     
             09/11/2008 12:13 PM         <lo...@logging.apache.org>        
                                                                             cc 
                                                                                
              Please respond to                                         Subject 
             "Log4J Users List"          RE: Logging from appender              
             <log4j-user@logging                                                
                .apache.org>                                                    
                                                                                
                                                                                
                                                                                
                                                                                




Sorry, I think I got misunderstood.  I have no problem with
levels/thresholds when logging from the app.

What I want to do is generate an additional log message from INSIDE the
appender code, WHILE it is about to process an application message.

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com]
Sent: Thursday, September 11, 2008 10:59 AM
To: Log4J Users List
Subject: Re: Logging from appender

I'm not an expert on Log4j, but recently had a similar requirement.  I
didn't want debug messages appearing on the console.  So on my console
appender, I set a threshold like this:

log4j.appender.CA.Threshold=INFO

I got that from somebody else on this list.  This way I only see INFO
messages and above on the console and I see everything in my log file
from debug up.  If you did the same but set the threshold above WARN,
the console will only show messages above WARN, however you won't see
anything less than or equal to WARN on the console.  Don't know if that
helps.  I think the log4j configuration in XML allows for a min and max
threshold.
(Embedded image moved to file: pic17673.jpg)





             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To
                                         "Log4J Users List"

             09/11/2008 11:53 AM         <lo...@logging.apache.org>


cc


              Please respond to
Subject
             "Log4J Users List"          Logging from appender

             <log4j-user@logging

                .apache.org>













What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)

Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.

I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.

bruno


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



RE: Logging from appender

Posted by Bruno Melloni <Br...@wnco.com>.
Sorry, I think I got misunderstood.  I have no problem with
levels/thresholds when logging from the app.

What I want to do is generate an additional log message from INSIDE the
appender code, WHILE it is about to process an application message. 

bruno

-----Original Message-----
From: Patrick.Grimard@xtl.com [mailto:Patrick.Grimard@xtl.com] 
Sent: Thursday, September 11, 2008 10:59 AM
To: Log4J Users List
Subject: Re: Logging from appender

I'm not an expert on Log4j, but recently had a similar requirement.  I
didn't want debug messages appearing on the console.  So on my console
appender, I set a threshold like this:

log4j.appender.CA.Threshold=INFO

I got that from somebody else on this list.  This way I only see INFO
messages and above on the console and I see everything in my log file
from debug up.  If you did the same but set the threshold above WARN,
the console will only show messages above WARN, however you won't see
anything less than or equal to WARN on the console.  Don't know if that
helps.  I think the log4j configuration in XML allows for a min and max
threshold.
(Embedded image moved to file: pic17673.jpg)



 

             "Bruno Melloni"

             <Bruno.Melloni@wnco

             .com>
To 
                                         "Log4J Users List"

             09/11/2008 11:53 AM         <lo...@logging.apache.org>

 
cc 
 

              Please respond to
Subject 
             "Log4J Users List"          Logging from appender

             <log4j-user@logging

                .apache.org>

 

 

 

 





What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)

Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.

I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.

bruno


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Logging from appender

Posted by Pa...@xtl.com.
I'm not an expert on Log4j, but recently had a similar requirement.  I didn't
want debug messages appearing on the console.  So on my console appender, I set
a threshold like this:

log4j.appender.CA.Threshold=INFO

I got that from somebody else on this list.  This way I only see INFO messages
and above on the console and I see everything in my log file from debug up.  If
you did the same but set the threshold above WARN, the console will only show
messages above WARN, however you won't see anything less than or equal to WARN
on the console.  Don't know if that helps.  I think the log4j configuration in
XML allows for a min and max threshold.
(Embedded image moved to file: pic17673.jpg)



                                                                                
             "Bruno Melloni"                                                    
             <Bruno.Melloni@wnco                                                
             .com>                                                           To 
                                         "Log4J Users List"                     
             09/11/2008 11:53 AM         <lo...@logging.apache.org>        
                                                                             cc 
                                                                                
              Please respond to                                         Subject 
             "Log4J Users List"          Logging from appender                  
             <log4j-user@logging                                                
                .apache.org>                                                    
                                                                                
                                                                                
                                                                                
                                                                                




What is the best way to send a message to the log from inside the
Appender itself?  (separate from the message that the appender is
currently processing)

Why do I even ask this?  My appender checks disk utilization every hour.
I'd like to record the % of disk utilized in the log.

I tried using LogLog.warn(), but it puts the message on the console, not
in the log file generated by the appender.  I could probably add it
manually to the code that writes to the file, but that feels messy...
and I suspect that there's built-in log4j functionality for what I want
to do.

bruno