RE: Logger object and change filename
At the code location where a particular Thread knows about processing a distinct element you put a identifying information into MDC, after having processed remove the info again. MDC values are kept on a per Thread basis. This info can be used by the MultifileAppender (when processing a log call) or by a own written Repository Selector (when fetching a logger). Heri -Original Message- From: Reza Razavipour [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 09, 2008 7:09 PM To: Log4J Users List Subject: Re: [SPAM (Bayesain Analysis)] - Logger object and change filename - Bayesian Filter detected spam I have, I just don't see how that works for my case??? Reza On Tue, Sep 9, 2008 at 9:28 AM, Jacob Kjome [EMAIL PROTECTED] wrote: Search the list for MultiFileAppender or something to the effect of per-thread logging based on MDC values. Jake On Tue, 9 Sep 2008 09:00:53 -0700 Reza Razavipour [EMAIL PROTECTED] wrote: Ok, let me explain more... I have a set of elements, a queue of them...I have a thread pool of processors. A processor takes an element from the queue and logs some information about them. So what I need to do is to log the information about element XYZ to a file called XYZ.log and for element ABC to the file ABC.log and on and on... From the log4j.xml for the app, there is an appender called AllElements, lets say. In addition to all element specific log files, I need to log to this file also...Now what I need to do is to clone. If it is a rollingFileAppender the element specific log appender needs to be the same, the pattern format should be the same, the only difference is appender file name... So for each element, I need a brand new logger with appenders exactly the same as the one defined in log4j.xml file, the only difference is the filename for the appender, there is only one. Does this help at all clarify what I need to do? Thanks Reza On Tue, Sep 9, 2008 at 8:00 AM, Bender Heri [EMAIL PROTECTED] wrote: Loggers do not have file names attached. Probably you mean a FileAppender. Each configured Appender is instantiated as singleton, even if it is attached to more than one Logger. Loggers are identified by a arbitrary String, commonly the FQCN. Therefore you cant clone a Logger which has the same name as the original. Explain more about your needs. Why do you have to clone it? Heri -Original Message- From: Reza Razavipour [mailto:[EMAIL PROTECTED] Sent: Monday, September 08, 2008 5:38 PM To: Log4J Users List Subject: [SPAM (Bayesain Analysis)] - Logger object and change filename - Bayesian Filter detected spam All, I have a Logger object and I need to create a clone of it and change its filename to a different name. How does one do that? The idea here is that I have initialized a Logger instance from log-4j.xml file. Now I need to create a new one, off of it or clone and change the filename. Every attribute of the new Logger instance should be whatever is in the file, only filename is diifferent. Thanks in advance. Reza --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [SPAM (Bayesain Analysis)] - RE: static log4j configuration statement - Bayesian Filter detected spam
Just put your property file into the classpath and you do not have to worry about initialization of log4j framework. It does it automagically when you fetch the first logger. Heri -Original Message- From: Michael Erskine [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 10, 2008 4:20 PM To: Log4J Users List Subject: [SPAM (Bayesain Analysis)] - RE: static log4j configuration statement - Bayesian Filter detected spam I use standard static code to include the log4j configuration: static { PropertyConfigurator.configure(file)); } But this code is not always executed, depending on if the class in which this is included particpates in execution. But if I add this statment to other classes too, I sooner or later get double-messages as two classes with this statement are used. Then I need to manually remove the code in one of them to achieve proper logging. How this is done right? I just want to have this configuration stated once and applicable to the whole project. Hi Sebastian, What I tend to do is have a class to do something similar but first check whether already configured: my class is called LogConfigureCheck and is used in a static block for all my JUnit tests thus... static { LogConfigureCheck.check(); } ...and here follows a version of the class suitable for redistribution. Enjoy, Michael Erskine import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; /** * Occasionally we find a JUnit test suite or test case class that tests classes * that use log4j but for whatever reason log4j is not configured. We want to * avoid log4j being configured multiple times as this adds its own problems! * The aim here is to enforce that log4j is configured once and only once with * typical but useful features. * * @author Michael Erskine (msemtd) */ public class LogConfigureCheck { public static void check() { // One indicator of log4j not being configured is the lack of appenders // for the root logger. So... if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) { // Here we could just use BasicConfigurator.configure() // but the layout is not as useful as it could be - here we do // essentially the same but with a better layout... Logger.getRootLogger().addAppender( new ConsoleAppender(new PatternLayout( %-5p %d{HH:mm:ss.SSS} %c [%t] %m%n))); } } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: static log4j configuration statement
Bender Heri [mailto:[EMAIL PROTECTED] wrote: Just put your property file into the classpath and you do not have to worry about initialization of log4j framework. It does it automagically when you fetch the first logger. Heri Whilst that might be perfectly correct it is not what I'm attempting to achieve here; when I run any of my JUnit test suites the normal initialisation is suppressed and the first test will bootstrap a pleasing ConsoleAppender so the test results can be recorded. This technique can be used in any scenario where we want a basic but useful log4j configuration created if one has not already been configured explicitly (or, perhaps, automagically). Regards, Michael Erskine. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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
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 [EMAIL PROTECTED] .com To Log4J Users List 09/11/2008 11:53 AM log4j-user@logging.apache.org cc Please respond to Subject Log4J Users List Logging from appender [EMAIL PROTECTED] .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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Logging from appender
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] .com To Log4J Users List 09/11/2008 11:53 AM log4j-user@logging.apache.org cc Please respond to Subject Log4J Users List Logging from appender [EMAIL PROTECTED] .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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Logging from appender
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 [EMAIL PROTECTED] .com To Log4J Users List 09/11/2008 02:02 PM log4j-user@logging.apache.org cc Please respond to Subject Log4J Users List RE: Logging from appender [EMAIL PROTECTED] .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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] .com To Log4J Users List 09/11/2008 12:13 PM log4j-user@logging.apache.org cc Please respond to Subject Log4J Users List RE: Logging from appender [EMAIL PROTECTED] .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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] .com To Log4J Users List 09/11/2008 11:53 AM log4j-user@logging.apache.org cc Please respond to Subject Log4J Users List Logging from appender [EMAIL PROTECTED] .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