log4j configuration ignored for inner classes
Hi all, I am trying to cut back on some of the logging noise from the Spark / Kafka frameworks by editing log4j.properties. However, it seems like package-specific customisations are ignored for inner classes. For example, the following configuration lines mostly work as expected, suppressing most logs from these packages below WARN level: log4j.logger.org.apache.spark=WARN log4j.logger.kafka.utils=WARN However, I am still getting log messages at INFO from classes like: org.apache.spark.Logging$class kafka.utils.Logging$class I suspect it's because these are inner classes. It still happens even when I go up a level and add configurations like log4j.logger.org=WARN. Is this a known bug in log4j? Is there any known way to suppress these, ideally through configuration rather than programmatically? Many thanks
RE: Problems with log4j configuration
Hi bmelloni! Thanks for all these good sugestions, but unfortunately none worked for me... :-(( What I've done: 1) Look in server.log and see if your entries might be going there. I've used grep in all my log files and my application console, and a random string that I've put there didn't appeared... I've used a break point in debug mode to be sure that my logger was called... :confused: 2) Check for typos. I've double checked for typos, but I don't think this is the case... 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. I've made this too, copying and pasting another configuration logger that's already working in another package, but it didn't work too... :-(( 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); I've tried this strategy too, and it was not effective again... :,( I really have no idea what might be happening... It seems that everything is alright, but my Auditor.log keeps empty... :confused: bmelloni wrote: Looks right to me, but I don't remember the RollingFileAppender parameters. I suggest you: 1) Look in server.log and see if your entries might be going there. 2) Check for typos. 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); -Original Message- From: rhaiger [mailto:rhai...@gmail.com] Sent: Monday, January 23, 2012 1:45 PM To: log4j-user@logging.apache.org Subject: Problems with log4j configuration Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33194364.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Problems with log4j configuration
Hi Bart! I've checked and I'm importing log4j correctly... =) Here's the import line: import org.apache.log4j.Logger; Thanks for the help! :-) Bart Berger wrote: If you let your IDE add the import statements, double-check that you're importing log4j's Logger and not JBoss's Logger. Cheers, Bart -Original Message- From: BRUNO MELLONI [mailto:bruno.mell...@chickasaw.net] Sent: Monday, January 23, 2012 11:58 AM To: Log4J Users List Subject: RE: Problems with log4j configuration Looks right to me, but I don't remember the RollingFileAppender parameters. I suggest you: 1) Look in server.log and see if your entries might be going there. 2) Check for typos. 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); -Original Message- From: rhaiger [mailto:rhai...@gmail.com] Sent: Monday, January 23, 2012 1:45 PM To: log4j-user@logging.apache.org Subject: Problems with log4j configuration Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33194369.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Problems with log4j configuration
I've noticed a very strange thing just now! While debugging, I've stoped in a point when my logger is called to log something... But when I evaluate my logger, it says: logger cannot be resolved This is very bizarre, cause when I try to log something with logger.info(bla) for example, it doesn't throws any exception... %-| rhaiger wrote: Hi bmelloni! Thanks for all these good sugestions, but unfortunately none worked for me... :-(( What I've done: 1) Look in server.log and see if your entries might be going there. I've used grep in all my log files and my application console, and a random string that I've put there didn't appeared... I've used a break point in debug mode to be sure that my logger was called... :confused: 2) Check for typos. I've double checked for typos, but I don't think this is the case... 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. I've made this too, copying and pasting another configuration logger that's already working in another package, but it didn't work too... :-(( 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); I've tried this strategy too, and it was not effective again... :,( I really have no idea what might be happening... It seems that everything is alright, but my Auditor.log keeps empty... :confused: bmelloni wrote: Looks right to me, but I don't remember the RollingFileAppender parameters. I suggest you: 1) Look in server.log and see if your entries might be going there. 2) Check for typos. 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); -Original Message- From: rhaiger [mailto:rhai...@gmail.com] Sent: Monday, January 23, 2012 1:45 PM To: log4j-user@logging.apache.org Subject: Problems with log4j configuration Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33194443.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Problems with log4j configuration
Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Problems with log4j configuration
Looks right to me, but I don't remember the RollingFileAppender parameters. I suggest you: 1) Look in server.log and see if your entries might be going there. 2) Check for typos. 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); -Original Message- From: rhaiger [mailto:rhai...@gmail.com] Sent: Monday, January 23, 2012 1:45 PM To: log4j-user@logging.apache.org Subject: Problems with log4j configuration Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Problems with log4j configuration
If you let your IDE add the import statements, double-check that you're importing log4j's Logger and not JBoss's Logger. Cheers, Bart -Original Message- From: BRUNO MELLONI [mailto:bruno.mell...@chickasaw.net] Sent: Monday, January 23, 2012 11:58 AM To: Log4J Users List Subject: RE: Problems with log4j configuration Looks right to me, but I don't remember the RollingFileAppender parameters. I suggest you: 1) Look in server.log and see if your entries might be going there. 2) Check for typos. 3) Try implementing your AUDITOR appender by cut/pasting the FILE appender that is there as a starting point. 4) Instead of using static and specifying the class use private final Logger logger = Logger.getLogger(this.getClass()); -Original Message- From: rhaiger [mailto:rhai...@gmail.com] Sent: Monday, January 23, 2012 1:45 PM To: log4j-user@logging.apache.org Subject: Problems with log4j configuration Hello guys, I'm new in this forum and I think you may help me with an issue... I'm trying to use log4j to log some login auditing informations, and I'm using JBoss 4 and Java with compliance level 5.0. It's a very old legacy system... I've added this lines at my log4j.xml: appender name=AUDITOR class=org.jboss.logging.appender.RollingFileAppender errorHandler class=org.jboss.logging.util.OnlyOnceErrorHandler/ layout class=org.apache.log4j.PatternLayout /layout /appender category name=com.itautec.siac.controleAcesso additivity=false priority value=INFO/ appender-ref ref=AUDITOR/ /category And in my Foo.java class, I've added this field: private static final Logger logger = Logger.getLogger(Foo.class); When I want to log something (inside my Foo.java class), I just call my logger with something like: logger.info(any message); Well, after that, I start JBoss4, and I can see that Auditor.log file is created in my log folder, as it should be, but everything I try to log doesn't appear in my Auditor.log file... :-( When I start my application in debug mode, I can see that I'm passing through several loggers that I've put in my Foo.java class, but it seems that log4j is just ignoring these callings and nothing is logged at all... Does anyone know what's happening? It seems to be something really simple, but I can't figure it out! :-(( Thanks from now and best regards! :-) -- View this message in context: http://old.nabble.com/Problems-with-log4j-configuration-tp33190553p33190553.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
log4j configuration for rollover and compression
Hi, Can someone please let me know how to configure log4j.properties file for the below requirement : 1. I need to rollover the log files on the basis of both size and time whichever earlier (example : rollover the log files if they cross 10MB or at the end of each day which ever occurs first) 2. The rolled over files need to be compressed in gz format. 3. Once the number of rolled over + compressed files (archive) reaches 10 then i need to start deleting the oldest archive. I have log4j-1.2.13.jar and apache-log4j-extras-1.1.jar in the classpath of my web application. logback is not an option for me and I need to get this done using log4j. Thanks, Yash -- View this message in context: http://old.nabble.com/log4j-configuration-for-rollover-and-compression-tp33074307p33074307.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Verification of log4j configuration file
Thank you, Josef, very detailed explanation! - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: Re: Verification of log4j configuration file
Hi Antonio I suggest to you the following. 1. Take NetBeans or any other IDE and catch the log4j open sources as a project. 2. Build log4j yourself, 3. JDK 6.0, maven 2.2.1 and ant 1.7 and a few other lesser important things is all you need 4. Do BUILD using NetBeans. / you can use also from a dos window mvn install comand 5. Select build.xml and ask for the javadoc ANT target to get doc and API's built 6. Then start your TrowableProperty or DOMConfiguratir development basically you have to consider a few Configurators BasicConfigurator Is extended by the PropertyConfigurator(reading config data from a property file) OR DOMConfigurator (reading config data from a XML file) Either of the two can be extended by your own TrowablePropertyConfigurator OR TrowableDOMConfigurator You may develop your own TrowablePropertyConfigurator or TrowableDOMConfigurator and engage it as shown in the Java Class below but this time inside a try catch block. So where is your TrowablePropertyConfigurator engaged? Look at the file Log4JTest.java written by ThomasFenner under ./contribs/ThomasFenner (here included as reference) You can see that this test catches exceptions if drives are not installed? OK? And you can see which and how the PropertyConfigurator is engaged? Now, at this stage we would engage your own TrowablePropertyConfigurator or your own TrowableDOMConfigurator import org.apache.log4j.*; import java.sql.*; import java.lang.*; import java.util.*; public class Log4JTest { // Create a category instance for this class static Category cat = Category.getInstance(Log4JTest.class.getName()); public static void main(String[] args) { // Ensure to have all necessary drivers installed ! try { Driver d = (Driver)(Class.forName(oracle.jdbc.driver.OracleDriver).newInstance()); DriverManager.registerDriver(d); } catch(Exception e){} // Set the priority which messages have to be logged cat.setPriority(Priority.INFO); try { // Configuration with configuration-file //PropertyConfigurator.configure(log4jtestprops.txt); TrowablePropertyConfigurator.configure(log4jtestprops.txt); } catch(Exception e){} // These messages with Priority = setted priority will be logged to the database. cat.debug(debug); //this not, because Priority DEBUG is less than INFO cat.info(info); cat.error(error); cat.fatal(fatal); } } For further understanding: Go to the ./docs/api/org(apache/log4j/PropertyConfigurator.html Open this and study what the PropertyConfigurator does for you? And you will find you confirmed that no exceptions are raise by log4j's PropertyConfigurator for whatever reason. Can you extend the PropertyConfigurator and extend and implement TrowablePropertyConfigurator ! Certainly you can. Finally do not forget to ask somebody from the developers group to help you check in your working/tested source code. Maybe somebody more know to the subject can comment my suggestions Josef -Ursprüngliche Nachricht- Von: Antonio Rodriges [mailto:antonio@gmail.com] Gesendet: Montag, 8. August 2011 11:05 An: log4j-user@logging.apache.org Betreff: Re: Re: Verification of log4j configuration file Thank you, Josef, however I would like to force log4j return me an error code or throw an exception (however docs says it never throws anything) in case of a malformed config file to stop my application. Otherwise all logs will cause exceptions and will not appear anywhere. What is the best practice for an application to behave in case of malformed log4j conf file? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: Verification of log4j configuration file
Add as first line log4j.debug=true to your config file and see how well your config file gets parsed Josef -Ursprüngliche Nachricht- Von: Antonio Rodriges [mailto:antonio@gmail.com] Gesendet: Samstag, 6. August 2011 11:49 An: log4j-user@logging.apache.org Betreff: Verification of log4j configuration file Hello, How to verify log4j configuration file to find out whether it is malformed or not? Can log4j notify me of bad file format? Thanks - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Verification of log4j configuration file
Hello, How to verify log4j configuration file to find out whether it is malformed or not? Can log4j notify me of bad file format? Thanks - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Log4j configuration
Hi, I am adding logging enhancement to my app. There is already a log4j wrapper is available in my app. But the existing is in jar and I can not modify. The problem is, now I have two log4j.xml file. one for my enhancement and other for existing one. I first initialize existing log4j wrapper, it uses DOMConfigurator.configure(initUrl) to configure. After this I call my new APIs, I follow the same DOMConfigurator.configure(initUrl) to override the configuration. The problem here is, I have custom appender, which I specified in log4j.xml of my enhancement, but the custom appender is called twice - once from existing APIs and another from my APIs. I dont know how log4j is invoking my custom appeder, when existing APIs are initialized. I looked this from stack trace. -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29285028.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4j configuration
Log4j configuration is cumulative. One call to configure() does not override another. Instead, the configurations are combined. Each time you configure() on a config file that defines an appender, a new one will be added rather than blow away the old one. Therefore you get duplicate logging as more than one appender is active. That said, it seems like this behavior was configurable? Or maybe we merely discussed it a while back since the default behavior is somewhat surprising to users? Maybe one of the other Log4j developers recalls this discussion and can provide details? Jake On Wed, 28 Jul 2010 03:17:25 -0700 (PDT) mokader moka...@cisco.com wrote: Hi, I am adding logging enhancement to my app. There is already a log4j wrapper is available in my app. But the existing is in jar and I can not modify. The problem is, now I have two log4j.xml file. one for my enhancement and other for existing one. I first initialize existing log4j wrapper, it uses DOMConfigurator.configure(initUrl) to configure. After this I call my new APIs, I follow the same DOMConfigurator.configure(initUrl) to override the configuration. The problem here is, I have custom appender, which I specified in log4j.xml of my enhancement, but the custom appender is called twice - once from existing APIs and another from my APIs. I dont know how log4j is invoking my custom appeder, when existing APIs are initialized. I looked this from stack trace. -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29285028.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4j configuration
Thanks Jake, Is there any way to override the configuration or remove the existing appenders. would the call to LogManager.shutdown()and then DOMConfigurator.configure(initUrl) work. Thanks in advance, Mohammed Jacob Kjome wrote: Log4j configuration is cumulative. One call to configure() does not override another. Instead, the configurations are combined. Each time you configure() on a config file that defines an appender, a new one will be added rather than blow away the old one. Therefore you get duplicate logging as more than one appender is active. That said, it seems like this behavior was configurable? Or maybe we merely discussed it a while back since the default behavior is somewhat surprising to users? Maybe one of the other Log4j developers recalls this discussion and can provide details? Jake On Wed, 28 Jul 2010 03:17:25 -0700 (PDT) mokader moka...@cisco.com wrote: Hi, I am adding logging enhancement to my app. There is already a log4j wrapper is available in my app. But the existing is in jar and I can not modify. The problem is, now I have two log4j.xml file. one for my enhancement and other for existing one. I first initialize existing log4j wrapper, it uses DOMConfigurator.configure(initUrl) to configure. After this I call my new APIs, I follow the same DOMConfigurator.configure(initUrl) to override the configuration. The problem here is, I have custom appender, which I specified in log4j.xml of my enhancement, but the custom appender is called twice - once from existing APIs and another from my APIs. I dont know how log4j is invoking my custom appeder, when existing APIs are initialized. I looked this from stack trace. -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29285028.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29289033.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4j configuration
On Wed, 28 Jul 2010 10:27:24 -0700 (PDT) mokader moka...@cisco.com wrote: Thanks Jake, Is there any way to override the configuration or remove the existing appenders. Yes, appenders can be removed manually by traversing the logging API. But, again, it seems like there was some way to tell Log4j not to be cumulative (at least I hope so). Hopefully someone else can shed light on this possibility. would the call to LogManager.shutdown()and then DOMConfigurator.configure(initUrl) work. I've never tested it. You should try it and report results. Jake Thanks in advance, Mohammed Jacob Kjome wrote: Log4j configuration is cumulative. One call to configure() does not override another. Instead, the configurations are combined. Each time you configure() on a config file that defines an appender, a new one will be added rather than blow away the old one. Therefore you get duplicate logging as more than one appender is active. That said, it seems like this behavior was configurable? Or maybe we merely discussed it a while back since the default behavior is somewhat surprising to users? Maybe one of the other Log4j developers recalls this discussion and can provide details? Jake On Wed, 28 Jul 2010 03:17:25 -0700 (PDT) mokader moka...@cisco.com wrote: Hi, I am adding logging enhancement to my app. There is already a log4j wrapper is available in my app. But the existing is in jar and I can not modify. The problem is, now I have two log4j.xml file. one for my enhancement and other for existing one. I first initialize existing log4j wrapper, it uses DOMConfigurator.configure(initUrl) to configure. After this I call my new APIs, I follow the same DOMConfigurator.configure(initUrl) to override the configuration. The problem here is, I have custom appender, which I specified in log4j.xml of my enhancement, but the custom appender is called twice - once from existing APIs and another from my APIs. I dont know how log4j is invoking my custom appeder, when existing APIs are initialized. I looked this from stack trace. -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29285028.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- View this message in context: http://old.nabble.com/Log4j-configuration-tp29285028p29289033.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Doubt about log4j configuration and OCI
Thanks... I also have found that if I put the database jar ojdbc14-10.2.0.1.0.jar in tomcat lib folder, it workd properly!! -Mensaje original- De: Douglas E Wegscheid [mailto:douglas_e_wegsch...@whirlpool.com] Enviado el: martes, 18 de mayo de 2010 14:39 Para: Log4J Users List CC: 'log4j-user@logging.apache.org' Asunto: Re: Doubt about log4j configuration and OCI ahha. someone *has* done a JDBCAppender that will use an existing datasource. Take a look at http://www.boky.cc/2010/02/03/jdbcappender-for-log4j/ Douglas E Wegscheid Lead Technical Analyst, Whirlpool Corporation A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation. Exposito Aguilera, Francisco francisco.expos...@es.issworld.com wrote on 05/18/2010 08:14:04 AM: Hello, I have a doubt about how to configure log4j in order to avoid the error java.lang.UnsatisfiedLinkError: Native Library C:\oracle\product\10.2.0\client_1\BIN\ocijdbc10.dll already loaded in another classloader I want log write the log in the same database as the other sql statements I need for my application. I have a DAO Connection class with this method: public static Connection getConnection() { InitialContext initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(java:/comp/env); DataSource dataSource = (DataSource) envContext.lookup(jdbc/testdb); return dataSource.getConnection(); } This method uses the DB info placed in META-INF/context.xml file: Resource name=jdbc/testdb auth=Container type=javax.sql.DataSource username= password= driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:oci:@DESARROLLO maxActive=20 maxIdle=24/ Then I have my log4j.xml files configured like that: appender name=db class=org.apache.log4j.jdbc.JDBCAppender param name=driver value=oracle.jdbc.driver.OracleDriver/ param name=URL value=jdbc:oracle:oci:@DESARROLLO/ param name=user value=/ param name=password value=/ param name=sql value=INSERT INTO TABLE.LOG4JTEST (Fecha,Clase,Prioridad,usuario,Mensaje) VALUES ( '%n%d{-MM-dd HH:mm:ss}','%C-%M(%L)','%p',SUBSTR('%m',1,INSTR('%m',':')-1),SUBSTR('%m',INS TR('%m',':')+2))/ param name=sql value=INSERT INTO FEXPOSITO.LOG4JTEST (Fecha,Clase,Prioridad,usuario,Mensaje) VALUES ( '%n%d{-MM-dd HH:mm:ss}','%C-%M(%L)','%p','%m','%m')/ /appender But when I execute the first log.debug statement (the connection class has been already executed), I receive the error java.lang.UnsatisfiedLinkError: Native Library C:\oracle\product\10.2.0\client_1\BIN\ocijdbc10.dll already loaded in another classloader Any idea? Thanks in advance. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Doubt about log4j configuration and OCI
I don't think you can load the Oracle native driver more than once (that tries to load the native bits/dlls more than once, and that's what the Native Library already loaded is about). A couple of choices are to try to use the existing DataSource (which I don't think JDBCAppender can do out of the box, though I'd be surprised if no one has fixed that), or trying to leave the driverClassName off (if possible) so that you rely on the driver that was loaded earlier. (That's assuming the log4j appender is the later of the two to load, and that the JDBCAppender will let you leave off the driver parameter). Douglas E Wegscheid Lead Technical Analyst, Whirlpool Corporation A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation. Exposito Aguilera, Francisco francisco.expos...@es.issworld.com wrote on 05/18/2010 08:14:04 AM: Hello, I have a doubt about how to configure log4j in order to avoid the error java.lang.UnsatisfiedLinkError: Native Library C:\oracle\product\10.2.0\client_1\BIN\ocijdbc10.dll already loaded in another classloader I want log write the log in the same database as the other sql statements I need for my application. I have a DAO Connection class with this method: public static Connection getConnection() { InitialContext initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(java:/comp/env); DataSource dataSource = (DataSource) envContext.lookup(jdbc/testdb); return dataSource.getConnection(); } This method uses the DB info placed in META-INF/context.xml file: Resource name=jdbc/testdb auth=Container type=javax.sql.DataSource username= password= driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:oci:@DESARROLLO maxActive=20 maxIdle=24/ Then I have my log4j.xml files configured like that: appender name=db class=org.apache.log4j.jdbc.JDBCAppender param name=driver value=oracle.jdbc.driver.OracleDriver/ param name=URL value=jdbc:oracle:oci:@DESARROLLO/ param name=user value=/ param name=password value=/ param name=sql value=INSERT INTO TABLE.LOG4JTEST (Fecha,Clase,Prioridad,usuario,Mensaje) VALUES ( '%n%d{-MM-dd HH:mm:ss}','%C-%M(%L)','%p',SUBSTR('%m',1,INSTR('%m',':')-1),SUBSTR('%m',INS TR('%m',':')+2))/ param name=sql value=INSERT INTO FEXPOSITO.LOG4JTEST (Fecha,Clase,Prioridad,usuario,Mensaje) VALUES ( '%n%d{-MM-dd HH:mm:ss}','%C-%M(%L)','%p','%m','%m')/ /appender But when I execute the first log.debug statement (the connection class has been already executed), I receive the error java.lang.UnsatisfiedLinkError: Native Library C:\oracle\product\10.2.0\client_1\BIN\ocijdbc10.dll already loaded in another classloader Any idea? Thanks in advance. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Problem on including DTD entity in a log4j configuration file
On Nov 15, 2009, at 2:25 PM, Brett Randall wrote: What is in common.xml, and is it valid according to the dtd? Brett The message is reporting that the content after common.xml is merged is not valid according to the DTD. The DOMConfigurator is less strict than the DTD that specifies (ignoring atypical elements) all the appender elements appear first, then any logger elements, then an optional root element. In XML DTD, if you cannot constrain the number of elements of a specific type without constraining the order. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
RE: Changing log4j configuration runtime ...
Or in other words I want to do PropertyConfigurator.reconfigure(Properties prop); Is there any way to do this ? -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 12:13 PM To: 'Log4J Users List' Subject: RE: Changing log4j configuration runtime ... Thanks Yair for the reply! I have used property file only. The thing is the property file is open and if someone edit it and restart the java process he would be able to see all the DEBUG logs (which contains some critical information) I dont want this to happen so want to change at runtime (in code) the configuration! -Original Message- From: Yair Ogen [mailto:yairo...@gmail.com] Sent: Sunday, June 21, 2009 2:38 PM To: Log4J Users List Subject: Re: Changing log4j configuration runtime ... Why not use a regular property file? Then when you to update the file you can load the changes automatically using the PropertyConfigurator.configureAndWatch mechanism. On Sun, Jun 21, 2009 at 11:41 AM, Preetam Palwe preet...@aftek.com wrote: Hello all, I have successfully configured log4j in my standalone java application using PropertyConfigurator.configure() Here is the configuration file log4j.rootLogger=DBUG, LogFile log4j.logger.com.server.core=INFO log4j.logger. com.server.core.SecurityManager =DEBUG log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG log4j.appender.LogFile=org.apache.log4j.RollingFileAppender log4j.appender.LogFile.File=c:/server.log log4j.appender.LogFile.MaxFileSize=5MB log4j.appender.LogFile.MaxBackupIndex=10 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout log4j.appender.LogFile.layout.ConversionPattern=%d{ MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n In case of my application I have a security related library (securitylib.jar) in which there we do some is a critical security related processing. And I want to set logging level of INFO to all the classes/loggers from this jar. The log4j configuration is done before loading securitylib.jar using above configuration file. When securitylib.jar is loaded I tried to re-configure log4j using following code. (what I have done here is removed all the explicit loggers set in configuration file, updated the configuration properties and configured logger again) But when I test the system I am still able to see the DEBUG logs for classes/loggers com.server.core.SecurityManager and com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in config files) My questions are ... 1. Why after reconfiguring the loggers the new configuration is not getting reflected ? 2. Is there any way to get the current log4j configuration and change it at runtime ? Thanks in advance for your help! ~PP private void reinitLog4j() { try { String log4jFile = System.getProperty(log4j.file); Properties properties = new Properties(); properties.load(new FileInputStream(log4jFile)); updateLoggingConfiguration(properties); PropertyConfigurator.configure(properties); } catch (IOException ioEx) { throw new RuntimeException(failed to reconfigure logger + ioEx.getMessage(), ioEx); } logger = Logger.getLogger(this.getClass()); logger.info(Log4j RE initialised to use INFO logs everywhere !); logger.debug(THIS SHOULD NEVER COME IN LOGS); } private void updateLoggingConfiguration(Properties properties) { for (Iterator iterator = properties.entrySet().iterator(); iterator .hasNext();) { Entry entry = (Entry) iterator.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(log4j.rootLogger)) { entry.setValue(getRootLoggerConfiguration((String) entry .getValue())); } else if (key.startsWith(log4j.logger)) { iterator.remove(); } } } private String getRootLoggerConfiguration(String currentConfig) { String[] tokens = IOUtil.tokenizeString(currentConfig, ,); StringBuilder builder = new StringBuilder(); for (int i = 0; i tokens.length; i++) { if (i == 0) { builder.append(INFO); continue
RE: Changing log4j configuration runtime ...
I tried using new PropertyConfigurator().doConfigure(properties, LogManager .getLoggerRepository()); But still the configuration is not getting reflected ! Any idea? -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 12:54 PM To: 'Log4J Users List' Subject: RE: Changing log4j configuration runtime ... Or in other words I want to do PropertyConfigurator.reconfigure(Properties prop); Is there any way to do this ? -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 12:13 PM To: 'Log4J Users List' Subject: RE: Changing log4j configuration runtime ... Thanks Yair for the reply! I have used property file only. The thing is the property file is open and if someone edit it and restart the java process he would be able to see all the DEBUG logs (which contains some critical information) I dont want this to happen so want to change at runtime (in code) the configuration! -Original Message- From: Yair Ogen [mailto:yairo...@gmail.com] Sent: Sunday, June 21, 2009 2:38 PM To: Log4J Users List Subject: Re: Changing log4j configuration runtime ... Why not use a regular property file? Then when you to update the file you can load the changes automatically using the PropertyConfigurator.configureAndWatch mechanism. On Sun, Jun 21, 2009 at 11:41 AM, Preetam Palwe preet...@aftek.com wrote: Hello all, I have successfully configured log4j in my standalone java application using PropertyConfigurator.configure() Here is the configuration file log4j.rootLogger=DBUG, LogFile log4j.logger.com.server.core=INFO log4j.logger. com.server.core.SecurityManager =DEBUG log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG log4j.appender.LogFile=org.apache.log4j.RollingFileAppender log4j.appender.LogFile.File=c:/server.log log4j.appender.LogFile.MaxFileSize=5MB log4j.appender.LogFile.MaxBackupIndex=10 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout log4j.appender.LogFile.layout.ConversionPattern=%d{ MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n In case of my application I have a security related library (securitylib.jar) in which there we do some is a critical security related processing. And I want to set logging level of INFO to all the classes/loggers from this jar. The log4j configuration is done before loading securitylib.jar using above configuration file. When securitylib.jar is loaded I tried to re-configure log4j using following code. (what I have done here is removed all the explicit loggers set in configuration file, updated the configuration properties and configured logger again) But when I test the system I am still able to see the DEBUG logs for classes/loggers com.server.core.SecurityManager and com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in config files) My questions are ... 1. Why after reconfiguring the loggers the new configuration is not getting reflected ? 2. Is there any way to get the current log4j configuration and change it at runtime ? Thanks in advance for your help! ~PP private void reinitLog4j() { try { String log4jFile = System.getProperty(log4j.file); Properties properties = new Properties(); properties.load(new FileInputStream(log4jFile)); updateLoggingConfiguration(properties); PropertyConfigurator.configure(properties); } catch (IOException ioEx) { throw new RuntimeException(failed to reconfigure logger + ioEx.getMessage(), ioEx); } logger = Logger.getLogger(this.getClass()); logger.info(Log4j RE initialised to use INFO logs everywhere !); logger.debug(THIS SHOULD NEVER COME IN LOGS); } private void updateLoggingConfiguration(Properties properties) { for (Iterator iterator = properties.entrySet().iterator(); iterator .hasNext();) { Entry entry = (Entry) iterator.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(log4j.rootLogger)) { entry.setValue(getRootLoggerConfiguration((String) entry .getValue())); } else if (key.startsWith(log4j.logger)) { iterator.remove(); } } } private String getRootLoggerConfiguration(String currentConfig
RE: Changing log4j configuration runtime ...
It worked!!! Just added ... properties.put(log4j.reset, true); Thanks !!! -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 1:23 PM To: Log4J Users List Subject: RE: Changing log4j configuration runtime ... I tried using new PropertyConfigurator().doConfigure(properties, LogManager .getLoggerRepository()); But still the configuration is not getting reflected ! Any idea? -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 12:54 PM To: 'Log4J Users List' Subject: RE: Changing log4j configuration runtime ... Or in other words I want to do PropertyConfigurator.reconfigure(Properties prop); Is there any way to do this ? -Original Message- From: Preetam Palwe [mailto:preet...@aftek.com] Sent: Monday, June 22, 2009 12:13 PM To: 'Log4J Users List' Subject: RE: Changing log4j configuration runtime ... Thanks Yair for the reply! I have used property file only. The thing is the property file is open and if someone edit it and restart the java process he would be able to see all the DEBUG logs (which contains some critical information) I dont want this to happen so want to change at runtime (in code) the configuration! -Original Message- From: Yair Ogen [mailto:yairo...@gmail.com] Sent: Sunday, June 21, 2009 2:38 PM To: Log4J Users List Subject: Re: Changing log4j configuration runtime ... Why not use a regular property file? Then when you to update the file you can load the changes automatically using the PropertyConfigurator.configureAndWatch mechanism. On Sun, Jun 21, 2009 at 11:41 AM, Preetam Palwe preet...@aftek.com wrote: Hello all, I have successfully configured log4j in my standalone java application using PropertyConfigurator.configure() Here is the configuration file log4j.rootLogger=DBUG, LogFile log4j.logger.com.server.core=INFO log4j.logger. com.server.core.SecurityManager =DEBUG log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG log4j.appender.LogFile=org.apache.log4j.RollingFileAppender log4j.appender.LogFile.File=c:/server.log log4j.appender.LogFile.MaxFileSize=5MB log4j.appender.LogFile.MaxBackupIndex=10 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout log4j.appender.LogFile.layout.ConversionPattern=%d{ MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n In case of my application I have a security related library (securitylib.jar) in which there we do some is a critical security related processing. And I want to set logging level of INFO to all the classes/loggers from this jar. The log4j configuration is done before loading securitylib.jar using above configuration file. When securitylib.jar is loaded I tried to re-configure log4j using following code. (what I have done here is removed all the explicit loggers set in configuration file, updated the configuration properties and configured logger again) But when I test the system I am still able to see the DEBUG logs for classes/loggers com.server.core.SecurityManager and com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in config files) My questions are ... 1. Why after reconfiguring the loggers the new configuration is not getting reflected ? 2. Is there any way to get the current log4j configuration and change it at runtime ? Thanks in advance for your help! ~PP private void reinitLog4j() { try { String log4jFile = System.getProperty(log4j.file); Properties properties = new Properties(); properties.load(new FileInputStream(log4jFile)); updateLoggingConfiguration(properties); PropertyConfigurator.configure(properties); } catch (IOException ioEx) { throw new RuntimeException(failed to reconfigure logger + ioEx.getMessage(), ioEx); } logger = Logger.getLogger(this.getClass()); logger.info(Log4j RE initialised to use INFO logs everywhere !); logger.debug(THIS SHOULD NEVER COME IN LOGS); } private void updateLoggingConfiguration(Properties properties) { for (Iterator iterator = properties.entrySet().iterator(); iterator .hasNext();) { Entry entry = (Entry) iterator.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(log4j.rootLogger)) { entry.setValue(getRootLoggerConfiguration((String) entry .getValue
Changing log4j configuration runtime ...
Hello all, I have successfully configured log4j in my standalone java application using PropertyConfigurator.configure() Here is the configuration file log4j.rootLogger=DBUG, LogFile log4j.logger.com.server.core=INFO log4j.logger. com.server.core.SecurityManager =DEBUG log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG log4j.appender.LogFile=org.apache.log4j.RollingFileAppender log4j.appender.LogFile.File=c:/server.log log4j.appender.LogFile.MaxFileSize=5MB log4j.appender.LogFile.MaxBackupIndex=10 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout log4j.appender.LogFile.layout.ConversionPattern=%d{ MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n In case of my application I have a security related library (securitylib.jar) in which there we do some is a critical security related processing. And I want to set logging level of INFO to all the classes/loggers from this jar. The log4j configuration is done before loading securitylib.jar using above configuration file. When securitylib.jar is loaded I tried to re-configure log4j using following code. (what I have done here is removed all the explicit loggers set in configuration file, updated the configuration properties and configured logger again) But when I test the system I am still able to see the DEBUG logs for classes/loggers com.server.core.SecurityManager and com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in config files) My questions are ... 1. Why after reconfiguring the loggers the new configuration is not getting reflected ? 2. Is there any way to get the current log4j configuration and change it at runtime ? Thanks in advance for your help! ~PP private void reinitLog4j() { try { String log4jFile = System.getProperty(log4j.file); Properties properties = new Properties(); properties.load(new FileInputStream(log4jFile)); updateLoggingConfiguration(properties); PropertyConfigurator.configure(properties); } catch (IOException ioEx) { throw new RuntimeException(failed to reconfigure logger + ioEx.getMessage(), ioEx); } logger = Logger.getLogger(this.getClass()); logger.info(Log4j RE initialised to use INFO logs everywhere !); logger.debug(THIS SHOULD NEVER COME IN LOGS); } private void updateLoggingConfiguration(Properties properties) { for (Iterator iterator = properties.entrySet().iterator(); iterator .hasNext();) { Entry entry = (Entry) iterator.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(log4j.rootLogger)) { entry.setValue(getRootLoggerConfiguration((String) entry .getValue())); } else if (key.startsWith(log4j.logger)) { iterator.remove(); } } } private String getRootLoggerConfiguration(String currentConfig) { String[] tokens = IOUtil.tokenizeString(currentConfig, ,); StringBuilder builder = new StringBuilder(); for (int i = 0; i tokens.length; i++) { if (i == 0) { builder.append(INFO); continue; } builder.append(, + tokens[i]); } return builder.toString(); }
Re: Changing log4j configuration runtime ...
Why not use a regular property file? Then when you to update the file you can load the changes automatically using the PropertyConfigurator.configureAndWatch mechanism. On Sun, Jun 21, 2009 at 11:41 AM, Preetam Palwe preet...@aftek.com wrote: Hello all, I have successfully configured log4j in my standalone java application using PropertyConfigurator.configure() Here is the configuration file log4j.rootLogger=DBUG, LogFile log4j.logger.com.server.core=INFO log4j.logger. com.server.core.SecurityManager =DEBUG log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG log4j.appender.LogFile=org.apache.log4j.RollingFileAppender log4j.appender.LogFile.File=c:/server.log log4j.appender.LogFile.MaxFileSize=5MB log4j.appender.LogFile.MaxBackupIndex=10 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout log4j.appender.LogFile.layout.ConversionPattern=%d{ MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n In case of my application I have a security related library (securitylib.jar) in which there we do some is a critical security related processing. And I want to set logging level of INFO to all the classes/loggers from this jar. The log4j configuration is done before loading securitylib.jar using above configuration file. When securitylib.jar is loaded I tried to re-configure log4j using following code. (what I have done here is removed all the explicit loggers set in configuration file, updated the configuration properties and configured logger again) But when I test the system I am still able to see the DEBUG logs for classes/loggers com.server.core.SecurityManager and com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in config files) My questions are ... 1. Why after reconfiguring the loggers the new configuration is not getting reflected ? 2. Is there any way to get the current log4j configuration and change it at runtime ? Thanks in advance for your help! ~PP private void reinitLog4j() { try { String log4jFile = System.getProperty(log4j.file); Properties properties = new Properties(); properties.load(new FileInputStream(log4jFile)); updateLoggingConfiguration(properties); PropertyConfigurator.configure(properties); } catch (IOException ioEx) { throw new RuntimeException(failed to reconfigure logger + ioEx.getMessage(), ioEx); } logger = Logger.getLogger(this.getClass()); logger.info(Log4j RE initialised to use INFO logs everywhere !); logger.debug(THIS SHOULD NEVER COME IN LOGS); } private void updateLoggingConfiguration(Properties properties) { for (Iterator iterator = properties.entrySet().iterator(); iterator .hasNext();) { Entry entry = (Entry) iterator.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(log4j.rootLogger)) { entry.setValue(getRootLoggerConfiguration((String) entry .getValue())); } else if (key.startsWith(log4j.logger)) { iterator.remove(); } } } private String getRootLoggerConfiguration(String currentConfig) { String[] tokens = IOUtil.tokenizeString(currentConfig, ,); StringBuilder builder = new StringBuilder(); for (int i = 0; i tokens.length; i++) { if (i == 0) { builder.append(INFO); continue; } builder.append(, + tokens[i]); } return builder.toString(); }
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]
static log4j configuration statement
Hi all, 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. Thanks for help! Sebastian - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: static log4j configuration statement
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]
RE: Syslog message is sent twice in the case no log4j configuration file is used
Nobody has an idea? -Original Message- From: Berwanger, Christian [mailto:[EMAIL PROTECTED] Sent: Dienstag, 8. Juli 2008 12:15 To: log4j-user@logging.apache.org Subject: Syslog message is sent twice in the case no log4j configuration file is used Hi log4j comunity, I'm using the log4j appender in order to send my log message to a remote host. I decided not to use the config file because the application itself is already using a central config file which I want to use to read my configurable data (like hostname, port...). However when I'm using the log4j API without config file the message is sent twice times. I read and tried already the hints on the tutorial sites without success which threads several ideas for the problem of multiple same messages. m_logger = Logger.getLogger(SecurityEvent.class.getName()); m_logger.setAdditivity(false); m_syslogAppender = new SyslogAppender(); m_syslogAppender.activateOptions(); m_syslogAppender.setLayout(new PatternLayout(%c: %m%n)); m_syslogAppender.setSyslogHost(localhost); m_logger.addAppender(m_syslogAppender); m_syslogAppender.setFacility(mapFacilityID(this.m_facility)); sendLogMessage(logMessage); m_logger.removeAllAppenders(); However when I tried following configuration file instead it worked fine. # Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.net.SyslogAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.SyslogHost=localhost log4j.appender.A1.layout.ConversionPattern=%c: %m%n How can I get only ONE log message? Thanks for all help Christian This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Syslog message is sent twice in the case no log4j configuration file is used
My only guess is that setting the additivity flag by code does not have any effect. Or maybe a kind of activateOptions() on the logger must be performed. Why dont you fetch the RootLogger for appending your syslog appender, as you do in your config example? After the log call you clear the appenders anyway. Heri -Original Message- From: Berwanger, Christian [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 09, 2008 9:27 AM To: Log4J Users List Subject: RE: Syslog message is sent twice in the case no log4j configuration file is used Nobody has an idea? -Original Message- From: Berwanger, Christian [mailto:[EMAIL PROTECTED] Sent: Dienstag, 8. Juli 2008 12:15 To: log4j-user@logging.apache.org Subject: Syslog message is sent twice in the case no log4j configuration file is used Hi log4j comunity, I'm using the log4j appender in order to send my log message to a remote host. I decided not to use the config file because the application itself is already using a central config file which I want to use to read my configurable data (like hostname, port...). However when I'm using the log4j API without config file the message is sent twice times. I read and tried already the hints on the tutorial sites without success which threads several ideas for the problem of multiple same messages. m_logger = Logger.getLogger(SecurityEvent.class.getName()); m_logger.setAdditivity(false); m_syslogAppender = new SyslogAppender(); m_syslogAppender.activateOptions(); m_syslogAppender.setLayout(new PatternLayout(%c: %m%n)); m_syslogAppender.setSyslogHost(localhost); m_logger.addAppender(m_syslogAppender); m_syslogAppender.setFacility(mapFacilityID(this.m_facility)); sendLogMessage(logMessage); m_logger.removeAllAppenders(); However when I tried following configuration file instead it worked fine. # Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.net.SyslogAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.SyslogHost=localhost log4j.appender.A1.layout.ConversionPattern=%c: %m%n How can I get only ONE log message? Thanks for all help Christian This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. - 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: Syslog message is sent twice in the case no log4j configuration file is used
Thx Heri for answering! Following code unfortunately produces the same problem. I still receive the message twice. m_logger = Logger.getRootLogger(); m_logger.setAdditivity(false); m_syslogAppender = new SyslogAppender(); m_syslogAppender.activateOptions(); m_syslogAppender.setLayout(new PatternLayout(%c: %m%n)); m_syslogAppender.setSyslogHost(localhost); m_logger.addAppender(m_syslogAppender); m_syslogAppender.setFacility(mapFacilityID(this.m_facility)); sendLogMessage(logMessage); m_logger.removeAllAppenders(); The only thing what I could imagine is that in the case there is no configuration file defined the system automatically generates a standard configuration with a standard syslog appender. To avoid this I tried to set the Additivity to false. I also called the getAllAppenders() in order to count the added appenders but I only got the right number of one! Has somebody any other ideas? Christian -Original Message- From: Bender Heri [mailto:[EMAIL PROTECTED] Sent: Mittwoch, 9. Juli 2008 15:59 To: Log4J Users List Subject: RE: Syslog message is sent twice in the case no log4j configuration file is used My only guess is that setting the additivity flag by code does not have any effect. Or maybe a kind of activateOptions() on the logger must be performed. Why dont you fetch the RootLogger for appending your syslog appender, as you do in your config example? After the log call you clear the appenders anyway. Heri -Original Message- From: Berwanger, Christian [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 09, 2008 9:27 AM To: Log4J Users List Subject: RE: Syslog message is sent twice in the case no log4j configuration file is used Nobody has an idea? -Original Message- From: Berwanger, Christian [mailto:[EMAIL PROTECTED] Sent: Dienstag, 8. Juli 2008 12:15 To: log4j-user@logging.apache.org Subject: Syslog message is sent twice in the case no log4j configuration file is used Hi log4j comunity, I'm using the log4j appender in order to send my log message to a remote host. I decided not to use the config file because the application itself is already using a central config file which I want to use to read my configurable data (like hostname, port...). However when I'm using the log4j API without config file the message is sent twice times. I read and tried already the hints on the tutorial sites without success which threads several ideas for the problem of multiple same messages. m_logger = Logger.getLogger(SecurityEvent.class.getName()); m_logger.setAdditivity(false); m_syslogAppender = new SyslogAppender(); m_syslogAppender.activateOptions(); m_syslogAppender.setLayout(new PatternLayout(%c: %m%n)); m_syslogAppender.setSyslogHost(localhost); m_logger.addAppender(m_syslogAppender); m_syslogAppender.setFacility(mapFacilityID(this.m_facility)); sendLogMessage(logMessage); m_logger.removeAllAppenders(); However when I tried following configuration file instead it worked fine. # Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.net.SyslogAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.SyslogHost=localhost log4j.appender.A1.layout.ConversionPattern=%c: %m%n How can I get only ONE log message? Thanks for all help Christian This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. - 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] This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should
Syslog message is sent twice in the case no log4j configuration file is used
Hi log4j comunity, I'm using the log4j appender in order to send my log message to a remote host. I decided not to use the config file because the application itself is already using a central config file which I want to use to read my configurable data (like hostname, port...). However when I'm using the log4j API without config file the message is sent twice times. I read and tried already the hints on the tutorial sites without success which threads several ideas for the problem of multiple same messages. m_logger = Logger.getLogger(SecurityEvent.class.getName()); m_logger.setAdditivity(false); m_syslogAppender = new SyslogAppender(); m_syslogAppender.activateOptions(); m_syslogAppender.setLayout(new PatternLayout(%c: %m%n)); m_syslogAppender.setSyslogHost(localhost); m_logger.addAppender(m_syslogAppender); m_syslogAppender.setFacility(mapFacilityID(this.m_facility)); sendLogMessage(logMessage); m_logger.removeAllAppenders(); However when I tried following configuration file instead it worked fine. # Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.net.SyslogAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.SyslogHost=localhost log4j.appender.A1.layout.ConversionPattern=%c: %m%n How can I get only ONE log message? Thanks for all help Christian This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
Re: How can I tell which log4j configuration file is being used?
The logic for selecting the configuration file is in the LogManager.java log4j class. The environment variable you're looking for might be: DEFAULT_INIT_OVERRIDE_KEY Do you remember where you set this? I'd like to know how you stop it looking at both files and instead allow the user to do BasicConfigurator.configure(); First log4j will look for the log4j.properties files Then if it doesnt find this it will look for the log4j.xml file If you want to see which one is has selected, use -Dlog4j.debug in your JVM arguments when you run your program. -- View this message in context: http://www.nabble.com/How-can-I-tell-which-log4j-configuration-file-is-being-used--tp17353608p17364347.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How can I tell which log4j configuration file is being used?
In the past I've set an environment variable to force log4j to output which log4j config file it is using - but I'll be damned if I can remember of find any trace of it again on the web. Can anyone help? Thanks, Alex -- View this message in context: http://www.nabble.com/How-can-I-tell-which-log4j-configuration-file-is-being-used--tp17353608p17353608.html Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How can I tell which log4j configuration file is being used?
Setting the log4j.debug system property to true should cause log4j internal diagnostic messages to be displayed to the console. java -Dlog4j.debug=true On May 20, 2008, at 7:17 PM, alexworden wrote: In the past I've set an environment variable to force log4j to output which log4j config file it is using - but I'll be damned if I can remember of find any trace of it again on the web. Can anyone help? Thanks, Alex -- View this message in context: http://www.nabble.com/How-can-I-tell-which-log4j-configuration-file-is-being-used--tp17353608p17353608.html Sent from the Log4j - Users mailing list archive at Nabble.com. - 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]
Dynamic log4j configuration
I'm working on a project where we want to dynamically configure log4j during a run. We want to change log levels, appenders, and filters in real time. The configureAndWait() method doesn't look like it would work well for our needs because: 1) It would be a performance hog if we wanted it to act real time (delay 500 ms) 2) We don't want to persist configuration changes from run to run (and if we write to the file that would be the default) So I was thinking of loading the config file, and for dynamic changes simply changing the properties objects and calling the reset and configure methods. I am confused, though, on why the PropertyConfigurator doesn't allow dynamic changes to filters (and only the DOMConfigurator does). I looked at the DOMConfigurator briefly and I see that it calls the addFilter() method of appender Is there any reason why the PropertyConfigurator doesn't do this? Would it be ok for me to use a PropertyConfigurator, and call addFilter() to deal with filter changes myself? I ask because I think connecting a UI with DOMConfigurator would be a bit clumsy, I'd have to hand craft XML for each change I want to send back.
Re: Websphere log4j configuration
On Mon, 21 Apr 2008 18:04:58 -0700 Himanshu Shah [EMAIL PROTECTED] wrote: I have .ear application deployed in websphere. It has two war, one ejb and one rar modules. I set the -Dlog4j.configuration=path to log4j.xml file as JVM argument. In websphere my application class loading policy is set to: - Classloader order: Classes loaded with application class loader first - WAR class loader policy: Single class loader for application I have my custom layout class which extends log4j's layout. I have implemented getHeader() method which returns information such as product name, version, host name etc. My problem is during websphere and application startup header gets printed twice in log files (log messages are ok, they are not printed twice). After debugging it looks like log4j is initialized twice during each war loading. That's curious. I would expect log messages to be duplicates as well if configuration was performed twice? Is this possible? Or is it something else? P.S. log4j.jar resides in my application's .ear file. Does any code in your app (or 3rd party apps) manually call configure()? Of course, that wouldn't expalin by there's not duplicate log messages. Jake -- Himanshu - Fill the brain with high thoughts, highest ideals, place them day and night before you, and out of that will come great work. - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Websphere log4j configuration
I have .ear application deployed in websphere. It has two war, one ejb and one rar modules. I set the -Dlog4j.configuration=path to log4j.xml file as JVM argument. In websphere my application class loading policy is set to: - Classloader order: Classes loaded with application class loader first - WAR class loader policy: Single class loader for application I have my custom layout class which extends log4j's layout. I have implemented getHeader() method which returns information such as product name, version, host name etc. My problem is during websphere and application startup header gets printed twice in log files (log messages are ok, they are not printed twice). After debugging it looks like log4j is initialized twice during each war loading. Is this possible? Or is it something else? P.S. log4j.jar resides in my application's .ear file. -- Himanshu - Fill the brain with high thoughts, highest ideals, place them day and night before you, and out of that will come great work. -
AW: multiple web application in same web container using different log4j configuration
Hi Jake, thanks for your answers. And yes, I realized that 1.3 is dead. I will switch back to the 1.2 branch as far as possible. Greetings and have a nice weekend, Andreas -Ursprüngliche Nachricht- Von: Jacob Kjome [mailto:[EMAIL PROTECTED] Gesendet: Do 28.02.2008 16:09 An: Log4J Users List Betreff: Re: multiple web application in same web container using different log4j configuration You have one of two choices. 1. Put Log4j in a parent classloader where all apps can see it and use a repository selector, usually based on JNDI. 2. Don't put log4j in a parent classloader. Only put it in WEB-INF/lib for each webapp. And put log4j.xml in WEB-INF/classes for each webapp. Since none of the webapps will be using the same log4j instance, they will each use a separate logger repository. BTW, you do realize that Log4j-1.3 is not an official version of Log4j and development has ceased in favor of further development of Logj4-1.2.xx along with Log4j companions for some Log4j-1.3 specific functionality? Jake On Thu, 28 Feb 2008 15:16:15 +0100 Andreas Grund [EMAIL PROTECTED] wrote: Hi Mailinglist, I have several web applications running in the same container. I want to use different log4j config files for them, but I have problems to do so. The problem is, that every time just one web application is logging. I use the weblogic 8.1 application server and log4j 1.3. What do I have to do to activate logging for every web application or isn´t it possible? Thanks for your help! Greetings, Andreas -- Andreas Grund externer Mitarbeiter Projet GUTS bei Conti mailto:[EMAIL PROTECTED] Mobile: Germany Phone: Fax: Geschäftsführer: Ingo Kriescher Amtsgericht Düsseldorf HRB48672 - 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]
multiple web application in same web container using different log4j configuration
Hi Mailinglist, I have several web applications running in the same container. I want to use different log4j config files for them, but I have problems to do so. The problem is, that every time just one web application is logging. I use the weblogic 8.1 application server and log4j 1.3. What do I have to do to activate logging for every web application or isn´t it possible? Thanks for your help! Greetings, Andreas -- Andreas Grund externer Mitarbeiter Projet GUTS bei Conti mailto:[EMAIL PROTECTED] Mobile: Germany Phone: Fax: Geschäftsführer: Ingo Kriescher Amtsgericht Düsseldorf HRB48672 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multiple web application in same web container using different log4j configuration
You have one of two choices. 1. Put Log4j in a parent classloader where all apps can see it and use a repository selector, usually based on JNDI. 2. Don't put log4j in a parent classloader. Only put it in WEB-INF/lib for each webapp. And put log4j.xml in WEB-INF/classes for each webapp. Since none of the webapps will be using the same log4j instance, they will each use a separate logger repository. BTW, you do realize that Log4j-1.3 is not an official version of Log4j and development has ceased in favor of further development of Logj4-1.2.xx along with Log4j companions for some Log4j-1.3 specific functionality? Jake On Thu, 28 Feb 2008 15:16:15 +0100 Andreas Grund [EMAIL PROTECTED] wrote: Hi Mailinglist, I have several web applications running in the same container. I want to use different log4j config files for them, but I have problems to do so. The problem is, that every time just one web application is logging. I use the weblogic 8.1 application server and log4j 1.3. What do I have to do to activate logging for every web application or isn´t it possible? Thanks for your help! Greetings, Andreas -- Andreas Grund externer Mitarbeiter Projet GUTS bei Conti mailto:[EMAIL PROTECTED] Mobile: Germany Phone: Fax: Geschäftsführer: Ingo Kriescher Amtsgericht Düsseldorf HRB48672 - 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]
Forcing XML configuration file to reset Log4J configuration
Folks, Been bit by the incremental nature of XML configuration application. Is there any way to not apply a changed XML configuration incrementally, but instead force full reset to reflect the state of the configuration file? Cheers - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Forcing XML configuration file to reset Log4J configuration
Thanks Matthew. We're talking about a JBoss environment using the configureAndWatch type of mechanism to pick up the XML configuration changes. There is no way to fully reset and reload the configuration w/o restarting the logging service? Matthew Kemp wrote: To reset an entire configuration you need something like this: public void reloadLog4J() { LogManager.resetConfiguration(); DOMConfigurator.configure(log4j.xml); } Unfortunately, even the DOMConfigurator.configureAndWatch() only does an incremental reload. Matt On Nov 13, 2007 3:58 PM, Paul Duffy [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Folks, Been bit by the incremental nature of XML configuration application. Is there any way to not apply a changed XML configuration incrementally, but instead force full reset to reflect the state of the configuration file? Cheers - To unsubscribe, e-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Forcing XML configuration file to reset Log4J configuration
On Nov 13, 2007, at 3:58 PM, Paul Duffy wrote: Folks, Been bit by the incremental nature of XML configuration application. Is there any way to not apply a changed XML configuration incrementally, but instead force full reset to reflect the state of the configuration file? Cheers log4j 1.2.15 and later support a reset attribute on the log4j:configuration element: log4j:configuration reset=true See http://issues.apache.org/bugzilla/show_bug.cgi?id=17531 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Log4j Configuration
Hi Anybody got any ideas on this one? Am i in correct mail list? Rgds Ed Howard GSK House D3-133 ext 4996 external 00 44 020 8047 4996 [EMAIL PROTECTED] wrote on 25/06/2007 16:26:32: Hi Hopefully someone can help me. I want to configure log4j from a properties file. I am writing a little java application. I have several log4j appenders and everything works well. However I want the option to exit application if ANY of log4j configuration fails. By default I am seeing a warning message from Log4j but application continues to run... Do you know of a property to set for log4j that application exits if log4j properties are not correct? OR should I attempt this programmicatally. Rgds Ed Howard --- This e-mail was sent by GlaxoSmithKline Services Unlimited (registered in England and Wales No. 1047315), which is a member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS. --- --- This e-mail was sent by GlaxoSmithKline Services Unlimited (registered in England and Wales No. 1047315), which is a member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS. ---
RE: Log4j Configuration
Ed -- Here's my recommendation: 1) Create a class that extends java.io.PrintStream. 2) In this class, override the public void println(String) method. In the overridden method, evaluate the string that's being written. If the string that's being written begins with log4j:ERROR , then record the fact that log4j has encountered an error. 3) Before log4j loads it's configuration, replace System.err with your extension of java.io.PrintStream. 4) Let log4j configure itself. 5) After the configuration is complete, restore System.err to the original PrintStream and check your extension of java.io.PrintStream to see if log4j wrote any error messages to System.err. Here's some code: // This is my extension of java.io.PrintStream public class MyPrintStream extends PrintStream { private List log4jErrors = new ArrayList(); public MyPrintStream(OutputStream out) throws FileNotFoundException { super(out); } public void println(String x) { // Record any errors that originate from log4j. if ((x != null) (x.startsWith(log4j:ERROR ))) { log4jErrors.add(x); } super.println(x); } public String[] getLog4jErrors() { String[] result = new String[log4jErrors.size()]; result = (String[])log4jErrors.toArray(result); return result; } } // This class demonstrates how this would work. private void runTest() { try { // Setup a new error stream. MyPrintStream myPs = new MyPrintStream(System.err); PrintStream oldErr = System.err; System.setErr(myPs); // Configure log4j. DOMConfigurator.configureAndWatch(log4j.xml); // Since my configuration has no errors in it, log4j didn't write // anything out to it's 'raw' logger. So, just for testing purposes, // I am going to write some messages out to log4j's 'raw' logger in // order to illustrate how you can respond to any errors that occur // during configuration. In a 'normal' situation, you would not do // this. LogLog.error(Something bad has happened!!); LogLog.error(This is an exception, new Exception( This is the exception)); // Restore the old error stream. System.setErr(oldErr); // Check to see if log4j wrote anything out to System.err String[] errors = myPs.getLog4jErrors(); if ((errors != null) (errors.length != 0)) { System.out.println(log4j recorded + errors.length + (errors.length == 1 ? error. : errors.)); for (int i = 0; i errors.length; i++) { System.out.println(log4jErrors[ + i + ]= + errors[i]); } System.exit(1); } } catch (FileNotFoundException e) { e.printStackTrace(); } } Ron Gallagher, ATT Mobility -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 28, 2007 5:38 AM To: Log4J Users List Subject: Re: Log4j Configuration Hi Anybody got any ideas on this one? Am i in correct mail list? Rgds Ed Howard GSK House D3-133 ext 4996 external 00 44 020 8047 4996 [EMAIL PROTECTED] wrote on 25/06/2007 16:26:32: Hi Hopefully someone can help me. I want to configure log4j from a properties file. I am writing a little java application. I have several log4j appenders and everything works well. However I want the option to exit application if ANY of log4j configuration fails. By default I am seeing a warning message from Log4j but application continues to run... Do you know of a property to set for log4j that application exits if log4j properties are not correct? OR should I attempt this programmicatally. Rgds Ed Howard --- This e-mail was sent by GlaxoSmithKline Services Unlimited (registered in England and Wales No. 1047315), which is a member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS. --- --- This e-mail was sent by GlaxoSmithKline Services Unlimited (registered in England and Wales No. 1047315), which is a member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS. --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Log4j Configuration
Hi Hopefully someone can help me. I want to configure log4j from a properties file. I am writing a little java application. I have several log4j appenders and everything works well. However I want the option to exit application if ANY of log4j configuration fails. By default I am seeing a warning message from Log4j but application continues to run... Do you know of a property to set for log4j that application exits if log4j properties are not correct? OR should I attempt this programmicatally. Rgds Ed Howard --- This e-mail was sent by GlaxoSmithKline Services Unlimited (registered in England and Wales No. 1047315), which is a member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS. ---
Re: Can I change log4j configuration programatically?
It appears that I don't have that method...how do I get it? Do I have an older version? James Stauffer wrote: I believe you call it on the appender after you change its settings. On 10/11/06, vincentw [EMAIL PROTECTED] wrote: What would I call activateOptions() with? Bender Heri wrote: Yes, you can. Don't forget to call activateOptions() at the end of reconfiguring. You need not to restart the app. Heri -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6762094 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6783730 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
AppenderSkeleton has activateOptions() and SMTPAppender extends AppenderSkeleton so it should work. What version do you have? I would be surprised if any 1.2.x version that is less than a fre years old doesn't have that. On 10/12/06, vincentw [EMAIL PROTECTED] wrote: It appears that I don't have that method...how do I get it? Do I have an older version? James Stauffer wrote: I believe you call it on the appender after you change its settings. On 10/11/06, vincentw [EMAIL PROTECTED] wrote: What would I call activateOptions() with? Bender Heri wrote: Yes, you can. Don't forget to call activateOptions() at the end of reconfiguring. You need not to restart the app. Heri -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6762094 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6783730 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
Sorry, I found it...using the wrong object. Thanks James Stauffer wrote: AppenderSkeleton has activateOptions() and SMTPAppender extends AppenderSkeleton so it should work. What version do you have? I would be surprised if any 1.2.x version that is less than a fre years old doesn't have that. On 10/12/06, vincentw [EMAIL PROTECTED] wrote: It appears that I don't have that method...how do I get it? Do I have an older version? James Stauffer wrote: I believe you call it on the appender after you change its settings. On 10/11/06, vincentw [EMAIL PROTECTED] wrote: What would I call activateOptions() with? Bender Heri wrote: Yes, you can. Don't forget to call activateOptions() at the end of reconfiguring. You need not to restart the app. Heri -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6762094 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6783730 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6784340 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
Its seems the new level doesn't take effect. So here's what I'm trying to do. I call a function initLogging to set up everything...call DOMConfigurator and pass it my log4j.xml file. So now log4j is setup with some default stuff. Now the cofig file may change the settings ie. logging level. Here's part of the code that does a check for config file ... if(useUserConfigFile) { aLogger.setMaxBackupIndex(zxConfig.getProperty(numLogs)); aLogger.setMaxFileSize(Long.parseLong(zxConfi.getProperty(logSize))); a.setLoggingLevel(root, zxConfig.getProperty(rootLogLevel)); a.setLoggingLevel(sql.xxx.xxx, zxConfig.getProperty(sqlLogLevel)); } Here is part of the code to set the new logging... ... Enumeration enLogger = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers(); Logger tmpLogger = null; /* If logger is root, then need to loop through all loggers under root * and change their logging levels too. Also, skip sql loggers so they * do not get effected. */ while(enLogger.hasMoreElements()) { tmpLogger = (Logger)(enLogger.nextElement()); if(tmpLogger.getName().startsWith(sql.xxx.xxx) logger.equals(sql.xxx.xxxi)) { tmpLogger.setLevel(Level.toLevel(level)); continue; } if(tmpLogger.getName().startsWith(xxx.xx) logger.equals(root)) { tmpLogger.setLevel(Level.toLevel(level)); } } while(enAppenders.hasMoreElements()) { appender = (Appender)enAppenders.nextElement(); if(appender.getName().equals(ASYNC)) { AsyncAppender asyncAppender = (AsyncAppender)appender; rfa = (RollingFileAppender)asyncAppender.getAppender(R); rfa.activateOptions(); ca = (ConsoleAppender)asyncAppender.getAppender(STDOUT); ca.activateOptions(); } } Another question is, at this point, I have use getLogger for a lot of packages. Now I want to change to logging level of my root package, and everything under it. I need to loop through all loggers like I have in the code right? Or is there a better way of doing this? Thanks -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6784793 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
A stand-alone Java application could use DOMConfigurator.configureAndWatch (but don't allow it to do automatic configuration). On 10/10/06, vincentw [EMAIL PROTECTED] wrote: I'm don't quite understand the question. it's a java application. James Stauffer wrote: In what kind of environment are you running? On 10/10/06, vincentw [EMAIL PROTECTED] wrote: Hi I'm new to using log4j and would like to know if I can change the configuration of log4j while it is already running. I have passed my log4j.xml to the DOMConfigurator and then I would like to change some settings. Here is my log4j.xml file ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=false !-- ==Appenders== -- !-- Define asyncAppender -- appender name=ASYNC class=org.apache.log4j.AsyncAppender appender-ref ref=STDOUT/ appender-ref ref=R/ /appender !-- Define STDOUT to a console -- appender name=STDOUT class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender !-- Define R; Rolling file logger -- appender name=R class=org.apache.log4j.RollingFileAppender param name=File value=logs/adminlog.txt/ param name=MaxFileSize value=100KB/ param name=MaxBackupIndex value=1/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender logger name=sql level value=off/ /logger !-- ==Setup the Root category== -- !-- rules for logging DEBUGINFOWARNERRORFATAL. -- root priority value = error/ appender-ref ref=ASYNC/ /root /log4j:configuration Now based on a user config file, I would like to change some of the config such as the MaxFileSize of the rolling file appender or the number of backup logs it keeps. I would also like to change the logging level of root or sql. Is it possible to to this? If so, how do I go about doing this? Thanks in advance -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6747745 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6750178 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
I see...no it's just a standalone Java application. James is probably wondering whether your code is running in a web container, such as Tomcat. In that case, LogWeb might be able to help http://www.codeczar.com/products/logweb/ It works great for me! Jake -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6757073 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
Well, I use DOMConfigurator initially, but what about when the program is running?? I would like to set a new root level or a log file size. Can I do something like Logger.getRootLogger.setLevel or something like that? If I do it this way do I have to stop and restart the logger? James Stauffer wrote: A stand-alone Java application could use DOMConfigurator.configureAndWatch (but don't allow it to do automatic configuration). -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6760580 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
Using configureAndWatch you can just change the file and it will update based on the changes. On 10/11/06, vincentw [EMAIL PROTECTED] wrote: Well, I use DOMConfigurator initially, but what about when the program is running?? I would like to set a new root level or a log file size. Can I do something like Logger.getRootLogger.setLevel or something like that? If I do it this way do I have to stop and restart the logger? James Stauffer wrote: A stand-alone Java application could use DOMConfigurator.configureAndWatch (but don't allow it to do automatic configuration). -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6760580 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
What would I call activateOptions() with? Bender Heri wrote: Yes, you can. Don't forget to call activateOptions() at the end of reconfiguring. You need not to restart the app. Heri -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6762094 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
I believe you call it on the appender after you change its settings. On 10/11/06, vincentw [EMAIL PROTECTED] wrote: What would I call activateOptions() with? Bender Heri wrote: Yes, you can. Don't forget to call activateOptions() at the end of reconfiguring. You need not to restart the app. Heri -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6762094 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Can I change log4j configuration programatically?
Hi I'm new to using log4j and would like to know if I can change the configuration of log4j while it is already running. I have passed my log4j.xml to the DOMConfigurator and then I would like to change some settings. Here is my log4j.xml file ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=false !-- ==Appenders== -- !-- Define asyncAppender -- appender name=ASYNC class=org.apache.log4j.AsyncAppender filter class=com.apani.common.log.RepeatFilter/ appender-ref ref=STDOUT/ appender-ref ref=R/ /appender !-- Define STDOUT to a console -- appender name=STDOUT class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender !-- Define R; Rolling file logger -- appender name=R class=org.apache.log4j.RollingFileAppender param name=File value=logs/adminlog.txt/ param name=MaxFileSize value=100KB/ param name=MaxBackupIndex value=1/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender logger name=sql level value=off/ /logger !-- ==Setup the Root category== -- !-- rules for logging DEBUGINFOWARNERRORFATAL. -- root priority value = error/ appender-ref ref=ASYNC/ /root /log4j:configuration Now based on a user config file, I would like to change some of the config such as the MaxFileSize of the rolling file appender or the number of backup logs it keeps. I would also like to change the logging level of root or sql. Is it possible to to this? If so, how do I go about doing this? Thanks in advance -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6747745 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
In what kind of environment are you running? On 10/10/06, vincentw [EMAIL PROTECTED] wrote: Hi I'm new to using log4j and would like to know if I can change the configuration of log4j while it is already running. I have passed my log4j.xml to the DOMConfigurator and then I would like to change some settings. Here is my log4j.xml file ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=false !-- ==Appenders== -- !-- Define asyncAppender -- appender name=ASYNC class=org.apache.log4j.AsyncAppender filter class=com.apani.common.log.RepeatFilter/ appender-ref ref=STDOUT/ appender-ref ref=R/ /appender !-- Define STDOUT to a console -- appender name=STDOUT class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender !-- Define R; Rolling file logger -- appender name=R class=org.apache.log4j.RollingFileAppender param name=File value=logs/adminlog.txt/ param name=MaxFileSize value=100KB/ param name=MaxBackupIndex value=1/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender logger name=sql level value=off/ /logger !-- ==Setup the Root category== -- !-- rules for logging DEBUGINFOWARNERRORFATAL. -- root priority value = error/ appender-ref ref=ASYNC/ /root /log4j:configuration Now based on a user config file, I would like to change some of the config such as the MaxFileSize of the rolling file appender or the number of backup logs it keeps. I would also like to change the logging level of root or sql. Is it possible to to this? If so, how do I go about doing this? Thanks in advance -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6747745 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
I'm don't quite understand the question. it's a java application. James Stauffer wrote: In what kind of environment are you running? On 10/10/06, vincentw [EMAIL PROTECTED] wrote: Hi I'm new to using log4j and would like to know if I can change the configuration of log4j while it is already running. I have passed my log4j.xml to the DOMConfigurator and then I would like to change some settings. Here is my log4j.xml file ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=false !-- ==Appenders== -- !-- Define asyncAppender -- appender name=ASYNC class=org.apache.log4j.AsyncAppender appender-ref ref=STDOUT/ appender-ref ref=R/ /appender !-- Define STDOUT to a console -- appender name=STDOUT class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender !-- Define R; Rolling file logger -- appender name=R class=org.apache.log4j.RollingFileAppender param name=File value=logs/adminlog.txt/ param name=MaxFileSize value=100KB/ param name=MaxBackupIndex value=1/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender logger name=sql level value=off/ /logger !-- ==Setup the Root category== -- !-- rules for logging DEBUGINFOWARNERRORFATAL. -- root priority value = error/ appender-ref ref=ASYNC/ /root /log4j:configuration Now based on a user config file, I would like to change some of the config such as the MaxFileSize of the rolling file appender or the number of backup logs it keeps. I would also like to change the logging level of root or sql. Is it possible to to this? If so, how do I go about doing this? Thanks in advance -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6747745 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6750178 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can I change log4j configuration programatically?
James is probably wondering whether your code is running in a web container, such as Tomcat. In that case, LogWeb might be able to help http://www.codeczar.com/products/logweb/ It works great for me! Jake At 11:38 PM 10/10/2006, you wrote: I'm don't quite understand the question. it's a java application. James Stauffer wrote: In what kind of environment are you running? On 10/10/06, vincentw [EMAIL PROTECTED] wrote: Hi I'm new to using log4j and would like to know if I can change the configuration of log4j while it is already running. I have passed my log4j.xml to the DOMConfigurator and then I would like to change some settings. Here is my log4j.xml file ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=false !-- ==Appenders== -- !-- Define asyncAppender -- appender name=ASYNC class=org.apache.log4j.AsyncAppender appender-ref ref=STDOUT/ appender-ref ref=R/ /appender !-- Define STDOUT to a console -- appender name=STDOUT class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender !-- Define R; Rolling file logger -- appender name=R class=org.apache.log4j.RollingFileAppender param name=File value=logs/adminlog.txt/ param name=MaxFileSize value=100KB/ param name=MaxBackupIndex value=1/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-17X{ipAddress} [%t] [%p] - %m%n/ /layout /appender logger name=sql level value=off/ /logger !-- ==Setup the Root category== -- !-- rules for logging DEBUGINFOWARNERRORFATAL. -- root priority value = error/ appender-ref ref=ASYNC/ /root /log4j:configuration Now based on a user config file, I would like to change some of the config such as the MaxFileSize of the rolling file appender or the number of backup logs it keeps. I would also like to change the logging level of root or sql. Is it possible to to this? If so, how do I go about doing this? Thanks in advance -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically --tf2420301.html#a6747745 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Can-I-change-log4j-configuration-programatically --tf2420301.html#a6750178 Sent from the Log4j - Users mailing list archive at Nabble.com. - 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]
Log4j Configuration without use of configandwatch
I am trying to figure out if there is a way to reload the properties file anytime it changes without restarting the system. One of our requirements is that the properties file can be changed and the logging will automatically change without restarting the system. I know you can use the PropertyConfigurator's configureAndWatch method, but I don't see how you could put this method in each class that instantiates a logger. It seems like way too much overhead. If anyone knows of a way to do this, I would appreciate it -- View this message in context: http://www.nabble.com/Log4j-Configuration-without-use-of-configandwatch-tf1888905.html#a5164447 Sent from the Log4j - Users forum at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Log4j Configuration without use of configandwatch
but I don't see how you could put this method in each class that instantiates a logger You dont have to put the statement in each and every class that uses a logger. Use can just invoke it once(in may be some central class of your application), thats it. sudhakardvvn [EMAIL PROTECTED] wrote: I am trying to figure out if there is a way to reload the properties file anytime it changes without restarting the system. One of our requirements is that the properties file can be changed and the logging will automatically change without restarting the system. I know you can use the PropertyConfigurator's configureAndWatch method, but I don't see how you could put this method in each class that instantiates a logger. It seems like way too much overhead. If anyone knows of a way to do this, I would appreciate it -- View this message in context: http://www.nabble.com/Log4j-Configuration-without-use-of-configandwatch-tf1888905.html#a5164447 Sent from the Log4j - Users forum at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Yahoo! India Answers: Share what you know. Learn something new Click here Catch all the FIFA World Cup 2006 action on Yahoo! India Click here
log4j and tomcat, context taking over log4j configuration for the whole enchilada?
Hi, I've got a tomcat 5.5 server running a bunch of webapps, each one with its own copy of log4j.jar and log4j.properties. Each one does terse logs to the tomcat console and a detailed log to a separate log file for each webapp. The problem is that, when I reload a context, that context's log4j configuration seems to take over the log4j configurations of every webapp, and all the applications start logging with that configuration, which is no good at all, since the terse logs now all come formatted with the reloaded context's pattern, and the verbose logs are lost since the only verbose log file logged to is the reloaded context's, while the other log files sit untouched, and every additivity configuration of the other webapps is lost. Can anybody shed some light on this? Thanks in advance, -- Javier Gonzalez Nicolini - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: log4j and tomcat, context taking over log4j configuration for the whole enchilada?
Ok, now I'm restarting and now the takeover is complete - even after a restart a single webapp's config is applied to every other webapp. Regarding a parent classloader, I'll have to look into it, although I'm positive that each context has its own log4j.jar (even different versions among some) and either a log4j.xml file or a log4j.properties file. I'm double-dog sure about that ;) The tomcat is running standalone, version 5.5.12 running on BEA's JRockit jvm, version 1.5.0_04-b05 Is there a way to debug or trace the classloader? thanks for your response, Javier On 1/10/06, Jacob Kjome [EMAIL PROTECTED] wrote: I'm not sure why it wouldn't be happening on initial startup, but is it possible that the webapp is finding a log4j.xml file in a parent classloader, which would be used in preference (by Log4j's auto-configuration mechanism) to log4j.properties in each webapp? If that's not the case, you aren't, by chance, running Tomcat-5.5 under JBoss or something like that, are you? Because at that point, the classloader behavior changes to not be child-first by default, which would explain the behavior you are seeing. Are you double-dog sure that log4j.jar is in *each* webapp's WEB-INF/lib? Jake Quoting Javier Gonzalez [EMAIL PROTECTED]: Hi, I've got a tomcat 5.5 server running a bunch of webapps, each one with its own copy of log4j.jar and log4j.properties. Each one does terse logs to the tomcat console and a detailed log to a separate log file for each webapp. The problem is that, when I reload a context, that context's log4j configuration seems to take over the log4j configurations of every webapp, and all the applications start logging with that configuration, which is no good at all, since the terse logs now all come formatted with the reloaded context's pattern, and the verbose logs are lost since the only verbose log file logged to is the reloaded context's, while the other log files sit untouched, and every additivity configuration of the other webapps is lost. Can anybody shed some light on this? Thanks in advance, -- Javier Gonzalez Nicolini - 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] -- Javier Gonzalez Nicolini - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
changing log4J configuration during run time
Hi, In log4J, if I change the configuration i.e. increase/decrease the level of a particular logger or add more appenders/categories in the config file, then do I have to restart the web server for that setting to take effect. What I understand from the documentation is that if I use DOMConfigurator.configureAndWatch(configFileName, timeInMilliSec) then I don't have to restart the server. Is this the only way to change the logging configuration during run time or there are some other ways also? If you use this method, then a thread is launched which continously monitors the config file changes. Is this technique has some serious performance overhead and therefore not preffered in production enviornment? What do people generally prefer - use this method OR simply use DOMConfigurator.configure(fileName) and restart the server after changing the config file? Thanks Deep - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: changing log4J configuration during run time
Quoting Deep Chand [EMAIL PROTECTED]: Hi, In log4J, if I change the configuration i.e. increase/decrease the level of a particular logger or add more appenders/categories in the config file, then do I have to restart the web server for that setting to take effect. Avoid configureAndWatch() in a J2EE environment. Instead use something like LogWeb... http://www.codeczar.com/products/logweb/index.html Jake What I understand from the documentation is that if I use DOMConfigurator.configureAndWatch(configFileName, timeInMilliSec) then I don't have to restart the server. Is this the only way to change the logging configuration during run time or there are some other ways also? If you use this method, then a thread is launched which continously monitors the config file changes. Is this technique has some serious performance overhead and therefore not preffered in production enviornment? What do people generally prefer - use this method OR simply use DOMConfigurator.configure(fileName) and restart the server after changing the config file? Thanks Deep - 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: Log4j Configuration
William Mok [EMAIL PROTECTED] wrote on 08/17/2005 05:47:29 PM: Your explanation is a lot better than those I found on web. Thx. I still have some questions, see below: Cool, glad it helped. I've run into all these problems before, so that why I've got a good knowledge of all the ways you can screw it up :^) - Original Message - From: [EMAIL PROTECTED] William Mok [EMAIL PROTECTED] wrote on 08/16/2005 03:59:25 PM: Thanks. Your explanation make everything much clearer. Look at the call to Logger.getLogger(EchoService.class): what it does is retrieves the fully qualified name of that class, e.g. com.mycompany.mypackage.echo.EchoService. It then looks for a logger defined for com.mycompany.mypackage.echo.EchoService. If it doesn't find that, it'll look for the next step up the hierarchy, i.e. com.mycompany.mypackage.echo, then com.mycompany.mypackage, and so on. Once you've defined this logger for com.mycompany.mypackage.echo, that's what it'll find. It will then write whatever messages you send to that logger to the defined appenders, as long as those messages have the effective level of the logger or above. I am a bit confused about the rootlogger and childlogger concepts, what's the reason behind having different logging hierarchy? What does the rootLogger actually do? , i.e. when do I use the rootLogger? The root logger is just kind of a default handler so that if you don't have any specific logging stuff set up for a particular area of your code there's a place for the messages to go. That's why the root logger is usually set to ERROR or FATAL. Wherever a critical error occurs in your code, you generally want to know about it. Child loggers for particular parts of your code hierarchy then let you set the logging levels and output for particular parts of the functionality you're developing. You can set the root logger to ERROR, so that anything critical that occurs anywhere in your application is logged. You can then set the logging levels for each area that you're developing to different levels so you can see what's going on in there. So let's say, in addition to all of the framework code, you've got two packages in your application, one for business objects and one for the interface. When you're working on the business objects, you can set the logging level to DEBUG and get verbose information about that package, but set the interface logging level to WARN. This means that you'll see a ton of information in the logs about your business objects and only interesting stuff about your interface code. Now you've developed the business objects, change the settings to WARN for your business objects and DEBUG for your interface and get a ton of information about your interface code. This change in the amount and type of information you get from each section is done without changing your code at all, since the filtering is done by just not sending messages to the log when they're sent with Logger.debug() when that's below the logging level you've set. The cool thing is that, if you're suddenly getting weird results from a section of your code, just ratchet down the logging level and you get a bunch more information out of that section. For example, when I've got a bunch of queries that are getting run, I always output the query itself as info and usually output the results (as long as there aren't TOO too many results expected) with debug. That way, if something odd happens, I can see the query and its results without having to step through the debugger slowly, etc. That's probably because the stdout is being diverted somewhere. If you're running your servlet container (e.g. Tomcat) from a shell script, then that message will be displayed on the actual console. If you're running from a service on Windows or some other script on *nix, then stdout is usually diverted to something like localhost_log.date.txt or something like that. Another option is to replace the System.out.println() call by opening a file in a known location and writing out to that. It's completely impossible that you're not getting a class loader, otherwise... well, none of your classes would load :^) That's correct, if I run it using Eclipse, I can see the search and destroy on the Eclipse console but not appearing in any of the logs. Yeah, then that's just a matter of figuring out what your servlet container thinks is stdout. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Log4j Configuration
William Mok [EMAIL PROTECTED] wrote on 08/16/2005 03:59:25 PM: Thanks. Your explanation make everything much clearer. I modified the log4j.properties file and run the servlet again, I can only see empty file axis.log being created but there is no logging inside. The issue with that is most likely one of two things: * The logging level is set so that debug or info messages are not being sent, so you won't see any messages unless something bad happens (warn, error, fatal). Try knocking down the logging level to debug and see if you get anything. * From your previous code, it looks like you had the axis.log appender attached to classes in the org.apache.axis.enterprise package and below. That's Axis code, not your own. So when you do the Logger.getLogger() call on your own class (EchoService?), it's actually retrieving a logger for com.mycompany.mypackage.echo.EchoService, or whatever the package is that contains that class. If there are no loggers defined for any level of that hierarchy (i.e. com, com.mycompany, com.mycompany.mypackage, etc.), then you'll get the root category logger. Try redefining that logger to something like: # Set the my logger to DEBUG and add the my appender. log4j.logger.com.mycompany.mypackage.echo=DEBUG, CONSOLE, ECHO # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender ... # ECHO is set to be a File appender using a PatternLayout. log4j.appender.ECHO=org.apache.log4j.FileAppender ... Look at the call to Logger.getLogger(EchoService.class): what it does is retrieves the fully qualified name of that class, e.g. com.mycompany.mypackage.echo.EchoService. It then looks for a logger defined for com.mycompany.mypackage.echo.EchoService. If it doesn't find that, it'll look for the next step up the hierarchy, i.e. com.mycompany.mypackage.echo, then com.mycompany.mypackage, and so on. Once you've defined this logger for com.mycompany.mypackage.echo, that's what it'll find. It will then write whatever messages you send to that logger to the defined appenders, as long as those messages have the effective level of the logger or above. Also the check for ClassLoader seems to fail, i.e. cl = NULL as I cannot find the Search and destroy in any logs. That's probably because the stdout is being diverted somewhere. If you're running your servlet container (e.g. Tomcat) from a shell script, then that message will be displayed on the actual console. If you're running from a service on Windows or some other script on *nix, then stdout is usually diverted to something like localhost_log.date.txt or something like that. Another option is to replace the System.out.println() call by opening a file in a known location and writing out to that. It's completely impossible that you're not getting a class loader, otherwise... well, none of your classes would load :^) However, I believe the log4j.properties has been picked up otherwise the axis.log file will not be created. Definitely. That right there proves that your instance of log4j.properties is being loaded. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Log4j Configuration
Your explanation is a lot better than those I found on web. Thx. I still have some questions, see below: - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Wednesday, August 17, 2005 8:43 AM Subject: Re: Log4j Configuration William Mok [EMAIL PROTECTED] wrote on 08/16/2005 03:59:25 PM: Thanks. Your explanation make everything much clearer. I modified the log4j.properties file and run the servlet again, I can only see empty file axis.log being created but there is no logging inside. The issue with that is most likely one of two things: * The logging level is set so that debug or info messages are not being sent, so you won't see any messages unless something bad happens (warn, error, fatal). Try knocking down the logging level to debug and see if you get anything. * From your previous code, it looks like you had the axis.log appender attached to classes in the org.apache.axis.enterprise package and below. That's Axis code, not your own. So when you do the Logger.getLogger() call on your own class (EchoService?), it's actually retrieving a logger for com.mycompany.mypackage.echo.EchoService, or whatever the package is that contains that class. If there are no loggers defined for any level of that hierarchy (i.e. com, com.mycompany, com.mycompany.mypackage, etc.), then you'll get the root category logger. Try redefining that logger to something like: # Set the my logger to DEBUG and add the my appender. log4j.logger.com.mycompany.mypackage.echo=DEBUG, CONSOLE, ECHO # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender ... # ECHO is set to be a File appender using a PatternLayout. log4j.appender.ECHO=org.apache.log4j.FileAppender ... Look at the call to Logger.getLogger(EchoService.class): what it does is retrieves the fully qualified name of that class, e.g. com.mycompany.mypackage.echo.EchoService. It then looks for a logger defined for com.mycompany.mypackage.echo.EchoService. If it doesn't find that, it'll look for the next step up the hierarchy, i.e. com.mycompany.mypackage.echo, then com.mycompany.mypackage, and so on. Once you've defined this logger for com.mycompany.mypackage.echo, that's what it'll find. It will then write whatever messages you send to that logger to the defined appenders, as long as those messages have the effective level of the logger or above. I am a bit confused about the rootlogger and childlogger concepts, what's the reason behind having different logging hierarchy? What does the rootLogger actually do? , i.e. when do I use the rootLogger? Also the check for ClassLoader seems to fail, i.e. cl = NULL as I cannot find the Search and destroy in any logs. That's probably because the stdout is being diverted somewhere. If you're running your servlet container (e.g. Tomcat) from a shell script, then that message will be displayed on the actual console. If you're running from a service on Windows or some other script on *nix, then stdout is usually diverted to something like localhost_log.date.txt or something like that. Another option is to replace the System.out.println() call by opening a file in a known location and writing out to that. It's completely impossible that you're not getting a class loader, otherwise... well, none of your classes would load :^) That's correct, if I run it using Eclipse, I can see the search and destroy on the Eclipse console but not appearing in any of the logs. However, I believe the log4j.properties has been picked up otherwise the axis.log file will not be created. Definitely. That right there proves that your instance of log4j.properties is being loaded. - 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]
Log4j Configuration
Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = null; try { appender = new FileAppender(layout,connectionlog.txt,true); } Questions: 1. So how does this configuration work, does the java code override the configuration on properties file? 2. What does BasicConfigurator do? 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot find this axis.log anywhere after running the servlet. In the java servlet, I have the line appender = new FileAppender(layout,connectionlog.txt,true);, but I cannot find the connectionlog.txt file anywhere. Thanks. William
RE: Log4j Configuration
I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = null; try { appender = new FileAppender(layout,connectionlog.txt,true); } Questions: 1. So how does this configuration work, does the java code override the configuration on properties file? 2. What does BasicConfigurator do? 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot find this axis.log anywhere after running the servlet. In the java servlet, I have the line appender = new FileAppender(layout,connectionlog.txt,true);, but I cannot find the connectionlog.txt file anywhere. Thanks. William - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Log4j Configuration
Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = null; try { appender = new FileAppender(layout,connectionlog.txt,true); } Questions: 1. So how does this configuration work, does the java code override the configuration on properties file? 2. What does BasicConfigurator do? 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot find this axis.log anywhere after running the servlet. In the java servlet, I have the line appender = new FileAppender(layout,connectionlog.txt,true);, but I cannot find the connectionlog.txt file anywhere. Thanks. William - 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: Log4j Configuration
You seem to be running it to the console -- Sys.out and axis.log ... if it doesn't hurt your application hard code a directory prefix and then you'll know where it ends up ie log4j.appender.LOGFILE.File=axis.log to log4j.appender.LOGFILE.File=c:\axis.log in log4j.xml I can use java properties so maybe try log4j.appender.LOGFILE.File=$(user.dir}/axis.log if this is not clear reply and ill find the link for you -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 1:58 PM To: Log4J Users List Subject: Re: Log4j Configuration Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = null; try { appender = new FileAppender(layout,connectionlog.txt,true); } Questions: 1. So how does this configuration work, does the java code override the configuration on properties file? 2. What does BasicConfigurator do? 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot find this axis.log anywhere after running the servlet. In the java servlet, I have the line appender = new FileAppender(layout,connectionlog.txt,true);, but I cannot find the connectionlog.txt file anywhere. Thanks. William - 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: Log4j Configuration
Thanks, I changed the line to log4j.appender.LOGFILE.File=/sandbox/axis.log reatart tomcat, but the axis.log still does not exist. Another problem is that even I have specified the properties file in CLASSPATH, I got this warning when I try to deploy my servlet. Somehow it just cannot find the properties file ?? log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please initialize the log4j system properly. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:01 PM Subject: RE: Log4j Configuration You seem to be running it to the console -- Sys.out and axis.log ... if it doesn't hurt your application hard code a directory prefix and then you'll know where it ends up ie log4j.appender.LOGFILE.File=axis.log to log4j.appender.LOGFILE.File=c:\axis.log in log4j.xml I can use java properties so maybe try log4j.appender.LOGFILE.File=$(user.dir}/axis.log if this is not clear reply and ill find the link for you -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 1:58 PM To: Log4J Users List Subject: Re: Log4j Configuration Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = null; try { appender = new FileAppender(layout,connectionlog.txt,true); } Questions: 1. So how does this configuration work, does the java code override the configuration on properties file? 2. What does BasicConfigurator do? 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot find this axis.log anywhere after running the servlet. In the java servlet, I have the line appender = new FileAppender(layout,connectionlog.txt,true);, but I cannot find the connectionlog.txt file anywhere. Thanks. William - 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
Re: Log4j Configuration
Also add calls to other debug levels. I've had some real issues with the debug levels, what they get set to, and what I've thought they should get set to. So I'd go ahead and add: Logger logger = Logger.getLogger(EchoService.class); // Really, you shouldn't do this and instead set it with your props logger.setLevel((Level) Level.DEBUG); logger.debug(Here is some DEBUG); logger.info(Here is some INFO); logger.warn(Here is some WARN); logger.error(Here is some ERROR); logger.fatal(Here is some FATAL); William Mok [EMAIL PROTECTED] m To Log4J Users List 08/16/2005 12:18 log4j-user@logging.apache.org PM cc Subject Please respond to Re: Log4j Configuration Log4J Users List [EMAIL PROTECTED] ng.apache.org I have the following: Logger logger = Logger.getLogger(EchoService.class); logger.setLevel((Level) Level.DEBUG); logger.debug(Here is some DEBUG); - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:15 PM Subject: RE: Log4j Configuration public class WhatEver { private static Logger logger_m = Logger.getLogger( WhatEver.class ); public Whatever( ) { logger_m.error(HELP); } } DO you have this in your code? -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 2:13 PM To: Log4J Users List Subject: Re: Log4j Configuration Thanks, I changed the line to log4j.appender.LOGFILE.File=/sandbox/axis.log reatart tomcat, but the axis.log still does not exist. Another problem is that even I have specified the properties file in CLASSPATH, I got this warning when I try to deploy my servlet. Somehow it just cannot find the properties file ?? log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please initialize the log4j system properly. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:01 PM Subject: RE: Log4j Configuration You seem to be running it to the console -- Sys.out and axis.log ... if it doesn't hurt your application hard code a directory prefix and then you'll know where it ends up ie log4j.appender.LOGFILE.File=axis.log to log4j.appender.LOGFILE.File=c:\axis.log in log4j.xml I can use java properties so maybe try log4j.appender.LOGFILE.File=$(user.dir}/axis.log if this is not clear reply and ill find the link for you -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 1:58 PM To: Log4J Users List Subject: Re: Log4j Configuration Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE
Re: Log4j Configuration
Thanks. Rick. I am going to try all the stuff u advise. However, the thing I don't understand is how the log4j. properties file work with the FileAppender API call in the code. What I mean is the log4j.properties specify a file appender, and then in the code I specify another file appender, so is there a conflict? William - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:16 PM Subject: Re: Log4j Configuration William, Two things you can try: First, add an explicit path to the log file name. So set it to /var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log or whatever is appropriate depending on platform, perms, etc. You can also do something like ${catalina.home}/logs/axis.log or something like that too. What's valid is very dependent on your environment, so play around with that. The default directory for log output is the current directory, which in the case of a servlet container will usually be the container's home directory. So, for example, for Tomcat this means your /usr/local/tomcat or c:\Tomcat or wherever you've got it installed. I'm not sure where these might go for other containers. Second, check which log4j.properties file you're loading. I have a little code snippet here: http://slapfest.blogspot.com/2005/07/what-version-of-class-or-resource-am-i.html that you can use to find your log4j.properties. There may be a problem with that: in the cl.getResource() call, you may need to use log4j.properties rather than /log4j.properties, but I can't remember. That'll tell you if your definition is even getting loaded or if your servlet container is actually getting another log4j config from somewhere else. As far as your progammatically created appender, I can tell you why you won't see any output from there: you're not adding the appender to your logger. Try something like this: Logger logger = Logger.getLogger(EchoService.class); BasicConfigurator.configure(); SimpleLayout layout = new SimpleLayout(); FileAppender appender = new FileAppender(layout,connectionlog.txt,true); if (appender != null) { logger.addAppender(appender); } BTW, as far as the BasicConfigurator stuff? My guess is that that call is completely unnecessary and could even screw up your configuration (which is another possible reason why you might not be seeing any output into your log files, if it's somehow nuking the default configuration, which actually uses PropertyConfigurator). William Mok [EMAIL PROTECTED] m To Log4J Users List 08/16/2005 11:57 log4j-user@logging.apache.org AM cc Subject Please respond to Re: Log4j Configuration Log4J Users List [EMAIL PROTECTED] ng.apache.org Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
Re: Log4j Configuration
I have put log4j.properties under the directory where I have the class files, i.e. EchoService.class I have also included the code to test whether the properties file is being loaded, but I think the result is negative b'cos I cannot find the logging in catalina.out file. i.e. the classloader is null. Thanks anyway. William - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:19 PM Subject: Re: Log4j Configuration Don't put the properties file itself in the classpath, that won't help anything. Put the directory or jar file in which the properties file is stored in the classpath. There should be no folder package structure either, i.e. if it's /sandbox/classes, then log4j.properties should be in that directory, with other classes in, e.g. /sandbox/classes/org/myorg/myproj. Also, try out that code snippet I sent in my last post to see which properties file is actually getting loaded. And remove that BasicConfigurator call. And do this all one step at a time so you know which precise change fixed your problem! William Mok [EMAIL PROTECTED] m To Log4J Users List 08/16/2005 12:12 log4j-user@logging.apache.org PM cc Subject Please respond to Re: Log4j Configuration Log4J Users List [EMAIL PROTECTED] ng.apache.org Thanks, I changed the line to log4j.appender.LOGFILE.File=/sandbox/axis.log reatart tomcat, but the axis.log still does not exist. Another problem is that even I have specified the properties file in CLASSPATH, I got this warning when I try to deploy my servlet. Somehow it just cannot find the properties file ?? log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please initialize the log4j system properly. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:01 PM Subject: RE: Log4j Configuration You seem to be running it to the console -- Sys.out and axis.log ... if it doesn't hurt your application hard code a directory prefix and then you'll know where it ends up ie log4j.appender.LOGFILE.File=axis.log to log4j.appender.LOGFILE.File=c:\axis.log in log4j.xml I can use java properties so maybe try log4j.appender.LOGFILE.File=$(user.dir}/axis.log if this is not clear reply and ill find the link for you -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 1:58 PM To: Log4J Users List Subject: Re: Log4j Configuration Thanks, I have included the log4j.properties file in the CLASSPATH and restart tomcat, but I could not find any log file generated under the entire tomcat directory, after running the servlet. - Original Message - From: Harp, George [EMAIL PROTECTED] To: 'Log4J Users List' log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 10:51 AM Subject: RE: Log4j Configuration I don't have to put any configuration code in my appliaction I just make sure that log4j.properties or log4j.xml is in the clas path. -Original Message- From: William Mok [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 12:35 PM To: log4j-user@logging.apache.org Subject: Log4j Configuration Hi, I have the following log4j.properties file: --- # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n At the same time, I also have the following lines in my java servlet
Re: Log4j Configuration
If you create an appender programmatically and independently of the properties file, then it will simply work as an additional appender for that logger and be completely unaffected by the settings in the properties file. Note that you can do this same thing with the properties file and in fact, having just looked at your properties file, I know why, even if everything else is set properly, you're not getting any output to your axis.log file. Because you never send anything there. Note that I removed all of the appender definitions other than the name and class assignment: # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender ... # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender ... Basically, you have to understand that loggers and appenders are completely independent. Thus, you create an appender called CONSOLE which logs to the console (stdout) and an appender called LOGFILE that logs to axis.log. Great. Create a file and never write anything to it, and see how fast it fills up. Now you create a logger, a rootCategory logger, one for a specific package (e.g. your logger for org.apache.axis.enterprise), or whatever. You can set two main attributes for that logger (there are others, but don't worry about them for now): the default level for that logger (INFO for root and FATAL for org.apache.axis.enterprise) and the appender or APPENDERS to which the logger will write its messages. In this file, you're sending everything to the CONSOLE and nothing to the LOGFILE. What you probably want to do is something like this: # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE # Set the enterprise logger category to DEBUG and its appenders to CONSOLE and LOGFILE log4j.logger.org.apache.axis.enterprise=DEBUG, CONSOLE, LOGFILE # Then add the appender defines here I'm assuming that, because that LOGFILE appender is called axis.log that you want it set for your Axis stuff, so I added it to that. I also set the debug level down to DEBUG instead of FATAL, but really you can set it to whatever you want. So now, based on your properties definition, any message of DEBUG level or higher (i.e. pretty much all messages) sent to the org.apache.axis.enterprise logger (which will be messages from any class in that package or below) will go to the CONSOLE and to the LOGFILE logs. Any message of INFO or higher from any other packages will go only to the CONSOLE. Then, when you create a programmatic appender and assign it to a logger, messages sent to that logger will go to your new appender IN ADDITION to any other appenders already configured for that logger. Got it? :^) William Mok [EMAIL PROTECTED] m To Log4J Users List 08/16/2005 12:27 log4j-user@logging.apache.org PM cc Subject Please respond to Re: Log4j Configuration Log4J Users List [EMAIL PROTECTED] ng.apache.org Thanks. Rick. I am going to try all the stuff u advise. However, the thing I don't understand is how the log4j. properties file work with the FileAppender API call in the code. What I mean is the log4j.properties specify a file appender, and then in the code I specify another file appender, so is there a conflict? William - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:16 PM Subject: Re: Log4j Configuration William, Two things you can try: First, add an explicit path to the log file name. So set it to /var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log or whatever
Re: Log4j Configuration
Thanks. Your explanation make everything much clearer. I modified the log4j.properties file and run the servlet again, I can only see empty file axis.log being created but there is no logging inside. Also the check for ClassLoader seems to fail, i.e. cl = NULL as I cannot find the Search and destroy in any logs. However, I believe the log4j.properties has been picked up otherwise the axis.log file will not be created. ClassLoader cl = Thread.currentThread().getContextClassLoader(); while(cl != null) { java.net.URL loc = cl.getResource(/log4j.properties); System.out.println(Search and destroy -- + loc); cl = cl.getParent(); } - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:52 PM Subject: Re: Log4j Configuration If you create an appender programmatically and independently of the properties file, then it will simply work as an additional appender for that logger and be completely unaffected by the settings in the properties file. Note that you can do this same thing with the properties file and in fact, having just looked at your properties file, I know why, even if everything else is set properly, you're not getting any output to your axis.log file. Because you never send anything there. Note that I removed all of the appender definitions other than the name and class assignment: # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender ... # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender ... Basically, you have to understand that loggers and appenders are completely independent. Thus, you create an appender called CONSOLE which logs to the console (stdout) and an appender called LOGFILE that logs to axis.log. Great. Create a file and never write anything to it, and see how fast it fills up. Now you create a logger, a rootCategory logger, one for a specific package (e.g. your logger for org.apache.axis.enterprise), or whatever. You can set two main attributes for that logger (there are others, but don't worry about them for now): the default level for that logger (INFO for root and FATAL for org.apache.axis.enterprise) and the appender or APPENDERS to which the logger will write its messages. In this file, you're sending everything to the CONSOLE and nothing to the LOGFILE. What you probably want to do is something like this: # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE # Set the enterprise logger category to DEBUG and its appenders to CONSOLE and LOGFILE log4j.logger.org.apache.axis.enterprise=DEBUG, CONSOLE, LOGFILE # Then add the appender defines here I'm assuming that, because that LOGFILE appender is called axis.log that you want it set for your Axis stuff, so I added it to that. I also set the debug level down to DEBUG instead of FATAL, but really you can set it to whatever you want. So now, based on your properties definition, any message of DEBUG level or higher (i.e. pretty much all messages) sent to the org.apache.axis.enterprise logger (which will be messages from any class in that package or below) will go to the CONSOLE and to the LOGFILE logs. Any message of INFO or higher from any other packages will go only to the CONSOLE. Then, when you create a programmatic appender and assign it to a logger, messages sent to that logger will go to your new appender IN ADDITION to any other appenders already configured for that logger. Got it? :^) William Mok [EMAIL PROTECTED] m To Log4J Users List 08/16/2005 12:27 log4j-user@logging.apache.org PM cc Subject Please respond to Re: Log4j Configuration Log4J Users List [EMAIL PROTECTED] ng.apache.org Thanks. Rick. I am going to try all the stuff u advise. However, the thing I don't understand is how the log4j. properties file work with the FileAppender API call in the code. What I mean is the log4j.properties specify a file appender, and then in the code I specify another file appender, so is there a conflict? William - Original Message - From: [EMAIL PROTECTED] To: Log4J Users List log4j-user@logging.apache.org Sent: Tuesday, August 16, 2005 12:16 PM Subject: Re
Re: Problem with Log4j (Configuration)
For some reasons it is required ro use different configuration files... so whats the second solution of the problem? --- On Sat 12/18, Jacob Kjome [EMAIL PROTECTED] wrote: From: Jacob Kjome [mailto: [EMAIL PROTECTED] To: log4j-user@logging.apache.org Date: Sat, 18 Dec 2004 11:31:45 -0600 Subject: Re: Problem with Log4j (Configuration) At 05:20 PM 12/18/2004 +0100, you wrote:br br Amir,br br Are A.txt and B.txt the configuration files or the files where loggingbr output goes?br brbrI'm pretty sure he means that the .txt files are his log files and since he brhas two separate configurations, he expects appA's output to go to one file br(as it was configured in his appA config file) and he expects appB's output brto go to separate file (as it is configured in his appB config file). The brproblem is that there is only one config [file] per logger brrepository. When he says appA and appB, he means two jar files in the brsame application.brbrThe answer to this is that the approach is flawed. The way I interpret brthis is that ApplicationA.jar and ApplicationB.jar both have a log4j config brfile in their roots. This is a bad practice as someone else may use, for brinstance, ApplicationA.jar in their app but not want to have brApplicationA.jar defining their logger configuration. The problem is brthinking that configuration is happening per/library. It actually happens brper logger repository which, by default, is essentially per visible brclassloader hierarchy. If a repository selector is used, the configuration brhappens per whatever criteria the selector uses as a demarcation of logger brrepositories. This can add complexity which is necessary at times, but brprobably not here.brbrBecause of this, one should not distribute config files in jars. Logging bris for the end user, not the creator of the library. Remove the config brfiles from the libraries and use a single config file per/application. At brthis point, it is easy to send the output of the two libraries (with brdistinct package names) to separate log files...brbrappender name=File1 class=org.apache.log4j.FileAppenderbr param name=File value=file1.log /br/appenderbrappender name=File2 class=org.apache.log4j.FileAppenderbr param name=File value=file2.log /br/appenderbrbrlogger name=com.mycompany.librarya additivity=falsebr level value=debug/br appender-ref ref=File1/br/loggerbrbrlogger name=com.mycompany.libraryb additivity=falsebr level value=debug/br appender-ref ref=File2/br/loggerbrbrrootbrlevel value=warn/br appender-ref ref=Console/br/rootbrbrbrI hope that answers the question.brbrJakebrbr At 06:13 AM 12/17/2004, Ran//-\\mir wrote:br br Apologies are mine if this issue is discussed already.br I have two different applications i-e two separate jar filesbr (ApplicationA.jar and ApplicationB.jar).br Both use log4j for logging to separate files (A.txt and B.txt).br Now the scenario isbr ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jarbr and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationBbr runs, I expect to get logs in different files but unfortunately this doesbr not happen. ApplicationA makes some logging in B.txt and ApplicationB inbr A.txt. Though both are using different configuration files.br Is this normal? What is the solution to the problem?br Thanking in advance.br Amirbr br --br Ceki Gülcübr brThe complete log4j manual: http://qos.ch/log4j/br br br br -br To unsubscribe, e-mail: [EMAIL PROTECTED]br For additional commands, e-mail: [EMAIL PROTECTED]br br brbrbr-brTo unsubscribe, e-mail: [EMAIL PROTECTED]brFor additional commands, e-mail: [EMAIL PROTECTED]brbr ___ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with Log4j (Configuration)
thanks Jake, its working...:) but whats the detailed solution if i required two different configuration files. --- On Sat 12/18, Jacob Kjome [EMAIL PROTECTED] wrote: From: Jacob Kjome [mailto: [EMAIL PROTECTED] To: log4j-user@logging.apache.org Date: Sat, 18 Dec 2004 11:31:45 -0600 Subject: Re: Problem with Log4j (Configuration) At 05:20 PM 12/18/2004 +0100, you wrote:br br Amir,br br Are A.txt and B.txt the configuration files or the files where loggingbr output goes?br brbrI'm pretty sure he means that the .txt files are his log files and since he brhas two separate configurations, he expects appA's output to go to one file br(as it was configured in his appA config file) and he expects appB's output brto go to separate file (as it is configured in his appB config file). The brproblem is that there is only one config [file] per logger brrepository. When he says appA and appB, he means two jar files in the brsame application.brbrThe answer to this is that the approach is flawed. The way I interpret brthis is that ApplicationA.jar and ApplicationB.jar both have a log4j config brfile in their roots. This is a bad practice as someone else may use, for brinstance, ApplicationA.jar in their app but not want to have brApplicationA.jar defining their logger configuration. The problem is brthinking that configuration is happening per/library. It actually happens brper logger repository which, by default, is essentially per visible brclassloader hierarchy. If a repository selector is used, the configuration brhappens per whatever criteria the selector uses as a demarcation of logger brrepositories. This can add complexity which is necessary at times, but brprobably not here.brbrBecause of this, one should not distribute config files in jars. Logging bris for the end user, not the creator of the library. Remove the config brfiles from the libraries and use a single config file per/application. At brthis point, it is easy to send the output of the two libraries (with brdistinct package names) to separate log files...brbrappender name=File1 class=org.apache.log4j.FileAppenderbr param name=File value=file1.log /br/appenderbrappender name=File2 class=org.apache.log4j.FileAppenderbr param name=File value=file2.log /br/appenderbrbrlogger name=com.mycompany.librarya additivity=falsebr level value=debug/br appender-ref ref=File1/br/loggerbrbrlogger name=com.mycompany.libraryb additivity=falsebr level value=debug/br appender-ref ref=File2/br/loggerbrbrrootbrlevel value=warn/br appender-ref ref=Console/br/rootbrbrbrI hope that answers the question.brbrJakebrbr At 06:13 AM 12/17/2004, Ran//-\\mir wrote:br br Apologies are mine if this issue is discussed already.br I have two different applications i-e two separate jar filesbr (ApplicationA.jar and ApplicationB.jar).br Both use log4j for logging to separate files (A.txt and B.txt).br Now the scenario isbr ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jarbr and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationBbr runs, I expect to get logs in different files but unfortunately this doesbr not happen. ApplicationA makes some logging in B.txt and ApplicationB inbr A.txt. Though both are using different configuration files.br Is this normal? What is the solution to the problem?br Thanking in advance.br Amirbr br --br Ceki Gülcübr brThe complete log4j manual: http://qos.ch/log4j/br br br br -br To unsubscribe, e-mail: [EMAIL PROTECTED]br For additional commands, e-mail: [EMAIL PROTECTED]br br brbrbr-brTo unsubscribe, e-mail: [EMAIL PROTECTED]brFor additional commands, e-mail: [EMAIL PROTECTED]brbr ___ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with Log4j (Configuration)
well they are files where output goes And i am using different configuration files for both. -Original Message- From: Ceki Gülcü [mailto:[EMAIL PROTECTED] Sent: Saturday, December 18, 2004 9:20 PM To: Log4J Users List Subject: Re: Problem with Log4j (Configuration) Amir, Are A.txt and B.txt the configuration files or the files where logging output goes? At 06:13 AM 12/17/2004, Ran//-\\mir wrote: Apologies are mine if this issue is discussed already. I have two different applications i-e two separate jar files (ApplicationA.jar and ApplicationB.jar). Both use log4j for logging to separate files (A.txt and B.txt). Now the scenario is ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jar and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationB runs, I expect to get logs in different files but unfortunately this does not happen. ApplicationA makes some logging in B.txt and ApplicationB in A.txt. Though both are using different configuration files. Is this normal? What is the solution to the problem? Thanking in advance. Amir -- Ceki Gülcü The complete log4j manual: http://qos.ch/log4j/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Note: Kindly note that my email address has been changed to [EMAIL PROTECTED] The information transmitted (including any attachments) is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. ESP Global IT Systems does not guarantee that the integrity of this communication has been maintained nor that this communication is free of viruses, interceptions or interference. If you received this in error, please contact the sender and delete the material. If you require general information please email [EMAIL PROTECTED] == ESP Global IT Systems - The Software Solution Specialists © 2004 ESP Global IT Systems. All rights reserved. == - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with Log4j (Configuration)
well they are files where output goes And i am using different configuration files for both. --- On Sat 12/18, Ceki =?iso-8859-1?Q?G=FClc=FC?= [EMAIL PROTECTED] wrote: From: Ceki =?iso-8859-1?Q?G=FClc=FC?= [mailto: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date: Sat, 18 Dec 2004 17:20:27 +0100 Subject: Re: Problem with Log4j (Configuration) brAmir,brbrAre A.txt and B.txt the configuration files or the files where logging broutput goes?brbrAt 06:13 AM 12/17/2004, Ran//-\\mir wrote:brbrApologies are mine if this issue is discussed already.brI have two different applications i-e two separate jar files br(ApplicationA.jar and ApplicationB.jar).brBoth use log4j for logging to separate files (A.txt and B.txt).brNow the scenario isbrApplicationB uses ApplicationA jar file. I have placed ApplicationA.jar brand log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationB brruns, I expect to get logs in different files but unfortunately this does brnot happen. ApplicationA makes some logging in B.txt and ApplicationB in brA.txt. Though both are using different configuration files.brIs this normal? What is the solution to the problem?brThanking in advance.brAmirbrbr-- brCeki Gülcübrbr The complete log4j manual: http://qos.ch/log4j/brbrbrbr-brTo unsubscribe, e-mail: [EMAIL PROTECTED]brFor additional commands, e-mail: [EMAIL PROTECTED]brbr ___ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with Log4j (Configuration)
At 05:20 PM 12/18/2004 +0100, you wrote: Amir, Are A.txt and B.txt the configuration files or the files where logging output goes? I'm pretty sure he means that the .txt files are his log files and since he has two separate configurations, he expects appA's output to go to one file (as it was configured in his appA config file) and he expects appB's output to go to separate file (as it is configured in his appB config file). The problem is that there is only one config [file] per logger repository. When he says appA and appB, he means two jar files in the same application. The answer to this is that the approach is flawed. The way I interpret this is that ApplicationA.jar and ApplicationB.jar both have a log4j config file in their roots. This is a bad practice as someone else may use, for instance, ApplicationA.jar in their app but not want to have ApplicationA.jar defining their logger configuration. The problem is thinking that configuration is happening per/library. It actually happens per logger repository which, by default, is essentially per visible classloader hierarchy. If a repository selector is used, the configuration happens per whatever criteria the selector uses as a demarcation of logger repositories. This can add complexity which is necessary at times, but probably not here. Because of this, one should not distribute config files in jars. Logging is for the end user, not the creator of the library. Remove the config files from the libraries and use a single config file per/application. At this point, it is easy to send the output of the two libraries (with distinct package names) to separate log files... appender name=File1 class=org.apache.log4j.FileAppender param name=File value=file1.log / /appender appender name=File2 class=org.apache.log4j.FileAppender param name=File value=file2.log / /appender logger name=com.mycompany.librarya additivity=false level value=debug/ appender-ref ref=File1/ /logger logger name=com.mycompany.libraryb additivity=false level value=debug/ appender-ref ref=File2/ /logger root level value=warn/ appender-ref ref=Console/ /root I hope that answers the question. Jake At 06:13 AM 12/17/2004, Ran//-\\mir wrote: Apologies are mine if this issue is discussed already. I have two different applications i-e two separate jar files (ApplicationA.jar and ApplicationB.jar). Both use log4j for logging to separate files (A.txt and B.txt). Now the scenario is ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jar and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationB runs, I expect to get logs in different files but unfortunately this does not happen. ApplicationA makes some logging in B.txt and ApplicationB in A.txt. Though both are using different configuration files. Is this normal? What is the solution to the problem? Thanking in advance. Amir -- Ceki Gülcü The complete log4j manual: http://qos.ch/log4j/ - 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]
Problem with Log4j ( Configuration)
Apologies are mine if this issue is discussed already.
Problem with Log4j (Configuration)
Apologies are mine if this issue is discussed already. I have two different applications i-e two separate jar files (ApplicationA.jar and ApplicationB.jar). Both use log4j for logging to separate files (A.txt and B.txt). Now the scenario is ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jar and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationB runs, I expect to get logs in different files but unfortunately this does not happen. ApplicationA makes some logging in B.txt and ApplicationB in A.txt. Though both are using different configuration files. Is this normal? What is the solution to the problem? Thanking in advance. Amir ___ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Log4J configuration for library
Hi I'm developing a library and I'm using Log4J. I've had problems with applications that use the library and use log4j at the same time. For some reason the configuration gets messed up. I'm using a log4j.properties file inside de .jar library. Is there a correct way to configure log4j for libraries? Regards, Néstor Boscán - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Log4J configuration for library
Hi, First, please be more specific than just the configuration gets messed up. Our ability to help you is mostly limited by the quality and quantity of the information you provide. The common problem when developing libraries is the need to allow the user of the library to configure its logging. There is code on the log4j wiki that shows you how to check if log4j has already been configured. You can do this check, and then either throw a (possibly fatal) exception if log4j is not configured, or configure it yourself. This is a fairly safe approach. Yoav Shapira Millennium Research Informatics -Original Message- From: Nestor Boscan [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 2:26 PM To: [EMAIL PROTECTED] Subject: Log4J configuration for library Hi I'm developing a library and I'm using Log4J. I've had problems with applications that use the library and use log4j at the same time. For some reason the configuration gets messed up. I'm using a log4j.properties file inside de .jar library. Is there a correct way to configure log4j for libraries? Regards, Néstor Boscán - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
log4j configuration problem
Hi, I have a problem with the configuration of log4j. What I want to do is have some classes doing their logging in level INFO. I used the rootLogger to achieve this and it is working very well. There is another class (de.techem.novell.fileservice.Upload) which is still under development. Therefore it should log it's messages in level DEBUG. This is my log4j config: log4j.rootLogger=INFO,A1 log4j.logger.de.techem.novell.fileservice.Upload=DEBUG log4j.appender.A1=org.apache.log4j.FileAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d %-5p %m%n log4j.appender.A1.File=...filefilefilefile... It seems to me that there is a problem in the second line of the config file because every message is logged in level INFO. Then I changed the line to log4j.logger.de=DEBUG to be sure that the other classes in this package should log in level DEBUG but nothing happened. Every class is still logging in the level defined for the rootLogger. Then I thought it might have something to do with the classname and made log4j put the classname in my logfile changing the pattern to %d %C %-5p %m%n. After that chage, the classname appeared in the logfile and were exactly the same as specified in line 2 of the first version of the configfile (de.techem.novell.fileservice.Upload). Everything I tried did not succeed, so I am mailint to this list to find someone who could help me out. Any ideas what I am doing wrong? Thanks for your help. Flo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Running the same package in different JVM with the same log4j configuration
Return Receipt Your Running the same package in different JVM with the same document log4j configuration : was Michael Rutherfurd/CORPAU/WBCAU/WBG received by: at: 04/06/2004 16:43:05 WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. Westpac Banking Corporation ABN is 33 007 457 141. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
automatic LOG4J configuration reloading ?
Hi folks, Is there a way to do an automatic reloading of the log4j configuration declared as -Dlog4j.configuration ? = -- Regards, Ionel Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/ Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !Téléchargez Yahoo! Messenger sur http://fr.messenger.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Running the same package in different JVM with the same log4j configuration
Hi, I running one the same server multiple JVM machine which are running the same java package. The log4j configuration file location is in a property file in my logger framework package which is also running in each JVM of course. I using a FileAppender to as log trace. As a File can't be open twice, only one JVM can't write into the file. The problem also occurred for all Appender which extend the FileAppender. As work around I wrote a new FileAppender which use a System property to post fix the file name. So, I can launch different JVM with different System property and then avoid the concurency problem on a non-sharable ressource. I would be nice to have this feature in a future release or have a way or it already exists a way (which I ignore) to avoid this problem. Regards Dominique