Re: Separating some classes' messages from root
Seems to me that Log4j is just setting up the Root logger defined in the config file, which references the SERVERLOG appender and, therefore, configures said appender. It is only coincidence that this has anything to do with the org.serviio.console.ServiioConsole class performing logging. Apparently, this is the first logger to be called and since Log4j was not yet configured, it configures itself using the log4j.xml config file. Your problem is that the root logger is referencing an appender, which points to a file that the user running your application has no permission to create. This has nothing whatsoever to do with additivity. Your config is fine. Your user's file system permissions need tweaking (or you need to point to a different file system location in your config). Jake On Wed, 23 Feb 2011 19:09:14 -0500 Mikhail T. mi+t...@aldan.algebra.com wrote: On 23.02.2011 18:18, Jacob Kjome wrote: logger name=special.example.com additivity=false level value=INFO/ appender-ref ref=STDERR/ /logger I tried that before -- it did not work... Here is the current actual config (full file is attached): logger name=org.serviio.console additivity=false level value=INFO/ appender-ref ref=STDERR/ /logger ... root level value=DEBUG/ appender-ref ref=SERVERLOG/ /root But, for some reason, when the class org.serviio.console.ServiioConsole tries to make a log entry, log4j attempts to open the server's log-file. Here is the full output of the application's start-up (with debug=true): log4j: reset attribute= false. log4j: Threshold =null. log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [org.serviio] additivity to [true]. log4j: Level value for org.serviio is [INFO]. log4j: org.serviio level set to INFO log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [org.jaudiotagger] additivity to [true]. log4j: Level value for org.jaudiotagger is [ERROR]. log4j: org.jaudiotagger level set to ERROR log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [org.restlet] additivity to [true]. log4j: Level value for org.restlet is [ERROR]. log4j: org.restlet level set to ERROR log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [org.serviio.console] additivity to [false]. log4j: Level value for org.serviio.console is [INFO]. log4j: org.serviio.console level set to INFO log4j: Class name: [org.apache.log4j.ConsoleAppender] log4j: Setting property [threshold] to [DEBUG]. log4j: Setting property [target] to [System.err]. log4j: Parsing layout of class: org.apache.log4j.PatternLayout log4j: Setting property [conversionPattern] to [%d{ISO8601} %-5p [%c{1}] %m%n]. log4j: Adding appender named [STDERR] to category [org.serviio.console]. log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [org.serviio.ui.view] additivity to [false]. log4j: Level value for org.serviio.ui.view is [INFO]. log4j: org.serviio.ui.view level set to INFO log4j: Adding appender named [STDERR] to category [org.serviio.ui.view]. log4j: Level value for root is [DEBUG]. log4j: root level set to DEBUG log4j: Class name: [org.apache.log4j.RollingFileAppender] log4j: Setting property [threshold] to [DEBUG]. log4j: Setting property [append] to [true]. log4j: Setting property [file] to [/var/log/serviio/serviio.log]. log4j: Setting property [maxFileSize] to [500KB]. log4j: Setting property [maxBackupIndex] to [5]. log4j: Setting property [encoding] to [UTF-8]. log4j: Parsing layout of class: org.apache.log4j.PatternLayout log4j: Setting property [conversionPattern] to [%d{ISO8601} %-5p [%c{1}] %m%n]. log4j: setFile called: /var/log/serviio/serviio.log, true log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: /var/log/serviio/serviio.log (Permission denied) at java.io.FileOutputStream.openAppend(Native Method) at java.io.FileOutputStream.init(FileOutputStream.java:177) at java.io.FileOutputStream.init(FileOutputStream.java:102) at org.apache.log4j.FileAppender.setFile(FileAppender.java:294) at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207) at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165) at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307) at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:295) at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:176) at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:191) at
xml config
I guess I just do not understand log4j very well. I have spent the past two days searching and reading the mailing list but just cannot come up with an answer. I am using Netbeans for development and I cannot understand where to put my log4j.xml file, nor can I seem to figure out the concept. I have created the simplest project, I have tried the Properties loader but from what I have read it seems that log4j looks for the log4j.xml file: public class Main { static Logger logger = Logger.getLogger(Main.class); static Properties properties = new Properties(); static FileInputStream fis; /** * @param args the command line arguments */ public static void main(String[] args) { logger.info(info); logger.debug(debug); logger.warn(warn); } } I added log4j.xml into the src folder: ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd !-- Document : logging.xml Created on : February 23, 2011, 12:34 PM Author : bobby Description: Purpose of the document follows. -- log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=console class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ABSOLUTE} %5p %c{1}:%L - %m%n/ /layout /appender appender name=file class=org.apache.log4j.FileAppender param name=File value=/home/bobby/test.log/ param name=Append value=false/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%t %-5p %c{2} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=console/ /root /log4j:configuration I can only seem to get this to act properly when I clean and build. Which makes no sense to me, the whole point of a config file is to change before run, but I am only getting the desired result if the code is essentially burned in. Further more, when I try to distribute my jar I place the xml file in my dist folder but it just does not work. At this point I am just beyond frustration, any help would be appreciated. I realize that this is the most basic of problems and I apologize. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: xml config
I place the xml file in my dist folder but it just does not work. Is your dist folder in the running application's classpath? If not, then you can't expect it to possibly get picked up. 1. Log4j looks for config files in the default package. For instance, in a webapp, this might be WEB-INF/classes. Or, it could be the root directory of a jar file. As long as it isn't in a named package like com.mycompany, then you are golden. If you place the directory /path/to/my/app in the classpath, then you would place your config file in the directory /path/to/my/app. 2. Log4j look for 2 different types of config files: XML files and Properties files. Because there are 2 possibilities, it has to prefer one over the other. That is, it looks for one type and, if it doesn't find it, then looks for the other. Log4j prefers XML files over Properties files. That is, if log4j.xml is found, it doesn't bother looking for log4j.properties. However, if log4j.xml is not found, then it looks for log4j.properties. If you have both in the classpath, only log4j.xml will be used. In order to use log4j.properties, ensure that log4j.xml is NOT in the classpath. 3. Just to emphasize the points in #1, your config file HAS to be in a directory or jar file that is in the running application's classpath. If it is not, then it won't be found by Log4j. And if it is not in the default package, it also won't be found. Jake On Thu, 24 Feb 2011 11:38:38 -0500 Bobby Richards bobby.richa...@gmail.com wrote: I guess I just do not understand log4j very well. I have spent the past two days searching and reading the mailing list but just cannot come up with an answer. I am using Netbeans for development and I cannot understand where to put my log4j.xml file, nor can I seem to figure out the concept. I have created the simplest project, I have tried the Properties loader but from what I have read it seems that log4j looks for the log4j.xml file: public class Main { static Logger logger = Logger.getLogger(Main.class); static Properties properties = new Properties(); static FileInputStream fis; /** * @param args the command line arguments */ public static void main(String[] args) { logger.info(info); logger.debug(debug); logger.warn(warn); } } I added log4j.xml into the src folder: ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd !-- Document : logging.xml Created on : February 23, 2011, 12:34 PM Author : bobby Description: Purpose of the document follows. -- log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=console class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ABSOLUTE} %5p %c{1}:%L - %m%n/ /layout /appender appender name=file class=org.apache.log4j.FileAppender param name=File value=/home/bobby/test.log/ param name=Append value=false/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%t %-5p %c{2} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=console/ /root /log4j:configuration I can only seem to get this to act properly when I clean and build. Which makes no sense to me, the whole point of a config file is to change before run, but I am only getting the desired result if the code is essentially burned in. Further more, when I try to distribute my jar I place the xml file in my dist folder but it just does not work. At this point I am just beyond frustration, any help would be appreciated. I realize that this is the most basic of problems and I apologize. - 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: Separating some classes' messages from root
On 24.02.2011 10:49, Jacob Kjome wrote: Seems to me that Log4j is just setting up the Root logger defined in the config file, which references the SERVERLOG appender and, therefore, configures said appender. It is only coincidence that this has anything to do with the org.serviio.console.ServiioConsole class performing logging. Apparently, this is the first logger to be called and since Log4j was not yet configured, it configures itself using the log4j.xml config file. Your problem is that the root logger is referencing an appender, which points to a file that the user running your application has no permission to create. This has nothing whatsoever to do with additivity. Your config is fine. Your user's file system permissions need tweaking (or you need to point to a different file system location in your config). Thank you very much, Jacob, for the analysis. Here is some more information... The application I'm dealing with -- serviio http://www.serviio.org/ -- consists of two parts: the server daemon and the GUI console. As distributed by the author, they share some settings, including the log4j.xml file. The daemon-part starts automatically at boot and runs under its own user-ID. I want the daemon's log-messages in the log-file. The console-piece can be started by any local user of the system -- and no such user should be able to write to the server's log -- hence the restrictive permissions... I want the console's log-messages to go to stderr only, as is normal for interactive programs. There are only two log4j-using classes used by the console, so it was practical to enumerate them explicitly sending all their entries to stderr. The catch-all Root-logger would not be used by the console at all -- or so I thought... I'd consider it a bug, that the files referenced by the file-appenders are opened /in advance/ instead of, /lazily/ -- when needed -- which in this case would be never. If there is no setting to tell log4j to postpone opening the files until there is an actual message ready to be written there, I guess, my only option is to have two distinct configuration files -- one for each piece of the application... Is there a way to specify an alternative file (rather than the default log4j.xml) on command-line with an environment variable or -D/something/? Or must I create a separate directory for the different log4j.xml? Thanks! Yours, -mi
Re: Separating some classes' messages from root
-Dlog4j.defaultInitOverride=true -Dlog4j.configuration=file:/url/path/to/log4j.xml See more at... http://logging.apache.org/log4j/1.2/manual.html#defaultInit Jake On Thu, 24 Feb 2011 12:14:18 -0500 Mikhail T. mi+t...@aldan.algebra.com wrote: On 24.02.2011 10:49, Jacob Kjome wrote: Seems to me that Log4j is just setting up the Root logger defined in the config file, which references the SERVERLOG appender and, therefore, configures said appender. It is only coincidence that this has anything to do with the org.serviio.console.ServiioConsole class performing logging. Apparently, this is the first logger to be called and since Log4j was not yet configured, it configures itself using the log4j.xml config file. Your problem is that the root logger is referencing an appender, which points to a file that the user running your application has no permission to create. This has nothing whatsoever to do with additivity. Your config is fine. Your user's file system permissions need tweaking (or you need to point to a different file system location in your config). Thank you very much, Jacob, for the analysis. Here is some more information... The application I'm dealing with -- serviio http://www.serviio.org/ -- consists of two parts: the server daemon and the GUI console. As distributed by the author, they share some settings, including the log4j.xml file. The daemon-part starts automatically at boot and runs under its own user-ID. I want the daemon's log-messages in the log-file. The console-piece can be started by any local user of the system -- and no such user should be able to write to the server's log -- hence the restrictive permissions... I want the console's log-messages to go to stderr only, as is normal for interactive programs. There are only two log4j-using classes used by the console, so it was practical to enumerate them explicitly sending all their entries to stderr. The catch-all Root-logger would not be used by the console at all -- or so I thought... I'd consider it a bug, that the files referenced by the file-appenders are opened /in advance/ instead of, /lazily/ -- when needed -- which in this case would be never. If there is no setting to tell log4j to postpone opening the files until there is an actual message ready to be written there, I guess, my only option is to have two distinct configuration files -- one for each piece of the application... Is there a way to specify an alternative file (rather than the default log4j.xml) on command-line with an environment variable or -D/something/? Or must I create a separate directory for the different log4j.xml? Thanks! Yours, -mi - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Separating some classes' messages from root
On 24.02.2011 12:26, Jacob Kjome wrote: -Dlog4j.defaultInitOverride=true -Dlog4j.configuration=file:/url/path/to/log4j.xml Thanks! Do I need the first of these switches for the second one to have effect? See more at... http://logging.apache.org/log4j/1.2/manual.html#defaultInit The manual says: 1. Setting the log4j.defaultInitOverride system property to any other value then false will cause log4j to skip the default initialization procedure (this procedure). Which leaves things a bit unclear... Yours, -mi
Re: xml config
and Jacob's other posting is also helpful: I quote: -Dlog4j.defaultInitOverride=true -Dlog4j.configuration=file:/url/path/to/log4j.xml See more at... http://logging.apache.org/log4j/1.2/manual.html#defaultInit ■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER (269) 923-5278 // douglas_e_wegsch...@whirlpool.com A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation. Jacob Kjome h...@visi.com 02/24/2011 12:06 PM Please respond to Log4J Users List log4j-user@logging.apache.org To Log4J Users List log4j-user@logging.apache.org cc Subject Re: xml config I place the xml file in my dist folder but it just does not work. Is your dist folder in the running application's classpath? If not, then you can't expect it to possibly get picked up. 1. Log4j looks for config files in the default package. For instance, in a webapp, this might be WEB-INF/classes. Or, it could be the root directory of a jar file. As long as it isn't in a named package like com.mycompany, then you are golden. If you place the directory /path/to/my/app in the classpath, then you would place your config file in the directory /path/to/my/app. 2. Log4j look for 2 different types of config files: XML files and Properties files. Because there are 2 possibilities, it has to prefer one over the other. That is, it looks for one type and, if it doesn't find it, then looks for the other. Log4j prefers XML files over Properties files. That is, if log4j.xml is found, it doesn't bother looking for log4j.properties. However, if log4j.xml is not found, then it looks for log4j.properties. If you have both in the classpath, only log4j.xml will be used. In order to use log4j.properties, ensure that log4j.xml is NOT in the classpath. 3. Just to emphasize the points in #1, your config file HAS to be in a directory or jar file that is in the running application's classpath. If it is not, then it won't be found by Log4j. And if it is not in the default package, it also won't be found. Jake On Thu, 24 Feb 2011 11:38:38 -0500 Bobby Richards bobby.richa...@gmail.com wrote: I guess I just do not understand log4j very well. I have spent the past two days searching and reading the mailing list but just cannot come up with an answer. I am using Netbeans for development and I cannot understand where to put my log4j.xml file, nor can I seem to figure out the concept. I have created the simplest project, I have tried the Properties loader but from what I have read it seems that log4j looks for the log4j.xml file: public class Main { static Logger logger = Logger.getLogger(Main.class); static Properties properties = new Properties(); static FileInputStream fis; /** * @param args the command line arguments */ public static void main(String[] args) { logger.info(info); logger.debug(debug); logger.warn(warn); } } I added log4j.xml into the src folder: ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd !-- Document : logging.xml Created on : February 23, 2011, 12:34 PM Author : bobby Description: Purpose of the document follows. -- log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=console class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ABSOLUTE} %5p %c{1}:%L - %m%n/ /layout /appender appender name=file class=org.apache.log4j.FileAppender param name=File value=/home/bobby/test.log/ param name=Append value=false/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%t %-5p %c{2} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=console/ /root /log4j:configuration I can only seem to get this to act properly when I clean and build. Which makes no sense to me, the whole point of a config file is to change before run, but I am only getting the desired result if the code is essentially burned in. Further more, when I try to distribute my jar I place the xml file in my dist folder but it just does not work. At this point I am just beyond frustration, any help would be appreciated. I realize that this is the most basic of problems and I apologize. - 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: xml config
And if you add: -Dlog4j.debug=true to your vm params, you might have an output which helps you to identify your problem too Cheers Christian 2011/2/24 Douglas E Wegscheid douglas_e_wegsch...@whirlpool.com: and Jacob's other posting is also helpful: I quote: -Dlog4j.defaultInitOverride=true -Dlog4j.configuration=file:/url/path/to/log4j.xml See more at... http://logging.apache.org/log4j/1.2/manual.html#defaultInit ■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER (269) 923-5278 // douglas_e_wegsch...@whirlpool.com A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation. Jacob Kjome h...@visi.com 02/24/2011 12:06 PM Please respond to Log4J Users List log4j-user@logging.apache.org To Log4J Users List log4j-user@logging.apache.org cc Subject Re: xml config I place the xml file in my dist folder but it just does not work. Is your dist folder in the running application's classpath? If not, then you can't expect it to possibly get picked up. 1. Log4j looks for config files in the default package. For instance, in a webapp, this might be WEB-INF/classes. Or, it could be the root directory of a jar file. As long as it isn't in a named package like com.mycompany, then you are golden. If you place the directory /path/to/my/app in the classpath, then you would place your config file in the directory /path/to/my/app. 2. Log4j look for 2 different types of config files: XML files and Properties files. Because there are 2 possibilities, it has to prefer one over the other. That is, it looks for one type and, if it doesn't find it, then looks for the other. Log4j prefers XML files over Properties files. That is, if log4j.xml is found, it doesn't bother looking for log4j.properties. However, if log4j.xml is not found, then it looks for log4j.properties. If you have both in the classpath, only log4j.xml will be used. In order to use log4j.properties, ensure that log4j.xml is NOT in the classpath. 3. Just to emphasize the points in #1, your config file HAS to be in a directory or jar file that is in the running application's classpath. If it is not, then it won't be found by Log4j. And if it is not in the default package, it also won't be found. Jake On Thu, 24 Feb 2011 11:38:38 -0500 Bobby Richards bobby.richa...@gmail.com wrote: I guess I just do not understand log4j very well. I have spent the past two days searching and reading the mailing list but just cannot come up with an answer. I am using Netbeans for development and I cannot understand where to put my log4j.xml file, nor can I seem to figure out the concept. I have created the simplest project, I have tried the Properties loader but from what I have read it seems that log4j looks for the log4j.xml file: public class Main { static Logger logger = Logger.getLogger(Main.class); static Properties properties = new Properties(); static FileInputStream fis; /** * @param args the command line arguments */ public static void main(String[] args) { logger.info(info); logger.debug(debug); logger.warn(warn); } } I added log4j.xml into the src folder: ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd !-- Document : logging.xml Created on : February 23, 2011, 12:34 PM Author : bobby Description: Purpose of the document follows. -- log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=console class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ABSOLUTE} %5p %c{1}:%L - %m%n/ /layout /appender appender name=file class=org.apache.log4j.FileAppender param name=File value=/home/bobby/test.log/ param name=Append value=false/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%t %-5p %c{2} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=console/ /root /log4j:configuration I can only seem to get this to act properly when I clean and build. Which makes no sense to me, the whole point of a config file is to change before run, but I am only getting the desired result if the code is essentially burned in. Further more, when I try to distribute my jar I place the xml file in my dist folder but it just does not work. At this point I am just beyond frustration, any help would be appreciated. I realize that this is the most basic of problems and I apologize. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Separating some classes' messages from root
ah. a good point. you probably just want the 2nd one: -Dlog4j.configuration=file:/url/path/to/log4j.xml you can just try it also (along with the -Dlog4j.debug=true suggested previously) ■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER (269) 923-5278 // douglas_e_wegsch...@whirlpool.com A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation. Mikhail T. mi+t...@aldan.algebra.com 02/24/2011 12:33 PM Please respond to Log4J Users List log4j-user@logging.apache.org To Jacob Kjome h...@visi.com cc log4j-user@logging.apache.org Subject Re: Separating some classes' messages from root On 24.02.2011 12:26, Jacob Kjome wrote: -Dlog4j.defaultInitOverride=true -Dlog4j.configuration=file:/url/path/to/log4j.xml Thanks! Do I need the first of these switches for the second one to have effect? See more at... http://logging.apache.org/log4j/1.2/manual.html#defaultInit The manual says: 1. Setting the log4j.defaultInitOverride system property to any other value then false will cause log4j to skip the default initialization procedure (this procedure). Which leaves things a bit unclear... Yours, -mi