Re: Set log level while running integration test
Just create 2 log4j.properties files: one for unit tests and one for performance tests. Place these files in different directories and add the appropriate directory to the classpath for each type of test run, respectively. Jake On Thu, 30 Jul 2015 00:45:46 + Liang, Hsuan Tzu liahs...@a9.com wrote: Hello everyone, I am currently encountering a problem that I need to set the log level of a certain class while running performance test to prevent too many outputs. But while running unit tests, the logs need to be printed out. This can easily be achieved by setting the log level in the performance test code dynamically, but I am wondering if there is any way to configure it using the log4j.properties file. Is it possible to specify the level of a certain logger for different class that are using it? Eg: log4j.logger.a=debug, while running performance test log4j.logger.a=info, while running unit test Thanks, Zack - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: how to override log4j.properties bundled in jar
Actually, that should work if memory serves me correctly. Are you saying the one in the jar file still gets picked up? One thing you might need to do is to define the path as a fully qualified URL, such as -Dlog4j.configuration=file:/tmp/log4j.properties ...or, for windows -Dlog4j.configuration=file:C:/tmp/log4j.properties If that doesn't work, for whatever reason, you can stick a log4j.properties file into WEB-INF/classes, which will get picked up before the one in the jar, therefore the one in the jar will be ignored. Jake On Wed, 07 Jan 2015 16:50:06 -0800 Jason Novotny jason.novo...@gmail.com wrote: Hi, I have a WAR file that contains a jar file that has a log4j.properties file baked into it. I want to override that with my own production log4j.properties file. I thought it would be sufficient to just add -Dlog4j.configuration=/tmp/log4j.properties to my java command line parameters but I see that doesn't work. Any ideas on how to do this? Thanks, Jason - 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.properties gets loaded twice causing rollling to fail
No. More likely, there some code in your app performing manual configuration. Jake On Sun, 13 Jul 2014 16:31:35 +0800 Gerald gerald...@yahoo.com.sg wrote: Hi so in my case, because log4j.properties was not found in my webapps WEB-INF/classes, the webapp classloader then went to look for the log4j.properties in my tomcat. this second reloading causes the rolling to fail. I see that subsequently the log4j.properties of my webapp (in WEB-INF/classes/properties) was loaded towards the end, so can I infer the following? The webapp classloader first tries to load all config files in WEB-INF/classes,and because log4j properties was not found , then goes back to (re)load log4j.properties in the tomcat's lib and then comes back to WEB-INF/classes/* to load the remaining configs? and since the log4j.properties was found in WEB-INF/classes/properties it was eventually loaded. Regards. On Sun 13 Jul, 2014, at 12:24 pm, Jacob Kjome h...@visi.com wrote: Because Log4j, by default, looks for config files in the default package. Furthermore, because of Tomcat's child-first classloading behavior, if you place log4j.properties in the default package of the webapp (WEB-INF/classes) it won't bother looking in the parent classloader since it will have already found the config file in the webapp classloader. Note, however, that log4j.xml takes precedence over log4j.properties. So, if you have log4j.xml in Tomcat's classpath (in the default package), then even if you have log4j.properties in the webapp classpath, it will use log4j.xml from the server classpath. If that case, you'd need log4j.xml in the webapp's default package to override the server's log4j.xml. Just thought I'd point that out. Jake On Sun, 13 Jul 2014 00:04:26 +0800 Gerald gerald...@yahoo.com.sg wrote: Hi Could I trouble you to explain further why putting the application log4j.properties in WEB-INF/classes, as opposed to WEB-INF/classes/properties, would prevent the webapp classloader from seeing the tomcat's log4j.properties? Gerald On 11 Jul, 2014, at 11:27 pm, Jacob Kjome h...@visi.com wrote: Why don't you place your webapp's log4j.properties file in WEB-INF/classes instead of WEB-INF/classes/properties? That way, the webapp classloader won't ever see the tomcat log4j.properties, thus no rolling file appender conflicts. Jake On Fri, 11 Jul 2014 11:16:41 +0800 guowei gerald...@yahoo.com.sg wrote: Dear all, I am using log4j for tomcat internal logging and also application logging. I followed Tomcat's instruction to configure log4j rolling and I also have configured my application to have its own log4j rolling. log4j.jar is in both Tomcat's lib and web application's lib, each have their respective log4j.properties I enabled -Dlog4j.debug and I can see the sequence of the events 1) log4j.properties for the tomcat gets loaded by Tomcat's StandardClassLoader 2) the same log4j.properties for tomcat gets loaded by the Tomcat's WebappClassLoader 3) application's log4j.properties is loaded Between 1) and 2) I can see the tomcat files being rolled ( I intentionally set DailyRollingAppender to -MM-dd-HH-mm and DEBUG level to make sure lots of things gets logged). Rolling was working well. Files were rolled on the minute However, when step 2) kicks in, the rolling of tomcat files failed. I reckon that the moment the the same log4j.properties is loaded, there is a conflict since the same appenders are referred twice. I am not certain has it anything to do with the tomcat's log4j configuration or appliation's log4j configuration. The Application's log files are rolled correctly. Would appreciate if anyone can enlighten me. -Dlog4j.debug output log4j: Trying to find [log4j.xml] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Trying to find [log4j.xml] using org.apache.catalina.loader.StandardClassLoader@1529d183 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Using URL [file:/C:\Apache\Tomcat/lib/log4j.properties] for automatic log4j configuration. log4j: Reading configuration from URL file:/C:\Apache\Tomcat/lib/log4j.properties log4j: Parsing for [root] with value=[WARN,CATALINA,LOCALHOST,MANAGER,HOST-MANAGER,stdout,stderr]. log4j: Level token is [WARN]. log4j: Category root set to WARN log4j: Parsing appender named CATALINA. log4j: Parsing layout options for CATALINA. log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c- %m%n]. log4j: End of parsing for CATALINA. log4j: Setting property [encoding] to [UTF-8]. log4j: Setting property [datePattern] to ['.'-MM-dd-HH-mm'.log']. log4j: Setting property [file] to [C:\Apache\Tomcat/logs/catalina]. log4j: Setting property [append] to [true]. log4j: setFile called: C:\Apache\Tomcat/logs/catalina, true log4j
Re: log4j.properties gets loaded twice causing rollling to fail
Because Log4j, by default, looks for config files in the default package. Furthermore, because of Tomcat's child-first classloading behavior, if you place log4j.properties in the default package of the webapp (WEB-INF/classes) it won't bother looking in the parent classloader since it will have already found the config file in the webapp classloader. Note, however, that log4j.xml takes precedence over log4j.properties. So, if you have log4j.xml in Tomcat's classpath (in the default package), then even if you have log4j.properties in the webapp classpath, it will use log4j.xml from the server classpath. If that case, you'd need log4j.xml in the webapp's default package to override the server's log4j.xml. Just thought I'd point that out. Jake On Sun, 13 Jul 2014 00:04:26 +0800 Gerald gerald...@yahoo.com.sg wrote: Hi Could I trouble you to explain further why putting the application log4j.properties in WEB-INF/classes, as opposed to WEB-INF/classes/properties, would prevent the webapp classloader from seeing the tomcat's log4j.properties? Gerald On 11 Jul, 2014, at 11:27 pm, Jacob Kjome h...@visi.com wrote: Why don't you place your webapp's log4j.properties file in WEB-INF/classes instead of WEB-INF/classes/properties? That way, the webapp classloader won't ever see the tomcat log4j.properties, thus no rolling file appender conflicts. Jake On Fri, 11 Jul 2014 11:16:41 +0800 guowei gerald...@yahoo.com.sg wrote: Dear all, I am using log4j for tomcat internal logging and also application logging. I followed Tomcat's instruction to configure log4j rolling and I also have configured my application to have its own log4j rolling. log4j.jar is in both Tomcat's lib and web application's lib, each have their respective log4j.properties I enabled -Dlog4j.debug and I can see the sequence of the events 1) log4j.properties for the tomcat gets loaded by Tomcat's StandardClassLoader 2) the same log4j.properties for tomcat gets loaded by the Tomcat's WebappClassLoader 3) application's log4j.properties is loaded Between 1) and 2) I can see the tomcat files being rolled ( I intentionally set DailyRollingAppender to -MM-dd-HH-mm and DEBUG level to make sure lots of things gets logged). Rolling was working well. Files were rolled on the minute However, when step 2) kicks in, the rolling of tomcat files failed. I reckon that the moment the the same log4j.properties is loaded, there is a conflict since the same appenders are referred twice. I am not certain has it anything to do with the tomcat's log4j configuration or appliation's log4j configuration. The Application's log files are rolled correctly. Would appreciate if anyone can enlighten me. -Dlog4j.debug output log4j: Trying to find [log4j.xml] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Trying to find [log4j.xml] using org.apache.catalina.loader.StandardClassLoader@1529d183 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Using URL [file:/C:\Apache\Tomcat/lib/log4j.properties] for automatic log4j configuration. log4j: Reading configuration from URL file:/C:\Apache\Tomcat/lib/log4j.properties log4j: Parsing for [root] with value=[WARN,CATALINA,LOCALHOST,MANAGER,HOST-MANAGER,stdout,stderr]. log4j: Level token is [WARN]. log4j: Category root set to WARN log4j: Parsing appender named CATALINA. log4j: Parsing layout options for CATALINA. log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c- %m%n]. log4j: End of parsing for CATALINA. log4j: Setting property [encoding] to [UTF-8]. log4j: Setting property [datePattern] to ['.'-MM-dd-HH-mm'.log']. log4j: Setting property [file] to [C:\Apache\Tomcat/logs/catalina]. log4j: Setting property [append] to [true]. log4j: setFile called: C:\Apache\Tomcat/logs/catalina, true log4j: setFile ended log4j: Appender [CATALINA] to be rolled on top of every minute. log4j: Parsed CATALINA options. log4j: Handling log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=[null] log4j: Finished configuring. . . #Parsing for rest of the file . . log4j: Parsing for [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[host-manager]] with value=[WARN, HOST-MANAGER]. log4j: Level token is [WARN]. log4j: Category org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[host-manager] set to WARN log4j: Parsing appender named HOST-MANAGER. delegate: false repositories: /WEB-INF/classes/ -- Parent Classloader: org.apache.catalina.loader.StandardClassLoader@6c79fa4f . log4j: Trying to find [log4j.xml] using WebappClassLoader context: /mya delegate: false repositories: /WEB-INF/classes/ -- Parent Classloader: org.apache.catalina.loader.StandardClassLoader@6c79fa4f class loader
Re: log4j.properties gets loaded twice causing rollling to fail
Why don't you place your webapp's log4j.properties file in WEB-INF/classes instead of WEB-INF/classes/properties? That way, the webapp classloader won't ever see the tomcat log4j.properties, thus no rolling file appender conflicts. Jake On Fri, 11 Jul 2014 11:16:41 +0800 guowei gerald...@yahoo.com.sg wrote: Dear all, I am using log4j for tomcat internal logging and also application logging. I followed Tomcat's instruction to configure log4j rolling and I also have configured my application to have its own log4j rolling. log4j.jar is in both Tomcat's lib and web application's lib, each have their respective log4j.properties I enabled -Dlog4j.debug and I can see the sequence of the events 1) log4j.properties for the tomcat gets loaded by Tomcat's StandardClassLoader 2) the same log4j.properties for tomcat gets loaded by the Tomcat's WebappClassLoader 3) application's log4j.properties is loaded Between 1) and 2) I can see the tomcat files being rolled ( I intentionally set DailyRollingAppender to -MM-dd-HH-mm and DEBUG level to make sure lots of things gets logged). Rolling was working well. Files were rolled on the minute However, when step 2) kicks in, the rolling of tomcat files failed. I reckon that the moment the the same log4j.properties is loaded, there is a conflict since the same appenders are referred twice. I am not certain has it anything to do with the tomcat's log4j configuration or appliation's log4j configuration. The Application's log files are rolled correctly. Would appreciate if anyone can enlighten me. -Dlog4j.debug output log4j: Trying to find [log4j.xml] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Trying to find [log4j.xml] using org.apache.catalina.loader.StandardClassLoader@1529d183 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader org.apache.catalina.loader.StandardClassLoader@1529d183. log4j: Using URL [file:/C:\Apache\Tomcat/lib/log4j.properties] for automatic log4j configuration. log4j: Reading configuration from URL file:/C:\Apache\Tomcat/lib/log4j.properties log4j: Parsing for [root] with value=[WARN,CATALINA,LOCALHOST,MANAGER,HOST-MANAGER,stdout,stderr]. log4j: Level token is [WARN]. log4j: Category root set to WARN log4j: Parsing appender named CATALINA. log4j: Parsing layout options for CATALINA. log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c- %m%n]. log4j: End of parsing for CATALINA. log4j: Setting property [encoding] to [UTF-8]. log4j: Setting property [datePattern] to ['.'-MM-dd-HH-mm'.log']. log4j: Setting property [file] to [C:\Apache\Tomcat/logs/catalina]. log4j: Setting property [append] to [true]. log4j: setFile called: C:\Apache\Tomcat/logs/catalina, true log4j: setFile ended log4j: Appender [CATALINA] to be rolled on top of every minute. log4j: Parsed CATALINA options. log4j: Handling log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=[null] log4j: Finished configuring. . . #Parsing for rest of the file . . log4j: Parsing for [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[host-manager]] with value=[WARN, HOST-MANAGER]. log4j: Level token is [WARN]. log4j: Category org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[host-manager] set to WARN log4j: Parsing appender named HOST-MANAGER. delegate: false repositories: /WEB-INF/classes/ -- Parent Classloader: org.apache.catalina.loader.StandardClassLoader@6c79fa4f . log4j: Trying to find [log4j.xml] using WebappClassLoader context: /mya delegate: false repositories: /WEB-INF/classes/ -- Parent Classloader: org.apache.catalina.loader.StandardClassLoader@6c79fa4f class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader WebappClassLoader context: /mya delegate: false repositories: /WEB-INF/classes/ -- Parent Classloader: org.apache.catalina.loader.StandardClassLoader@6c79fa4f . log4j: Using URL [file://C:\Apache\Tomcat/lib/log4j.properties] for automatic log4j configuration. log4j: Using URL [file:/C:\Apache\Tomcat/lib/log4j.properties] for automatic log4j configuration. log4j: log4j: Parsing for [root] with value=[WARN,CATALINA,LOCALHOST,MANAGER,HOST-MANAGER,stdout,stderr]. log4j: Level token is [WARN]. Reading configuration from URL file:/C:\Apache\Tomcat/lib/log4j.properties log4j: Category root set to WARN log4j: Parsing appender named CATALINA. log4j: Parsing layout options for CATALINA. log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c- %m%n]. log4j: End of parsing for CATALINA. log4j: Setting property [encoding] to [UTF-8]. log4j: Setting property [datePattern] to ['.'-MM-dd-HH-mm'.log']. log4j: Setting property [file] to [C:\Apache\Tomcat/logs/catalina].
Re: All log4j appenders defined in log4j.properties in play
First, your understanding is incorrect. You can attach appenders to any logger, not just the root. Second, there must be some other stray log4j config file being loaded, instead of this one, that logs to a file appender pointing at the same file as the one in this log4j.properties. I suggest you start up the server with the following system property set to be able to see how log4j is loading configuration... -Dlog4j.debug=true Jake On Fri, 11 Jul 2014 11:31:22 +0530 Vishal Pore pore.vis...@gmail.com wrote: My log4j.properties file is pasted below. My understanding is that we need to add Appenders to the *root *logger for the appender to work. As you can see in the below properties file, only appender A is attached to the root logger (log4j.rootLogger=info, A). However, what I see is that the logging information is printed to both the appenders (ConsoleAppender - A and File Appender - B). How is this possible? log4j.rootLogger=info, A log4j.appender.A=org.apache.log4j.ConsoleAppender log4j.appender.A.layout=org.apache.log4j.PatternLayout log4j.appender.A.layout.ConversionPattern=%-4r [%t] [rid=%X{RID} ] %-5p %c %x - %m%n log4j.appender.B=org.apache.log4j.FileAppender log4j.appender.B.layout=org.apache.log4j.PatternLayout log4j.appender.B.file=target/server.log log4j.appender.B.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n I have posted the same question on stackoverflow-link http://stackoverflow.com/questions/24679226/all-log4j-appenders-defined-in-log4j-properties-in-play and failed to get any responses. Any resposes appreciated. Regards, Vishal Pore - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: beta9 to rc1
Regarding the serialization exception, are you saving an object to the session that contains a reference to a non-static/non-transient Logger object? If so, that's why. Jake On Sun, 23 Mar 2014 08:45:40 +0530 Mahesh Dilhan mail.mahesh...@gmail.com wrote: HI I managed to *fix *the *look-up issue*, just configuring log4j2.xml. it works as expected. And more surprisingly , now it does not create an additional *${web *empty file like that was in *beta9* On a Side note, I did a Jmeter *perfTest 100 clients . *when I traced the threads with *Jconsole*, AsynLogger-1 show Block- [X] Wait - [X XX XXX] [X] : this number gets varied. Why there are many waiting threads ? are there configuration that I have to set ? Also still i'm getting that Tomcat [7.0.47] init exception. *catalina.out * Mar 21, 2014 6:54:29 PM org.apache.catalina.session.StandardManager doLoad SEVERE: IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.logging.log4j.core.Logger$PrivateConfig java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.logging.log4j.core.Logger$PrivateConfig at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at java.util.ArrayList.readObject(ArrayList.java:593) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at java.util.HashMap.readObject(HashMap.java:1030) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1597) at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1062) at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:284) at org.apache.catalina.session.StandardManager.load(StandardManager.java:204) at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:491) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:983) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1660) at
Re: Multiple appenders and verbose logging for specific classes for an appender
Apply appenderA and AppenderB to the root logger. I always set the root logger level to WARN to avoid trace/debug/info messages from arbitrary libraries. Then, if you want INFO logging for most of your library, configure the lowest common denominator package for your app, let's say com.myapp, for the INFO level. Now configure the ClassX and ClassY loggers for the DEBUG level. Now your requirements get complicated. You need to configure filters for both appenders so that: 1. AppenderB explicitly ignores anything but WARN+, except when logging for ClassY, in which case it should accept DEBUG+. 2. AppenderA accepts whatever is sent to it except when logging for ClassY, in which case it should only accept INFO+ You can roll your own filter by implementing the Filter interface [1] or you could try the extras [2] ExpressionFilter [3]. I'm not an expert on supported expressions, but you can search for examples, such as [4]. This is an awfully complicated setup. I hope this is just about theory and not the way you actually intend to use Log4j. Nevertheless, Log4j should be able to handle it. [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html [2] http://logging.apache.org/log4j/companions/extras/index.html [3] http://svn.apache.org/repos/asf/logging/site/trunk/docs/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html [4] http://apache-logging.6191.n7.nabble.com/Multiple-expressions-define-in-one-ExpressionFilter-td7229.html Jake On Wed, 2 Oct 2013 11:16:42 +0200 fedinho fedi...@gmail.com wrote: Hi. No, I do not want to exclude the more severe logging levels, but I want to enable more verbose logging for specific classes for appender A independently of appender Bs logging of those same classes, and vice versa: Appender A and B is defined. Appender A is logging INFO+ for all by default, while appender B is logging WARN+ for all. Class X is logging DEBUG+more severe levels through appender A, but still logging WARN+more severe levels through appender B. Class Y is logging DEBUG+more severe levels through appender B, but still logging INFO+more severe levels through appender A. + means including more severe logging levels Thanks Fredrik On Wed, Oct 2, 2013 at 9:35 AM, Remko Popma remko.po...@gmail.com wrote: By default, if you set the level of a logger/appender to debug, it will process debug, info, warn, error and fatal messages. Is this what you want, or do you want to include only debug-level messages, and exclude info, warn, error and fatal messages? On Wednesday, October 2, 2013, fedinho wrote: Thanks for your response Jacob. I've been looking at the additive feature, but I'm not sure it solves my requirement. Given this configuration, I would like to debug class X on appender A, but still keep the info level messages from class X on appender B. I was hoping that this line would make this happen, but doesn't seem to work. log4j.logger.classX=debug, A Is there a simple example similar to my requirements somewhere? Thanks Fredrik On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome h...@visi.comjavascript:; wrote: On Tue, 1 Oct 2013 18:17:41 +0200 fedinho fedi...@gmail.com javascript:; wrote: Hi. A simple question I hope someone can help me with. This is using log4j 1.2.x I would like to log info level to one appender A and warn level to another appenderB. However, I would like to log debug messages from class X to appender A, and debug messages from class Y to appender B. Thanks for any tips for a configuration that will work. Threshold is not the way to go. Is there a way A and B can have different root loggers or categories? This is usually done by setting the logger additivity to false for either the logger in question or one it inherits from, which essentially makes the logger with additivity=false the root logger for all inheritors. See... http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts Kind regards Fredrik --**--**- To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org log4j-user-unsubscr...@logging.apache.org javascript:; For additional commands, e-mail: log4j-user-help@logging.**apache.org log4j-user-h...@logging.apache.org javascript:; - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Multiple appenders and verbose logging for specific classes for an appender
On Tue, 1 Oct 2013 18:17:41 +0200 fedinho fedi...@gmail.com wrote: Hi. A simple question I hope someone can help me with. This is using log4j 1.2.x I would like to log info level to one appender A and warn level to another appenderB. However, I would like to log debug messages from class X to appender A, and debug messages from class Y to appender B. Thanks for any tips for a configuration that will work. Threshold is not the way to go. Is there a way A and B can have different root loggers or categories? This is usually done by setting the logger additivity to false for either the logger in question or one it inherits from, which essentially makes the logger with additivity=false the root logger for all inheritors. See... http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts Kind regards Fredrik - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: ?????? ??????why can log4j2 not print on console in command window
Please post the contents of the manifest.mf file. Unless you have a period in the Class-Path value, then the current directory won't get placed in the classpath using the -jar option. Hence, your log4j2.xml won't get picked up. For instance.. Class-Path: . someJarDep.jar Jake On Mon, 9 Sep 2013 00:07:36 +0800 =?gb18030?B?wffX06lZ?= 41157...@qq.com wrote: 1.my project is named global,and it is compiled to global.jar using ant script ,the content of file named start.bat is as this:java -jar global.jar 2.When I run from the command line from my global.jar ,the log4j2.xml file is located at the same file directory level with global.jar and start.bat thank you for your answer ! Allen -- -- ??: Ralph Goers;ralph.go...@dslextreme.com; : 2013??9??8??(??) 11:53 ??: Log4J Users Listlog4j-user@logging.apache.org; : Re: ??why can log4j2 not print on console in command window 1. What does start.bat do? Can you post the source? 2. When you run from the command line from your jar where is the log4j2.xml file located? Ralph On Sep 8, 2013, at 8:36 AM, ?Y wrote: i use log4j2 as following: iimport org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; private static final Logger logger = LogManager.getLogger(OOXX.class); -- -- ??: ;41157...@qq.com; : 2013??9??8??(??) 11:32 ??: log4j-user-infolog4j-user-i...@logging.apache.org; log4j-user-faqlog4j-user-...@logging.apache.org; log4j-userlog4j-user@logging.apache.org; : why can log4j2 not print on console in command window I have use the version beta 8 for log4j2, I have third-party framework using in my project ,e.g. spring which using slf4j. and i import the jars into my libaray :log4j-over-slf4j-1.7.5.jar log4j-api-2.0-beta8.jar log4j-core-2.0-beta8.jar log4j-slf4j-impl-2.0-beta8.jar and my java environment is JDK 7,my configration file named log4j2.xml is as following : ?xml version=1.0 encoding=UTF-8?!-- status=debug log4j?? --configuration status=off monitorInterval=30 properties property name=LOG_HOME/log/fish/property !-- -- property name=BACKUP_HOME{LOG_HOME}/backup/property property name=STAT_NAMEstat/property property name=SERVER_NAMEglobal/property /properties appenders !-- ?? -- Console name=Console target=SYSTEM_OUT PatternLayout pattern=%date{-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n / /Console !-- ?? -- FastRollingFile name=DevLog fileName=${LOG_HOME}/${SERVER_NAME} filePattern=${LOG_HOME}/${SERVER_NAME}.%d{-MM-dd-HH}.log PatternLayout pattern=%date{-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n / PoliciesTimeBasedTriggeringPolicy interval=1 modulate=true / /Policies /FastRollingFile !-- -- FastRollingFile name=ProductLog fileName=${LOG_HOME}/${SERVER_NAME}_${STAT_NAME} filePattern=${LOG_HOME}/${SERVER_NAME}_${STAT_NAME}.%d{-MM-dd-HH}.log PatternLayoutpattern=%date{-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n / PoliciesTimeBasedTriggeringPolicy interval=1 modulate=true / /Policies /FastRollingFile /appenders loggers !-- 3rdparty Loggers -- logger name=org.springframework.core level=info /logger logger name=org.springframework.beans level=info /logger logger name=org.springframework.context level=info /logger logger name=org.springframework.web level=info /logger logger name=org.jboss.netty level=warn /logger logger name=org.apache.http level=warn /logger !-- Game Stat logger -- logger name=com.u9.global.service.log level=info additivity=false appender-ref ref=ProductLog / /logger !-- Root Logger -- root level=DEBUG appender-ref ref=DevLog / appender-ref ref=Console / /root /loggers/configuration when I run my project ,it works ok in eclipse,everything print ok in console. however,when i compile the project to jar ,and run it by start.bat ,log4j2 can.t print output in cmd window,i can't catch the reason,pls help me. thank you! - 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: Need help: Steps in your INSTALL doc failing
No, Mary is just running an example from the install documentation. And since the code is calling BasicConfigurator.configure(), there is no need for a config file in the classpath (though it is generally recommended to use a config file rather than configure via code). Mary, please provide an example of your java command line when you run this. It should look something like... java -cp log4j-1.2-17.jar Hello Jake On Tue, 14 May 2013 10:41:18 +0900 Remko Popma rem...@yahoo.com wrote: Mary, Gary was referring to log4j-2.0. While generally more awesome (ahem), it does need those 2 jars to run. You seem to be using log4j-1.2. Then you should only need the one jar. You also need a log4j.properties or log4j.xml file in a directory that is in the classpath. The site should have some sample config files. In your code, I don't think you need to call BasicConfigurator.configure(); I think you can safely remove that line; log4j will pick up your config file from the classpath. Sent from my iPhone On 2013/05/14, at 10:30, Mary Laude marylaudeci...@gmail.com wrote: Hey - thanks for the quick reply! Ya know, I read that bit but the jar file I have is named log4j-1.2-17.jar, and I thought it comprised everything. When I downloaded the code, that's the only jar file there was. Clearly, I was delusional! I'll go look for the corresponding API and core jar files... Thanks again! On Mon, May 13, 2013 at 6:00 PM, Gary Gregory garydgreg...@gmail.comwrote: You need the API and core jar files on your classpath for compilation and runtime. Gary On May 13, 2013, at 20:46, Mary Laude marylaudeci...@gmail.com wrote: Hello - I can write, compile, and successfully run a Java program to look at a .jar file and list the classes defined therein, but I can't for the life of me get your Using log4j java code shown in 1-2.17's INSTALL doc to work. Perhaps there's some other magic that needs to happen to get this code snippet you wrote to yield output? You can now test your installation by first compiling the following simple program. import org.apache.log4j.Logger; import org.apache.log4j.BasicConfigurator; public class Hello { private static final Logger logger = Logger.getLogger(Hello.class); public static void main(String argv[]) { BasicConfigurator.configure(); logger.debug(Hello world.); logger.info(What a beatiful day.); } } - I understand how CLASSPATH works, etc. I can get it to compile but even if I again (with option -cp) specify exactly where the .class file is that it just created from the compile, it still can't find what it needs. Depending on where I've put things and what I tell it, I get one of these failing results when I try to run the executable: (1) java.lang.NoClassDefFoundError: org/apache/log4j/Logger at Hello.clinit(Hello.java:6) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 1 more Exception in thread main or (2) Error: Could not find or load main class Hello Please, I am an old UNIX geek but this is really really frustrating me. I have looked literally EVERYWHERE to find out what the problem is but of course I am apparently the first and only person to ever have this problem. Ha! -- Please test what you build. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- Please test what you build. - 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: Need help: Steps in your INSTALL doc failing
Whoops, I neglected one thing... java -cp .;log4j-1.2-17.jar Hello Notice I added the current directory to the classpath. Change the classpath separator character to a colon if needed. Jake On Tue, 14 May 2013 09:00:57 -0700 Mary Laude marylaudeci...@gmail.com wrote: Here is what I just did. Note I am actually inside a Win VM, at a cygwin prompt. Mary@WinServ2008-Enterprise /home/Mary/apache-log4j-1.2.17 $ ls build.properties.sample INSTALL log4j-1.2.17.jar site build.xmlJarDir.class NOTICEsrc contribs JarDir.java NTEventLogAppender.amd64.dll tests examples KEYS NTEventLogAppender.dll Hello.java LICENSE pom.xml Mary@WinServ2008-Enterprise /home/Mary/apache-log4j-1.2.17 $ echo $CLASSPATH /home/Mary/apache-log4j-1.2.17/ Mary@WinServ2008-Enterprise /home/Mary/apache-log4j-1.2.17 $ javac -cp ./log4j-1.2.17.jar Hello.java Mary@WinServ2008-Enterprise /home/Mary/apache-log4j-1.2.17 $ java -cp ./log4j-1.2.17.jar Hello Error: Could not find or load main class Hello Mary@WinServ2008-Enterprise /home/Mary/apache-log4j-1.2.17 $ ls build.properties.sample Hello.javaLICENSE pom.xml build.xmlINSTALL log4j-1.2.17.jar site contribs JarDir.class NOTICEsrc examples JarDir.java NTEventLogAppender.amd64.dll tests Hello.class KEYS NTEventLogAppender.dll Any ideas? Thx. Mary On Tue, May 14, 2013 at 8:36 AM, Jacob Kjome h...@visi.com wrote: No, Mary is just running an example from the install documentation. And since the code is calling BasicConfigurator.configure(), there is no need for a config file in the classpath (though it is generally recommended to use a config file rather than configure via code). Mary, please provide an example of your java command line when you run this. It should look something like... java -cp log4j-1.2-17.jar Hello Jake On Tue, 14 May 2013 10:41:18 +0900 Remko Popma rem...@yahoo.com wrote: Mary, Gary was referring to log4j-2.0. While generally more awesome (ahem), it does need those 2 jars to run. You seem to be using log4j-1.2. Then you should only need the one jar. You also need a log4j.properties or log4j.xml file in a directory that is in the classpath. The site should have some sample config files. In your code, I don't think you need to call BasicConfigurator.configure(); I think you can safely remove that line; log4j will pick up your config file from the classpath. Sent from my iPhone On 2013/05/14, at 10:30, Mary Laude marylaudeci...@gmail.com wrote: Hey - thanks for the quick reply! Ya know, I read that bit but the jar file I have is named log4j-1.2-17.jar, and I thought it comprised everything. When I downloaded the code, that's the only jar file there was. Clearly, I was delusional! I'll go look for the corresponding API and core jar files... Thanks again! On Mon, May 13, 2013 at 6:00 PM, Gary Gregory garydgreg...@gmail.com wrote: You need the API and core jar files on your classpath for compilation and runtime. Gary On May 13, 2013, at 20:46, Mary Laude marylaudeci...@gmail.com wrote: Hello - I can write, compile, and successfully run a Java program to look at a .jar file and list the classes defined therein, but I can't for the life of me get your Using log4j java code shown in 1-2.17's INSTALL doc to work. Perhaps there's some other magic that needs to happen to get this code snippet you wrote to yield output? --**--** You can now test your installation by first compiling the following simple program. import org.apache.log4j.Logger; import org.apache.log4j.**BasicConfigurator; public class Hello { private static final Logger logger = Logger.getLogger(Hello.class); public static void main(String argv[]) { BasicConfigurator.configure(); logger.debug(Hello world.); logger.info(What a beatiful day.); } } --**--** - I understand how CLASSPATH works, etc. I can get it to compile but even if I again (with option -cp) specify exactly where the .class file is that it just created from the compile, it still can't find what it needs. Depending on where I've put things and what I tell it, I get one of these failing results when I try to run the executable: (1) java.lang.**NoClassDefFoundError: org/apache/log4j/Logger at Hello.clinit(Hello.java:6) Caused by: java.lang.**ClassNotFoundException: org.apache.log4j.Logger at java.net.URLClassLoader$1.run(**URLClassLoader.java:366) at java.net.URLClassLoader$1.run(**URLClassLoader.java:355) at java.security.**AccessController.doPrivileged
Re: Communcating An Own Properties-Object To log4j As Substtution For System-Properties
Well, you can manually bind properties at configuration time by loading the config as a properties object, adding more properties, and then calling configure(Properties) [1]. It's not clear to me how this might be done with XML configuration, thought I vaguely recall it being talked about in the past? [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.util.Properties%29 Jake On Fri, 16 Nov 2012 15:12:18 +0100 malte.kem...@de.equens.com wrote: Hi to all (again), I just thought on theoretical level. My problem, using log4j in a mulithraded environment using Apender that create file names using property input could only work, if it is possible to give the appender (log4) An own properties-object, rahter than using the Systm-Properties. Is there a method, with that you are able to tell an apender to get an very own Properties-Object with out the need to change the configuration possibility using ${propertiesname} to address the partcular property? right now my appender configuration looks liek that: appender name=xsd-check class=de.cmk.log4j.NameComposingFileAppender param name=string4Construction value=${input.file.path}/param param name=inputRegex value=(.*)/param param name=file value=logs/[user.name]/XSDCHECK.(0).log /param param name=Append value=false / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-5p %m%n / /layout /appender I would like to tell the an appender, by using a log4j-method within a certian application init-time. Is there something like that or is something like that planned in a later version of log4j? (Is there any chance something like that would work at all?) thanks in advancs for any hints Malte -Ursprüngliche Nachricht- Von: malte.kem...@de.equens.com [mailto:malte.kem...@de.equens.com mailto:malte.kem...@de.equens.com ] Gesendet: Freitag, 16. November 2012 13:37 An: log4j-user@logging.apache.org Betreff: AW: Funny Bbehaviour Wth A Customzed Appender Hi Gary, finally I found the trouble. It got nothing to do with log4j itself. It is the stuff around my application, since I comuniate the input file names within Systemproperties, that are filled by one but not by the other application. The logger produces empty files for each, even though the other application not even running. I guess the cause of this is that I am using just one logging config for all my applcations. I probably could fix this behaviour by using for each application an own logger config. Inkow, using system properties is not the best choice, because they are global. That makes thread safety impossible. For a long term I should overthink the comunication of properties to my NamedFileAppender. Is there another way to build up a file name for the logging using things like input file names may be with appenders that are shiiped with log4j? Malte Von: Gary Gregory [mailto:garydgreg...@gmail.com mailto:garydgreg...@gmail.com ] Gesendet: Donnerstag, 15. November 2012 18:03 An: Log4J Users List Betreff: Re: Funny Bbehaviour Wth A Customzed Appender Hi Malte, You should probably file a Bugzilla issue but I am not sure how much help you'll get here because you are using custom code. There you can attach all the files you want. Can this be reproduced in any way with a stock appender of any type like a rolling file appender? The best way to get anyone to help is to create a standalone program that illustrates the problem. Ideally, it should be a unit test that fails. Another question that will come up is, does using the current version, 1.2.17, work better? Differently? Gary On Thu, Nov 15, 2012 at 11:14 AM, malte.kem...@de.equens.com wrote: Hi to all, I have programmed an appender dirived from FileAppender, that is able to produce log-files with file names that you can controll in a more flexible way. You can use an other String, for example the input file, or parts of it to produce your desired log file name, seq-numbers and time stamps etc. My applcation, that got the log-config (actually the xml configuration type) is a mroe infratstuctional Programm, that calls other applications like converters. I have put all in one single log-configuration-file using the cusomized appender on several file processing applcations. The confguration is like this, that each processed file is suppose to produce one log file per application that is processing it. For one application it works pretty good. Ror another it produces each expected log file but produces the logs for all turns only in one file. The others stay empty. I am not sure what I am doing wrong and what is going on here. I cannot understand
Re: Communcating An Own Properties-Object To log4j As Substtution For System-Properties
Yes, but that file-based configuration is only read once, and the appender only sees the fully resolved value and does not maintain the ${propertyname} for dynamic runtime substitution. Even the solution I proposed only applies the one time. It just allows you to define local properties rather than depending on System properties set JVM-wide. You have to obtain an reference to the appender object and re-set its properties. This is most certainly doable. Just look up a logger that the appender is assigned to and use getAppender(appenderName). Then you can modify the appender to your heart's content. Jake On Fri, 16 Nov 2012 18:26:10 +0100 malte.kem...@de.equens.com wrote: Hi Jake, Thanks for the hint. But I am afraid that is not quite that what I ment. Looking at the example below there is the following line: param name=string4Construction value=${input.file.path}/param Here the parameter string4Construction gets a value from the SystemProperty input.file.path. So actually if the SystemProperty's value is MyInputFile.txt then the parameter string4Construction got exactly its value MyInputFile.txt. The syntax ${propertyname} is already built in somewhere of log4j, I think, which means that it will be looked at runtime on the System-Properties for getting the value of the property named here. If I knew where in the code of log4j that resolving takes place, I could may be understand how to manage it, to give dynamigly own Properties-ojects while run-time. Since there was no special code needed for inventing own parameters, but producing setter-methods in the customized appender, I believe log4j binds the parameters by reflection. Malte -Ursprüngliche Nachricht- Von: Jacob Kjome [mailto:h...@visi.com] Gesendet: Freitag, 16. November 2012 18:04 An: Log4J Users List Betreff: Re: Communcating An Own Properties-Object To log4j As Substtution For System-Properties Well, you can manually bind properties at configuration time by loading the config as a properties object, adding more properties, and then calling configure(Properties) [1]. It's not clear to me how this might be done with XML configuration, thought I vaguely recall it being talked about in the past? [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.util.Properties%29 Jake On Fri, 16 Nov 2012 15:12:18 +0100 malte.kem...@de.equens.com wrote: Hi to all (again), I just thought on theoretical level. My problem, using log4j in a mulithraded environment using Apender that create file names using property input could only work, if it is possible to give the appender (log4) An own properties-object, rahter than using the Systm-Properties. Is there a method, with that you are able to tell an apender to get an very own Properties-Object with out the need to change the configuration possibility using ${propertiesname} to address the partcular property? right now my appender configuration looks liek that: appender name=xsd-check class=de.cmk.log4j.NameComposingFileAppender param name=string4Construction value=${input.file.path}/param param name=inputRegex value=(.*)/param param name=file value=logs/[user.name]/XSDCHECK.(0).log /param param name=Append value=false / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{ISO8601} %-5p %m%n / /layout /appender I would like to tell the an appender, by using a log4j-method within a certian application init-time. Is there something like that or is something like that planned in a later version of log4j? (Is there any chance something like that would work at all?) thanks in advancs for any hints Malte -Ursprüngliche Nachricht- Von: malte.kem...@de.equens.com [mailto:malte.kem...@de.equens.com mailto:malte.kem...@de.equens.com ] Gesendet: Freitag, 16. November 2012 13:37 An: log4j-user@logging.apache.org Betreff: AW: Funny Bbehaviour Wth A Customzed Appender Hi Gary, finally I found the trouble. It got nothing to do with log4j itself. It is the stuff around my application, since I comuniate the input file names within Systemproperties, that are filled by one but not by the other application. The logger produces empty files for each, even though the other application not even running. I guess the cause of this is that I am using just one logging config for all my applcations. I probably could fix this behaviour by using for each application an own logger config. Inkow, using system properties is not the best choice, because they are global. That makes thread safety impossible. For a long term I should overthink the comunication of properties to my NamedFileAppender. Is there another way to build up a file name for the logging using things like input file names may be with appenders that are shiiped with log4j? Malte
Re: each log message output twice
The x logger inherits the root appender instances (unless you set additivity for x to false). But then you are adding new appender instances to the x logger, so you have 4 instances; 2 per/appender. Therefore, you should expect each message to be written twice to each appender. Remove the references to the appenders on the x logger, and you will get the behavior your were hoping for. Jake On Thu, 8 Nov 2012 16:49:49 +0800 (SGT) tong123123 tong123...@yahoo.com.hk wrote: My log4j.properties file is as follow log4j.rootLogger=error, A1, A2 log4j.logger.x=info, A1, A2 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d %-5p (%13F:%L) %3x - %m%n # Appender A2 writes to the file test. log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender log4j.appender.A2.DatePattern='.'-MM-dd log4j.appender.A2.File=./debugleveldemo_logs/debugleveldemo.log # Appender A2 uses the PatternLayout. log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n in my project, I have a class in package x.y and named TestLog4j. the relevant code is as follow: static Logger logger = Logger.getLogger(TestLog4j.class); void method1(){ Properties props = new Properties(); try { // the file need placed in C:\workspace\workspace1\TestLog4j {root folder} props.load(new FileInputStream(log4j.properties)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } PropertyConfigurator.configure(props); logger.debug(debug); logger.info(info); logger.warn(warn); System.out.println(see system out); } the output log message is duplicate as follow: 2012-11-08 16:37:10,478 INFO (TestLog4j.java:30) - info 2012-11-08 16:37:10,478 INFO (TestLog4j.java:30) - info 2012-11-08 16:37:10,490 WARN (TestLog4j.java:31) - warn 2012-11-08 16:37:10,490 WARN (TestLog4j.java:31) - warn see system out why each log message is displayed twice? for rootLogger, the level is error, so should not be triggered, and only log4j.logger.x is triggered, so I expected the debug message should be displayed only once. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: all log4j level in jar application is treated as debug level
This sort of confusion is almost always caused by some other configuration file being loaded rather than the one you expect. I suggest setting -Dlog4j.debug=true on the command line (in this case, the command line starting the appserver), which will cause Log4j to provide information on how it is configuring the application. Note that it's also possible the the correct config file is being loaded, but then some application code is dynamically reconfiguring without you realizing it. Ensure that no code is manually configuration Log4j after initialization. Jake On Wed, 7 Nov 2012 17:20:09 +0800 (SGT) tong123123 tong123...@yahoo.com.hk wrote: I have a web application and it use my another application packed as jar. in war\web-inf\classes\log4j.properties, I wrote log4j.rootLogger=WARN, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout.ConversionPattern=%d %-5p (%13F:%L) %3x -%m%n then in my web application I wrote private static Logger logger = Logger.getLogger(MyWebApp.class); logger.debug(debug); logger.warn(warn); the output is as expected, only warn will be shown. but in my jar application, I wrote private static Logger logger = Logger.getLogger(JarApp.class); logger.warn(warn in jar); there is no output in console!!! and if I change the log4j.properties log level to DEBUG log4j.rootLogger=, A1 then the warn in jar will be shown in console, but with %-5p shown as DEBUG. That is, even in my jar application, I wrote logger.warn(warn in jar); log4j still treat it as DEBUG level, why will this happen? I am using log4j-1.2.16.jar - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4j Extras ExpressionFilter issue
When you added the URL to the marker field, did you add it with or amp;? When setting it via MDC, I'd be setting it as . But, in XML, it must be escaped using amp; otherwise we'll get a parsing error, since is a reserved character that defines the start of an entity reference. In fact, I'm not sure how you were able to define level == info prop.marker=... without experiencing a parsing error, such as log4j:WARN Fatal parsing error 15 and column 67 log4j:WARN The entity name must immediately follow the '' in the entity reference. log4j:ERROR Could not parse url [file:./log4j.xml]. org.xml.sax.SAXParseException: The entity name must immediately follow the '' in the entity reference. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:769) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:871) In any case, if anything, I'd expect to see **no** TRACE output if it had trouble matching the value. Instead, I see **all** trace output. It's as if it were able to parse the LEVEL == TRACE part, but then silently ignore the rest of the configuration that, maybe, it was unable to parse? Or maybe, it silently ignored the entire expression altogether, leaving me with only the fact that the TRACE level is enabled for the particular logger I am using, so the TRACE info was logged regardless. In fact, the latter appears to be the case. The expression is totally ignored. I tried the following minimal expression, and I continued to get DEBUG info, as well as TRACE info... appender name=default class=org.apache.log4j.rolling.RollingFileAppender ... filter class=org.apache.log4j.filter.ExpressionFilter param name=Expression value=(level = info)/ /filter /appender Are you sure this thing works outside of Chainsaw? I'm not using Chainsaw here, just logging to a RollingFileAppender in a command-line application. BTW, I'm also using SLF4J, binding to Log4j-1.2.17. Jake On Thu, 4 Oct 2012 15:38:59 -0700 Scott Deboy scott.de...@gmail.com wrote: Hey Jake I tried this in the latest developer snapshot of Chainsaw..I pulled up a log in Chainsaw which contained info and debug entries (I didn't have a log with trace). And I added your URL value you provided in the 'marker' field of two of my INFO entries This expression: (level = debug) || (level == info prop.marker == ' https://somedomain/somepath/somepage.do?someparam=somevalamp;anotherparam=anotherval ') Gave me all of the debug entries and two info level entries.. It could be something weird with trace...or something weird with parsing the amp; ??? but...this should work.. Scott On Wed, Oct 3, 2012 at 8:56 AM, Jacob Kjome h...@visi.com wrote: Thanks Scott, However, while I didn't experience an error in parsing the expression this time, the expression seems to be, at least partially, ignored. Below is the relevant config, where com.mypackage.MyClass sets MDC (via SLF4J) with a url key and the currently processed URL as the value, then logs the page content for the URL at the TRACE level (with MDC removal of url immediately after logging the page content). But rather than getting TRACE output for only the URL defined in the Expression, I get **all** TRACE output. It's like it sees the LEVEL == TRACE but then ignores the . Thoughts? appender name=default class=org.apache.log4j.** rolling.RollingFileAppender ... filter class=org.apache.log4j.**filter.ExpressionFilter param name=Expression value=( LEVEL = DEBUG ) || ( LEVEL == TRACE amp;amp; PROP.url == 'https://somedomain/somepath/** somepage.do?someparam=someval**amp;anotherparam=anothervalhttps://somedomain/somepath/somepage.do?someparam=somevalanotherparam=anotherval' )/ /filter /appender logger name=com.mypackage.MyClass level value=TRACE/ /logger root level value=WARN/ appender-ref ref=default/ /root On Tue, 2 Oct 2012 15:53:57 -0700 Scott Deboy scott.de...@gmail.com wrote: Try PROP.url == 'blah' MDC entries are really just set as properties of the log4j events. Scott On Tue, Oct 2, 2012 at 1:10 PM, Jacob Kjome h...@visi.com wrote: I'm trying to use the ExpressionFilter [1] from Log4j Extras to limit logging for a particular appender to those cases where MDC contains a url entry that equals some specific value. But I get an error from Log4j saying Invalid EQUALS rule - MDC.url is not a supported field (see below for complete error output from Log4j). I'm using the latest versions of Log4j-1.x and Log4j-extras. Here's the relevant config... appender... filter class=org.apache.log4j
Re: Log4j Extras ExpressionFilter issue
Here's the relevant Log4j debug output (no error thrown upon parsing, as you can see)... log4j: Class name: [org.apache.log4j.rolling.RollingFileAppender] log4j: Setting property [fileNamePattern] to [./logs/myapp.%d.log.gz]. log4j: Parsing layout of class: org.apache.log4j.PatternLayout log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} [%-5p][%-8.8t]: %39.39c - %m%n]. log4j: Setting property [expression] to [(level = info)]. log4j: Adding filter of type [class org.apache.log4j.filter.ExpressionFilter] to appender named [default]. log4j: setFile called: ./logs/myapp.2012-10-05.log, true log4j: setFile ended log4j: Adding appender named [default] to category [root]. Yet, I get TRACE and DEBUG output in the log file. I even tried a second run, removing the parens and had just level = info. Same thing. I still get TRACE and DEBUG output when I've clearly specified in the expression that it should filter everything but INFO and above. Jake On Fri, 5 Oct 2012 13:47:27 -0700 Scott Deboy scott.de...@gmail.com wrote: Right, in the XML it has to be escaped for the filter. Chainsaw uses the same expression-handling code the ExpressionFilter uses (ExpressionRule), which is why as long as the xml parsing is working as expected it should be an equivalent test. ExpressionRule throws an exception if the expression couldn't be parsed, so if you turned on -Dlog4j.debug you'd see an error when the ExpressionFilter parsing happens. Scott On Fri, Oct 5, 2012 at 1:38 PM, Jacob Kjome h...@visi.com wrote: When you added the URL to the marker field, did you add it with or amp;? When setting it via MDC, I'd be setting it as . But, in XML, it must be escaped using amp; otherwise we'll get a parsing error, since is a reserved character that defines the start of an entity reference. In fact, I'm not sure how you were able to define level == info prop.marker=... without experiencing a parsing error, such as log4j:WARN Fatal parsing error 15 and column 67 log4j:WARN The entity name must immediately follow the '' in the entity reference. log4j:ERROR Could not parse url [file:./log4j.xml]. org.xml.sax.SAXParseException: The entity name must immediately follow the '' in the entity reference. at com.sun.org.apache.xerces.**internal.parsers.DOMParser.** parse(DOMParser.java:249) at com.sun.org.apache.xerces.**internal.jaxp.** DocumentBuilderImpl.parse(**DocumentBuilderImpl.java:284) at org.apache.log4j.xml.**DOMConfigurator$2.parse(** DOMConfigurator.java:769) at org.apache.log4j.xml.**DOMConfigurator.doConfigure(** DOMConfigurator.java:871) In any case, if anything, I'd expect to see **no** TRACE output if it had trouble matching the value. Instead, I see **all** trace output. It's as if it were able to parse the LEVEL == TRACE part, but then silently ignore the rest of the configuration that, maybe, it was unable to parse? Or maybe, it silently ignored the entire expression altogether, leaving me with only the fact that the TRACE level is enabled for the particular logger I am using, so the TRACE info was logged regardless. In fact, the latter appears to be the case. The expression is totally ignored. I tried the following minimal expression, and I continued to get DEBUG info, as well as TRACE info... appender name=default class=org.apache.log4j.** rolling.RollingFileAppender ... filter class=org.apache.log4j.**filter.ExpressionFilter param name=Expression value=(level = info)/ /filter /appender Are you sure this thing works outside of Chainsaw? I'm not using Chainsaw here, just logging to a RollingFileAppender in a command-line application. BTW, I'm also using SLF4J, binding to Log4j-1.2.17. Jake On Thu, 4 Oct 2012 15:38:59 -0700 Scott Deboy scott.de...@gmail.com wrote: Hey Jake I tried this in the latest developer snapshot of Chainsaw..I pulled up a log in Chainsaw which contained info and debug entries (I didn't have a log with trace). And I added your URL value you provided in the 'marker' field of two of my INFO entries This expression: (level = debug) || (level == info prop.marker == ' https://somedomain/somepath/**somepage.do?someparam=someval** amp;anotherparam=anothervalhttps://somedomain/somepath/somepage.do?someparam=somevalanotherparam=anotherval ') Gave me all of the debug entries and two info level entries.. It could be something weird with trace...or something weird with parsing the amp; ??? but...this should work.. Scott On Wed, Oct 3, 2012 at 8:56 AM, Jacob Kjome h...@visi.com wrote: Thanks Scott, However, while I didn't experience an error in parsing the expression this time, the expression seems to be, at least partially, ignored. Below is the relevant config, where com.mypackage.MyClass sets MDC (via SLF4J) with a url key and the currently processed URL as the value, then logs the page content for the URL at the TRACE level
Re: Log4j Extras ExpressionFilter issue
Thanks Scott, However, while I didn't experience an error in parsing the expression this time, the expression seems to be, at least partially, ignored. Below is the relevant config, where com.mypackage.MyClass sets MDC (via SLF4J) with a url key and the currently processed URL as the value, then logs the page content for the URL at the TRACE level (with MDC removal of url immediately after logging the page content). But rather than getting TRACE output for only the URL defined in the Expression, I get **all** TRACE output. It's like it sees the LEVEL == TRACE but then ignores the . Thoughts? appender name=default class=org.apache.log4j.rolling.RollingFileAppender ... filter class=org.apache.log4j.filter.ExpressionFilter param name=Expression value=( LEVEL = DEBUG ) || ( LEVEL == TRACE amp;amp; PROP.url == 'https://somedomain/somepath/somepage.do?someparam=somevalamp;anotherparam=anotherval' )/ /filter /appender logger name=com.mypackage.MyClass level value=TRACE/ /logger root level value=WARN/ appender-ref ref=default/ /root On Tue, 2 Oct 2012 15:53:57 -0700 Scott Deboy scott.de...@gmail.com wrote: Try PROP.url == 'blah' MDC entries are really just set as properties of the log4j events. Scott On Tue, Oct 2, 2012 at 1:10 PM, Jacob Kjome h...@visi.com wrote: I'm trying to use the ExpressionFilter [1] from Log4j Extras to limit logging for a particular appender to those cases where MDC contains a url entry that equals some specific value. But I get an error from Log4j saying Invalid EQUALS rule - MDC.url is not a supported field (see below for complete error output from Log4j). I'm using the latest versions of Log4j-1.x and Log4j-extras. Here's the relevant config... appender... filter class=org.apache.log4j.**filter.ExpressionFilter param name=Expression value=MDC.url == ' http://somedomain/somepath'/** /filter /appender Based on the documentation [2] and commit comment [3] I found, it seems like this should work. What am I missing? Here's the complete error output from Log4j... log4j:ERROR Could not create an Appender. Reported error follows. java.lang.**IllegalArgumentException: Invalid EQUALS rule - MDC.url is not a supported field at org.apache.log4j.rule.**EqualsRule.init(EqualsRule.**java:62) at org.apache.log4j.rule.**EqualsRule.getRule(EqualsRule.** java:100) at org.apache.log4j.rule.**EqualsRule.getRule(EqualsRule.** java:85) at org.apache.log4j.rule.**RuleFactory.getRule(** RuleFactory.java:154) at org.apache.log4j.rule.**ExpressionRule$** PostFixExpressionCompiler.**compileExpression(**ExpressionRule.java:149) at org.apache.log4j.rule.**ExpressionRule.getRule(** ExpressionRule.java:100) at org.apache.log4j.filter.**ExpressionFilter.**activateOptions(** ExpressionFilter.java:95) at org.apache.log4j.config.**PropertySetter.activate(** PropertySetter.java:307) at org.apache.log4j.xml.**DOMConfigurator.parseFilters(** DOMConfigurator.java:380) at org.apache.log4j.xml.**DOMConfigurator.parseAppender(** DOMConfigurator.java:273) at org.apache.log4j.xml.**DOMConfigurator.**findAppenderByName(** DOMConfigurator.java:176) at org.apache.log4j.xml.**DOMConfigurator.** findAppenderByReference(**DOMConfigurator.java:191) at org.apache.log4j.xml.**DOMConfigurator.** parseChildrenOfLoggerElement(**DOMConfigurator.java:523) at org.apache.log4j.xml.**DOMConfigurator.parseRoot(** DOMConfigurator.java:492) at org.apache.log4j.xml.**DOMConfigurator.parse(** DOMConfigurator.java:1006) at org.apache.log4j.xml.**DOMConfigurator.doConfigure(** DOMConfigurator.java:872) at org.apache.log4j.xml.**DOMConfigurator.doConfigure(** DOMConfigurator.java:778) at org.apache.log4j.helpers.**OptionConverter.** selectAndConfigure(**OptionConverter.java:526) at org.apache.log4j.LogManager.**clinit(LogManager.java:127) at org.slf4j.impl.**Log4jLoggerFactory.getLogger(** Log4jLoggerFactory.java:64) at org.slf4j.LoggerFactory.**getLogger(LoggerFactory.java:**270) at org.slf4j.LoggerFactory.**getLogger(LoggerFactory.java:**281) [1] http://logging.apache.org/**log4j/companions/extras/** apidocs/org/apache/log4j/**filter/ExpressionFilter.htmlhttp://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html [2] https://logging.apache.org/**log4j/companions/extras/** apidocs/org/apache/log4j/spi/**LoggingEventFieldResolver.htmlhttps://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/spi/LoggingEventFieldResolver.html [3] http://mail-archives.apache.**org/mod_mbox/logging-log4j-** dev/200310.mbox/%**3C20031027083531.85866.qmail@**minotaur.apache.org%3Ehttp://mail-archives.apache.org/mod_mbox/logging-log4j-dev/200310
Log4j Extras ExpressionFilter issue
I'm trying to use the ExpressionFilter [1] from Log4j Extras to limit logging for a particular appender to those cases where MDC contains a url entry that equals some specific value. But I get an error from Log4j saying Invalid EQUALS rule - MDC.url is not a supported field (see below for complete error output from Log4j). I'm using the latest versions of Log4j-1.x and Log4j-extras. Here's the relevant config... appender... filter class=org.apache.log4j.filter.ExpressionFilter param name=Expression value=MDC.url == 'http://somedomain/somepath'/ /filter /appender Based on the documentation [2] and commit comment [3] I found, it seems like this should work. What am I missing? Here's the complete error output from Log4j... log4j:ERROR Could not create an Appender. Reported error follows. java.lang.IllegalArgumentException: Invalid EQUALS rule - MDC.url is not a supported field at org.apache.log4j.rule.EqualsRule.init(EqualsRule.java:62) at org.apache.log4j.rule.EqualsRule.getRule(EqualsRule.java:100) at org.apache.log4j.rule.EqualsRule.getRule(EqualsRule.java:85) at org.apache.log4j.rule.RuleFactory.getRule(RuleFactory.java:154) at org.apache.log4j.rule.ExpressionRule$PostFixExpressionCompiler.compileExpression(ExpressionRule.java:149) at org.apache.log4j.rule.ExpressionRule.getRule(ExpressionRule.java:100) at org.apache.log4j.filter.ExpressionFilter.activateOptions(ExpressionFilter.java:95) at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307) at org.apache.log4j.xml.DOMConfigurator.parseFilters(DOMConfigurator.java:380) at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:273) at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:176) at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:191) at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:523) at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:492) at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:1006) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:872) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:778) at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526) at org.apache.log4j.LogManager.clinit(LogManager.java:127) at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:64) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281) [1] http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html [2] https://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/spi/LoggingEventFieldResolver.html [3] http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/200310.mbox/%3c20031027083531.85866.qm...@minotaur.apache.org%3E Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Pushing STDOUT to File...
You don't appear to reference your DRFA appender in any logger. You specifically reference the console appender in the rootLogger. Why do you think that your logging should go to file when you specifically have it configure to go to Console? Jake On Mon, 1 Oct 2012 18:17:35 +0100 Lewis John Mcgibbney lewis.mcgibb...@gmail.com wrote: Good Afternoon, I currently am working on the following log4j.properties file [0] as I use many classes from the terminal and I would like to be able to store the logs (redirect?) them to a file. Currently this is just not happening for me even though (AFAIK) I've specified the DRFA and various other configuration. Still when I use my classes from the terminal no log directory appears and no gora.log appears within the log directory... this is what I would like. I can't seem to sort this one out...any help would be greatly appreciated. Kind Regards Lewis [0] http://svn.apache.org/repos/asf/gora/trunk/conf/log4j.properties -- Lewis - 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: Logging with specialized logger for webapplication
I think some of your config is missing. It must have gotten messed up by your email client or something? Maybe you can try to attach (can't remember if the list allows attachments) or post a link to the config. Jake On Mon, 25 Jun 2012 05:05:38 -0700 (PDT) garfield168 garfield...@gmx.de wrote: Hello, We use WebSphere as application server which has the standard logging files SystemOut.log and SystemErr.log. I want to create a log4j configuration with a special logger SpecialLogger which logs all debug/info/error messages to a special log file. Additionally error messages should be logged to SystemErr.log but the debug/info messages from this logger should not be logged to SystemOut.log (but other info messages not from this logger should be logged). Maybe there is a solution with additivity=false and LevelRangeFilter but I cannot get it work like described. Here is my last try: ?xml version=1.0? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=stdout class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.PatternLayout /layout /appender appender name=SpecialLoggerAppender class=org.apache.log4j.RollingFileAppender layout class=org.apache.log4j.SimpleLayout/ filter class=org.apache.log4j.varia.LevelRangeFilter /filter /appender logger name=SpecialLogger additivity=false level value=error / appender-ref ref=SpecialLoggerAppender / /logger root level value=error/ appender-ref ref=stdout / /root /log4j:configuration Can someone help please? Thanks in advance -- View this message in context: http://old.nabble.com/Logging-with-specialized-logger-for-webapplication-tp34066057p34066057.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: User-based logger level
It's possible that Log4j2 supports this out of the box, but for Log4j1, the obvious way is to call logger.log() methods that accept an explicit Level/Priority [1]. Set a ThreadLocal with the Level to use and pass that Level to log() method. [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log%28org.apache.log4j.Priority,%20java.lang.Object%29 Jake On Mon, 11 Jun 2012 17:55:10 +0800 yong...@agfa.com wrote: Dear all, We're about to implement a logging strategy that for different users different effective logger level are used. In particular, we are doing EJB, and we have already pushed user info onto MDC to implement this strategy. By default, the system will run using the following example logger levels for all users: root = INFO com.my.ejb1=WARNING com.my.ejb2=INFO // different ejbs may have different default levels ... When a system setting is enabled at runtime, we want to change com.my.ejb1=DEBUG, but only for a few selected users. That is, if user A invokes ejb1, all ejb1 log messages with level = DEBUG will be logged, while if another user B invokes ejb1, it uses the default setting, and only messages with level = WARNING will be logged. (it also honors the logger hierarchy, that is if we want to change the level for a package, all ejbs in that package behave in the same way) We will do this on our production systems, so performance is critical. What would be a good way to achieve this? Kind Regards, Yong - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: class specific logging level
How do you define your logger in your Java code? I'm suspicious that the logger name you've defined as MyClass is merely the simple name of the class, not the fully qualified name of the class that you've likely defined it for your logger name. That is, if MyClass is in the package com.mypackage, and you've defined the logger using something like... Logger logger = Logger.getLogger(MyClass.class); OR Logger logger = Logger.getLogger(MyClass.class.getName()); ...then your configuration should be logger name=com.mypackage.MyClass level value=DEBUG / /logger Note that additivity is true by default and need only be specified if you want to set it to false (which would mean you wouldn't inherit appenders/levels from ancestor loggers). Also note that priority is the deprecated name for level. It will work the same, but you should just use level to avoid confusion. Finally, you mention you want all other classes to log at the ERROR level, yet you defined the level in root as INFO. Typo? Jake On Fri, 8 Jun 2012 08:45:21 -0700 (PDT) aggarwal akansha.ag...@gmail.com wrote: Hi, I have tried it with the following configuration : appender name=Log1 class=org.apache.log4j.RollingFileAppender layout class=org.apache.log4j.PatternLayout /layout /appender logger name=MyClass additivity=true level value=DEBUG / /logger root priority value=INFO / appender-ref ref=Log1 / /root I want MyClass logs of DEBUG level and all other classes of ERROR in log1.log file as mentioned in logger Log1. But it isnt happening. Am not getting any DEBUG logs in log1.log whereas if I set the level in appender Log1 to DEBUG, I do get the DEBUG logs of Myclass in log1.log. I am sorry if am still making some mistake here. Please correct me where am I wrong. Thanks for such quick replies. Jacob Kjome wrote: What I've provided does exactly what you are asking for. Setting your class logging level to DEBUG overrides the inherited level from root for the specified logger name. Why don't you just try it and see what it does rather than speculate on why you believe it wouldn't work? You can also read try reading the docs... http://logging.apache.org/log4j/1.2/manual.html Jake On Thu, 7 Jun 2012 20:44:05 -0700 (PDT) aggarwal akansha.ag...@gmail.com wrote: So when root level is ERROR and i set Myclass level to DEBUG, how will the Myclass's DEBUG logs get logged since the root level is ERROR and it will block the DEBUG logs ? What i know is that, if I set root level to DEBUG and some particular class (say Myclass) logger level to ERROR then, all classes' logs of DEBUG will get logged but not of Myclass as its restricted to ERROR. But what I want is the vice-versa. I want ERROR level of all classes and DEBUG of only few important classes. I am new to log4j so maybe what i am sayin is wrong. Jacob Kjome wrote: If you name your loggers by class name, then sure. This is standard logging configuration, not some extra special workaround. logger name=com.mypackage.Myclass level value=debug/ !-- inherits A1 appender from root, applies only to com.mypackage.MyClass -- /logger logger name=com.myotherpackage level value=debug/ !-- inherits A1 appender from root, applies to all classes in com.myotherpackage -- /logger root level value=error/ appender-ref ref=A1/ /root Jake On Thu, 7 Jun 2012 01:51:07 -0700 (PDT) aggarwal akansha.ag...@gmail.com wrote: Hi, Is it possible to set logging level for few selected classes in appender to DEBUG and rest all ERROR ? Is there any combination of filter that can do this ? -- View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.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/class-specific-logging-level-tp33974515p33979415.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/class-specific-logging
Re: class specific logging level
First, you are not setting the level of the appender, but that of the logger which can reference any given appender, including your named Log1 appender. So, if you want ERROR level for all classes, then set the root logger level to ERROR. After that, you make a decision of which appenders you want logging to go to (disregarding level, as that is the job of the logger - except in regard to more advanced configuration where you can set appender level thresholds or use filters, but that's beyond our discussion here). If you want output of all classes (again, disregarding level) to go to the Log1, then you provide a reference to Log1 in the primordial root logger. After that, if you want to lower the level for specific loggers, you can specify those as you've done with com.pkg.MyClass. Now all classes, including com.pkg.MyClass will log at the ERROR level, but com.pkg.MyClass will also provide DEBUG, INFO, and WARN (and SEVERE) logging as well. This is all very standard stuff. If you don't experience the above behavior, then I would suspect that the Log4j configuration you think you are using isn't being used at all. You might want to use... -Dlog4j.debug=true This will tell Log4j to report how it is being configured. You may find that some other configuration is being used instead of yours. Either that, or you are not describing what you want clearly enough. Jake On Fri, 8 Jun 2012 09:15:14 -0700 (PDT) aggarwal akansha.ag...@gmail.com wrote: If I set the level of Log1 appender to DEBUG, then DEBUG logs of all the classes including MyClass are getting logged. If I set it to ERROR, then ERROR logs of all the classes including MyClass are getting logged. But what I want is - DEBUG logs of only MyClass and ERROR of rest all. Here, my motive is to set DEBUG level logging for most important classes helping in debugging procedure. logger name=com.pkg.MyClass level value=DEBUG / /logger private final static Logger logger = Logger.getLogger(MyClass.class); This is how a logger is defined in my code. It was my mistake to replace com.pkg.MyClass with MyClass. Thanks for additivity and priority related suggestions. Actually, root isn't my concern here. No matter what the level of root and appender is, I want DEBUG logs of only MyClass. Douglas E Wegscheid wrote: I want MyClass logs of DEBUG level and all other classes of ERROR in log1.log file as mentioned in logger Log1. ... whereas if I set the level in appender Log1 to DEBUG, I do get the DEBUG logs of Myclass in log1.log. If you set the level of the Log1 appender to DEBUG, you say that you get the DEBUG logs of Myclass in log1.log. Isn't that what you want? -- View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33982558.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: SMTPAppender MDC
Alternatively, if you want to stick with Log4j, try. http://openutils.sourceforge.net/openutils-log4j/smtpappender.html Jake On Thu, 07 Jun 2012 11:40:31 +0200 ceki c...@qos.ch wrote: Hi Zbynek, Have you looked at logback? Its SMTPAppender [1] supports dynamically setting the destination, thus addressing your requirement. See also the document entitled Triggering an email containing the isolated logs of selected transactions [2] and in particular the section Selective triggering recipient addressing with transaction isolation. HTH, [1] http://logback.qos.ch/manual/appenders.html#SMTPAppender [2] http://logback.qos.ch/recipes/emailPerTransaction.html -- Ceki http://twitter.com/#!/ceki On 07.06.2012 11:08, Zbynek Vavros wrote: Hi, Im using SMTPAppender with MDC to send emails with custom subject and its working very nicely. Now, I would like to specify email receivers according to MDC value, like : MDC=a - 1...@email.com, 2...@email.com MDC=b - 3...@emai..com, 4...@email.com Is it possible via configuration ?? Thanks a lot Zbynek - 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: class specific logging level
If you name your loggers by class name, then sure. This is standard logging configuration, not some extra special workaround. logger name=com.mypackage.Myclass level value=debug/ !-- inherits A1 appender from root, applies only to com.mypackage.MyClass -- /logger logger name=com.myotherpackage level value=debug/ !-- inherits A1 appender from root, applies to all classes in com.myotherpackage -- /logger root level value=error/ appender-ref ref=A1/ /root Jake On Thu, 7 Jun 2012 01:51:07 -0700 (PDT) aggarwal akansha.ag...@gmail.com wrote: Hi, Is it possible to set logging level for few selected classes in appender to DEBUG and rest all ERROR ? Is there any combination of filter that can do this ? -- View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.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: slf4j, log4j and PropertyConfigurator.configure
Do you have multiple copies of log4j.jar in different classloaders? For instance, let's say you run under Tomcat where webapps use child-first classloading. You place log4j and slf4j in WEB-INF/lib and configure Log4j for this classloader. But then you also have log4j/slf4j in a parent classloader which didn't get configured and the code performing logging is also part of the parent classloader, not the webapp classloader. In this case, the no appenders could be found message makes sense. I'm not saying the above is exactly your situation, but possibly some derivation of it. Jake On Wed, 6 Jun 2012 18:26:51 -0400 Jeff Sawatzky jeff.sawat...@locationary.com wrote: I have a project where I am using slf4j with the log4j binder, and I am trying to configure log4j with the PropertyConfigurator. The project allows for a common log4.properties file and a machine log4j.properties file, and at start up I load the two files, combine them into a Properties object, and then pass them to PropertyConfigurator.configure. But when I try to log using slf4j I get a log4j:WARN No appenders could be found for logger error on the class I am trying to log from. In my app startup I have.. Properties props = //do work... LogManager.resetConfiguration(); PropertyConfigurator.configure(props); but here is the output (with log4j.debug turned on) log4j: Parsing for [root] with value=[INFO, stdout]. log4j: Level token is [INFO]. log4j: Category root set to INFO log4j: Parsing appender named stdout. log4j: Parsing layout options for stdout. log4j: Setting property [conversionPattern] to [%-4r [%t] %-5p %c %x - %m%n]. log4j: End of parsing for stdout. log4j: Parsed stdout options. log4j: Finished configuring. log4j: Parsing for [root] with value=[INFO]. log4j: Level token is [INFO]. log4j: Category root set to INFO log4j: Finished configuring. log4j:WARN No appenders could be found for logger (com.loca.util.services.AppListener). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Shouldn't the logger for com.loca.util.services.AppListener use the root appender that was configured? Thanks! - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
Selenium depends upon SLF4J. You may recall that I mentioned SLF4J in a previous email. In appears Selenium includes it's own SLF4J binding. It seems rather silly to me that they would include this as part of their main library rather than as a separate, optional, jar. I suggest you contact the Selenium developers and, possibly, the SLF4J developers to find a solution. In any case, if you are going to have SLF4J in your classpath and want to use Log4j as the implementation, you should include the following in the classpath jcl-over-slf4j.jar slf4j-api.jar slf4j-log4j12.jar log4j.jar And get rid of any, and all, commons-logging jars. The jcl-over-slf4j.jar contains the package/classes of commons-logging, except they are a re-implementation bound to SLF4J. Jake On Wed, 11 Apr 2012 19:55:20 +0200 tomm tommm...@gmail.com wrote: I added/removed jars one by one of course it had to be the last one. When I removed /home/min/ucng/javaLibs/selenium-server-standalone-2.20.0.jar It started to work. However... I need selenium - it's my main browser. So when I added it back SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/home/min/ucng/javaLibs/pbapi-full-1.4.0.91/lib/test/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/home/min/ucng/javaLibs/selenium-server-standalone-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. Exception in thread main java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:99) at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:212) at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:190) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732) at jobManager.UploadManager.main2(UploadManager.java:135) at jobManager.UploadManager.main(UploadManager.java:44) Java Result: 1 And when I removed the extra slf4j as jar:file:/home/min/ucng/javaLibs/pbapi-full-1.4.0.91/lib/test/slf4j-log4j12-1.6.1.jar Then I go back to a project that compiles but doesn't show output of HttpClient logger. Now I am like this @_@ What has some wierd slf4j to commons-logging or log4j. And what it has to do with HttpClient... I am so so so so confused. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
That system property stuff only applies to commons-logging, not Log4j. Look more closely at the instructions [1]. BTW, are you using commons-logging-api.jar? If so, that's the problem. You need commons-logging.jar. See the commons-logging release notes [2]. [1] http://hc.apache.org/httpcomponents-client-ga/logging.html [2] http://commons.apache.org/logging/RELEASE-NOTES.txt Jake On Tue, 10 Apr 2012 12:23:55 +0200 tomm tommm...@gmail.com wrote: From: http://hc.apache.org/httpcomponents-client-ga/logging.html I copy pasted log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n log4j.logger.org.apache.http=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package Didn't work at all. Then I put this in my class: System.setProperty(log4j.rootLogger, INFO, stdout); System.setProperty(log4j.appender.stdout, org.apache.log4j.ConsoleAppender); System.setProperty(log4j.appender.stdout.layout, org.apache.log4j.PatternLayout); System.setProperty(log4j.appender.stdout.layout.ConversionPattern, %5p [%c] %m%n); System.setProperty(log4j.logger.org.apache.http.client, DEBUG); System.setProperty(log4j.logger.org.apache.http, DEBUG); System.setProperty(log4j.logger.org.apache.http.wire, DEBUG); Yet it didn't work at all either. No additional output was produced. How do you make it work? ps: at: http://logging.apache.org/log4j/1.2/manual.html It's not written how to do it (empty paragraph Example Configurations and non empty yet ultimately useless Tomcat paragraph). - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
But I don't want to use commons-logging. I want to use log4j. You are missing the point. **You** want to use Log4j. That's fine. But HttpClient doesn't directly use Log4j. It directly uses commons-logging, which is a Logger adapter that supports various logging implementations, one of which is Log4j. If you want to use Log4j, then you ***have*** to use commons-logging.jar, and NOT commons-logging-api.jar, plus log4j.jar. To avoid commons-logging (and some of the problems it can create), you can skip commons-logging.jar and use SLF4J [1]: jcl-over-slf4j.jar + slf4j-api.jar + slf4j-log4j12.jar + log4j.jar. But either way, you can't avoid having the commons-logging packages/classes (which jcl-over-slf4j.jar mimics) in the classpath because HttpClient has a hard dependency on it. In any case, that System.property stuff didn't help either. Because it's commons-logging specific and totally irrelevant to Log4j. Besides, you were setting Log4j packages as properties and that is totally meaningless. For instance, you wrote... System.setProperty(log4j.logger.org.apache.http.client, DEBUG); But HttpClient's instructions say to do (again, read the instructions more closely)... System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.http.wire, DEBUG); Part of the code simply gets. ignored. Why? Because you are not following instructions. [1] http://slf4j.org/legacy.html#jcl-over-slf4j Jake On Tue, 10 Apr 2012 16:08:07 +0200 tomm tommm...@gmail.com wrote: On 10 April 2012 15:34, Jacob Kjome h...@visi.com wrote: That system property stuff only applies to commons-logging, not Log4j. Look more closely at the instructions [1]. BTW, are you using commons-logging-api.jar? If so, that's the problem. You need commons-logging.jar. See the commons-logging release notes [2]. [1] http://hc.apache.org/**httpcomponents-client-ga/**logging.htmlhttp://hc.apache.org/httpcomponents-client-ga/logging.html [2] http://commons.apache.org/**logging/RELEASE-NOTES.txthttp://commons.apache.org/logging/RELEASE-NOTES.txt Jake But I don't want to use commons-logging. I want to use log4j. In any case, that System.property stuff didn't help either. Part of the code simply gets. ignored. Why? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On Tue, 10 Apr 2012 18:43:21 +0200 tomm tommm...@gmail.com wrote: There is no commons-logging-api.jar in my classpath anywhere. There is commons-logging-1.1.1.jar (there are 2 of them actually). There is only one log4j in my classpath and it is log4j-1.2.16.jar Are the jars binary identical? That is, are they exactly the same size with exactly the same contents? What size are they? 52k would indicate it is the API jar (bad) by another name, 60k would indicate it really is the complete commons-logging.jar (good). Why do you have two of them on the classpath anyway? Are you running on the command line or under an App Server like Tomcat? If under an app server (provide name/version), do you put all your lib dependencies, including log4j.jar and commons-logging.jar, in WEB-INF/lib or elsewhere? If elsewhere, please detail. I highly doubt a problem to be a classpath problem, because then the logger.debug(some test message); would produce nothing, and it works well. That you can log directly to Log4j is good, but is of no consequence as it relates to HttpClient logging. The cause of your issue is almost certainly commons-logging, not Log4j, because HttpClient logs directly to commons-logging. It is the job of commons-logging to direct this logging to Log4j which it is, apparently, failing to do. The reason I need you to verify that you are not, in fact, using the commons-logging API jar is that it has no Log4j binding and, thus, would explain the lack of Log4j output. If you are, indeed, using the complete commons-logging.jar, containing Log4j bindings, then we need to look for other causes. And, BTW, these things are almost **always** classpath/classloading issues. Tom Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On Tue, 10 Apr 2012 19:23:18 +0200 tomm tommm...@gmail.com wrote: System.setProperty(log4j.**logger.org.apache.http.client**, DEBUG); But HttpClient's instructions say to do (again, read the instructions more closely)... System.setProperty(org.**apache.commons.logging.** simplelog.log.org.apache.http.**wire, DEBUG); For the record, you are refering to HttpClient 3.x HttpClient 3.x logging works perfectly for me, straight off the bat. I'm referring to the page you provided which provides instructions, of which the only ones that have anything to do with setting system properties to configure logging are the commons-logging examples [1]. In fact, I see no mention of version 3.x. The page appears to be exclusively for 4.x. If this is wrong, then file a bug with the HttpComponents project. HttpClient 4.x doesn't work at all. And it has different syntax. Just for the sake of it - I used old syntax with new HttpClient - no output generated. What old syntax? The syntax documented on the page? Again, if that's old, then file a bug with HttpComponents. In any case, clearly Log4j generally works for you, since it works when you log directly as well as with HttpClient-3.x. The difference appears to be the HttpClient version. Therefore, I suggest you ask the HttpClient developers. I'm not sure what else to tell you? Tom [1] http://hc.apache.org/httpcomponents-client-ga/logging.html#Commons_Logging_Examples Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
In your other email you say... Running command line. From within NetBeans. No fancy stuff. Never discount the complexity of an IDE and how it forks JVMs and/or performs idiosyncratic classloading. In any case, your test below is invalid in this context. You claimed, in an earlier response, that you load your config manually using... PropertyConfigurator.configure(./src/logging/log4j.properties); The output you see from Log4j, ending with the line... log4j: Could not find resource: [null]. ...just means that Log4j default config lookup didn't find a Log4j config file in the root of the classpath. That's normal if you didn't put it there. But because you manually configure, your config is loaded, so you can ignore the above line. The one odd thing I see is that there is a logger named jobManager that is configured. I don't see that in the log4 config you posted in a previous response (see below). Are you sure the config file that is being loaded is the one you **think** is being loaded? I copy pasted log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n log4j.logger.org.apache.http=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package BTW, why do you configure a properties file from a src folder. Why not just copy that into some folder on the classpath and let Log4j auto-configure. Besides, your methodology of using... PropertyConfigurator.configure(./src/logging/log4j.properties); ...suffers from the fact that this is a file path, relative to the directory from which the JVM started. That is bound to change from environment to environment and, therefore, brittle. Just stick it in the classpath and let Log4j pick it up. Jake On Tue, 10 Apr 2012 21:29:51 +0200 tomm tommm...@gmail.com wrote: My debug for log4j: log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource(). log4j: Could not find resource: [null]. log4j: Parsing for [root] with value=[DEBUG, stdout]. log4j: Level token is [DEBUG]. log4j: Category root set to DEBUG log4j: Parsing appender named stdout. log4j: Parsing layout options for stdout. log4j: Setting property [conversionPattern] to [%5p [%c] %m%n]. log4j: End of parsing for stdout. log4j: Parsed stdout options. log4j: Parsing for [org.apache.http.wire] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category org.apache.http.wire set to DEBUG log4j: Handling log4j.additivity.org.apache.http.wire=[null] log4j: Parsing for [org.apache.http] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category org.apache.http set to DEBUG log4j: Handling log4j.additivity.org.apache.http=[null] log4j: Parsing for [jobManager] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category jobManager set to DEBUG log4j: Handling log4j.additivity.jobManager=[null] log4j: Finished configuring. My output for System.out.println(httpClient.getClass().getClassLoader().getResource(log4j.properties)); is: null It seems the httpClient is not using the logger properties I specified. But I thought that's why there was this line: log4j.logger.org.apache.http=DEBUG in the first place. I am so confused. Any hints? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: LogManager / LoggerRepository
It's not clear what problem you are trying to solve? When you call Logger.getLogger(blah), if blah Logger does not yet exist, it is created. If it does exist it is returned. Loggers are stored in a LoggerRepository. How many logger repositories there are depends upon logger repository implementation behavior and/or classloading behavior as well as where you place log4j.jar in your container's classpath. For instance, if you place log4j.jar in WEB-INF/lib and use child-first classloading (ensuring that WEB-INF/lib/log4j.jar gets used rather than one found in a parent classloader), then you will have on blah Logger for that webapp. If you have another webapp containing log4j.jar and a common library using blah Logger, it will have its own independent instance of blah Logger. So, you will have 2 blah Loggers under the same appserver. Let's say you have the same scenario, except you don't include log4j.jar in WEB-INF/lib, but in some parent classloader available to both webapps. Now you will have a single blah Logger rather than 2. There are more scenarios, but I'll stop there. You might also want to read http://wiki.apache.org/logging-log4j/AppContainerLogging Is that helpful? Jake On Fri, 17 Feb 2012 01:51:16 -0800 (PST) indomie15 suigion.ander...@gmail.com wrote: Hi all, I am using log4j-1.2.8.jar in my application. How do I manage my Logger object? the number of logger object will be created everytime it is access by application. Is there a way to create the logger object one time and subsequently the created logger object will be used by the application? I google search and came across this LoggerRepository and LogManager. How to use these two components? Thank you. Anderson -- View this message in context: http://old.nabble.com/LogManager---LoggerRepository-tp33341582p33341582.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: Programmatically create a ConsoleAppender
Level is the new Priority, just as Logger is the new Category. Try Level.DEBUG. Jake On Mon, 13 Feb 2012 09:31:03 + Edmondo Porcu edmondo.po...@gottexbrokers.com wrote: Dear all, I have a test-case where I want to add extra logging compared to my normal logging settings. I have therefore create manually an appender, and add that to a logger. However, PRIORITY.DEBUG is deprecated. I am probably missing some information about how to add extra logging: private final val mockRealTimeLogger= Logger.getLogger(MockRealTimeConnectorLogger) mockRealTimeLogger.setLevel(Level.DEBUG) val appender = new ConsoleAppender(new PatternLayout(%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n)); appender.setThreshold(Priority.DEBUG) mockRealTimeLogger.addAppender(appender) Isn't this good? Thank you very much Edmondo Porcu Associate - Financial software architect Avenue de Rhodanie 48 1007 Lausanne Switzerland. Dir +41 (0) 21 560 30 82 Fax +41 (0) 21 617 71 55 Email : edmondo.po...@gottexbrokers.com The information in this email is confidential and may be legally privileged. If you are not the intended recipient, you must not read, use or disseminate the information. Although this email and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by the Gottex Group of Companies for any loss or damage arising in any way from its use. - 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: Programmatically create a ConsoleAppender
Did you try compiling and it failed? That would be odd. Level is a Priority [1], so setThreshold(Priority) should accept a Level. [1] http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/Level.html Jake On Mon, 13 Feb 2012 19:14:22 + Edmondo Porcu edmondo.po...@gottexbrokers.com wrote: But I can't pass Level.DEBUG to appender.setThreshold...right? Best Regards Edmondo Edmondo Porcu Financial software architect Avenue de Rhodanie 48 1007 Lausanne Switzerland. Dir +41 (0) 21 560 30 82 Fax +41 (0) 21 617 71 55 Email : edmondo.po...@gottexbrokers.com The information in this email is confidential and may be legally privileged. If you are not the intended recipient, you must not read, use or disseminate the information. Although this email and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by the Gottex Group of Companies for any loss or damage arising in any way from its use. -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: lunedì, febbraio 13, 2012 6:32 PM To: Log4J Users List Subject: Re: Programmatically create a ConsoleAppender Level is the new Priority, just as Logger is the new Category. Try Level.DEBUG. Jake On Mon, 13 Feb 2012 09:31:03 + Edmondo Porcu edmondo.po...@gottexbrokers.com wrote: Dear all, I have a test-case where I want to add extra logging compared to my normal logging settings. I have therefore create manually an appender, and add that to a logger. However, PRIORITY.DEBUG is deprecated. I am probably missing some information about how to add extra logging: private final val mockRealTimeLogger= Logger.getLogger(MockRealTimeConnectorLogger) mockRealTimeLogger.setLevel(Level.DEBUG) val appender = new ConsoleAppender(new PatternLayout(%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n)); appender.setThreshold(Priority.DEBUG) mockRealTimeLogger.addAppender(appender) Isn't this good? Thank you very much Edmondo Porcu Associate - Financial software architect Avenue de Rhodanie 48 1007 Lausanne Switzerland. Dir +41 (0) 21 560 30 82 Fax +41 (0) 21 617 71 55 Email : edmondo.po...@gottexbrokers.com The information in this email is confidential and may be legally privileged. If you are not the intended recipient, you must not read, use or disseminate the information. Although this email and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by the Gottex Group of Companies for any loss or damage arising in any way from its use. - 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 __ This email has been scanned by the Symantec Email Security.cloud service. For more information please visit http://www.symanteccloud.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: SMTPAppender Problems
I suggest you run with log4j debugging, which you can set in the config file or using -Dlog4j.debug=true on the command line. Also, it seems odd to define two logger/ entries with the same name org.tabbysplace.sso. I'm not sure what Log4j will do with this? I can see the appenders being additive, so that both cas and severe appenders are defined for that logger, but since Level can only be one thing at a time, it's either going to be INFO or FATAL. I'm guessing it's FATAL and you aren't actually logging any fatal events (which should be rare), which would explain the lack of logging. Try defining the logger once and use a low level (like DEBUG or INFO) that you are absolutely sure will get triggered in your code. Once you witness logging, then you can ramp up the Level so you aren't drowned in logging during normal usage of the app. Jake On Sat, 28 Jan 2012 15:27:32 -0500 Jonathan Rosenberg j...@tabbysplace.org wrote: I am trying to set up logging via email. Here is the relevant parts of my log4j.xml appender name='severe' class='org.apache.log4j.net.SMTPAppender' param name='SMTPDebug' value='true' / param name='To' value='x...@tabbysplace.org' / param name='From' value='x...@tabbysplace.org' / param name='SMTPHost' value='tabbysplace.org' / param name='SMTPPort' value='25' / param name='SMTPUsername' value='x...@tabbysplace.org' / param name='SMTPPassword' value=',XX' / param name='Subject' value='CAS Sever Error' / param name='bufferSize' value='1' / layout class='org.apache.log4j.PatternLayout' param name=ConversionPattern value='%d{[ dd.MM. HH:mm:ss.SSS]} [%t] %n%-5p %n%c %n%C %n %x %n %m%n' / /layout filter class=org.apache.log4j.varia.LevelRangeFilter param name=LevelMin value=error / param name=LevelMax value=fatal / /filter /appender logger name='org.tabbysplace.sso' additivity='true' level value='FATAL' / appender-ref ref='severe' / /logger logger name='org.tabbysplace.sso' additivity='true' level value='INFO' / appender-ref ref='cas' / /logger Things were not working so I added the debugging flag. I ran a bunch of tests. I see the console output, but except for 1 case (out of dozens), there was no SMTP activity. I then timed adding my own EvaluatorClass to see what was going on: param name='EvaluatorClass' value='org.tabbysplace.casServer.Evaluator' / This class writes to the console and tehn returns true. The class is never called. It's as if the SMTPappender is heing ignored. Any ideas? -- Jonathan Rosenberg Founder Executive Director Tabby's Place, a Cat Sanctuary http://www.tabbysplace.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
Re: log4j in two different project
On Thu, 12 Jan 2012 10:13:20 -0500 Anjib Mulepati anji...@hotmail.com wrote: Hi Is there any help I can get in this? * Are you log4j.properties files for each project identical? o No * the config file for you webapp doesn't provide the configuration you require for your DAO o How to do this? What does this mean? Because your DAO project (jar file) runs within the context of your webaapp and Log4j provides only a single configuration context per webapp (assuming Log4j.jar is deployed in WEB-INF/lib and you are using child-first classloading), then you need your config file to encompass the configuration for all applicable libraries. In this sense, you shouldn't think of your DAO project as something separate from the webapp. It's really a library dependency of the webapp, making it, for all intents and purposes, part of a single application. * is the DAO project deployed in WEB-INF/lib o What does this mean? how I can check? I presume your DAO project is represented as a jar file, no? If you use it as part of your webapp, then it must a library dependency of the webapp. If it is a library dependency of your webapp, then you normally deploy this in WEB-INF/lib. I'll leave it at that. Jake Thanks, Anjib On 1/9/2012 4:37 PM, Jacob Kjome wrote: Are you log4j.properties files for each project identical? My guess is that they are different and the config file for you webapp doesn't provide the configuration you require for your DAO. BTW, is the DAO project deployed in WEB-INF/lib? That is, is it part of the same classloader as the webapp. That could be an issue as well if it is not. Jake On Mon, 9 Jan 2012 12:24:19 -0500 Anjib Mulepati anji...@hotmail.com wrote: I have two different projects a) One for my DAO and b) Another for my web application. Web application uses the DAO jar file to handle all DAO operations. In both project I have configured the log4j.properties (lo4j-1.2.14) file and using commons-logging 1.1.1. When I run test code independently in DAO project I can see the log but when I try to see the log for DAO by running my application DAO logs are not generated I can only see the logs from my web application. What I am doing wrong? - 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
Re: Log4J DailyrollingFileAppender Issue
Are both applications run within the same JVM, or do you start up a separate JVM for the second application? If the latter, then no, it's not supported. You should point to a separate file location. This has more to do with the JVM than Log4j, though. That said, I think it's possible to do using NIO. Search the email list for discussion of NIO and FileAppenders. Jake On Mon, 9 Jan 2012 00:31:57 -0800 (PST) indomie15 suigion.ander...@gmail.com wrote: Hi All, I have two programs that will run concurrently to write logs into the same log file. I am using log4j-1.2.16.jar and place log4j.xml inside my application .jar file. The two programs will write logs into the file for 5 minutes and I am using DailyRollingFileAppender to rolled the log files every minutes. The problem is the log file is not rolled over and encounter error message failed to rename the file Why is it so? But when I run one program only, everything is fine. Does Log4j's DailyRollingFileAppender does not support more than one application that run simultaneosly to log file into same destination? Thank you. :D -- View this message in context: http://old.nabble.com/Log4J-DailyrollingFileAppender-Issue-tp33105755p33105755.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 in two different project
Are you log4j.properties files for each project identical? My guess is that they are different and the config file for you webapp doesn't provide the configuration you require for your DAO. BTW, is the DAO project deployed in WEB-INF/lib? That is, is it part of the same classloader as the webapp. That could be an issue as well if it is not. Jake On Mon, 9 Jan 2012 12:24:19 -0500 Anjib Mulepati anji...@hotmail.com wrote: I have two different projects a) One for my DAO and b) Another for my web application. Web application uses the DAO jar file to handle all DAO operations. In both project I have configured the log4j.properties (lo4j-1.2.14) file and using commons-logging 1.1.1. When I run test code independently in DAO project I can see the log but when I try to see the log for DAO by running my application DAO logs are not generated I can only see the logs from my web application. What I am doing wrong? - 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: org.apache.log4j.MDC vs. org.slf4j.MDC
Hi Steve, Your question really should be directed to the SLF4J mailing list [1], as Log4j already provides what you need. Your question deals with why doesn't SLF4J provide what Log4j provides, which the Log4j team cannot authoritatively answer. [1] http://slf4j.org/mailing-lists.html Jake On Tue, 01 Nov 2011 22:04:24 -0500 Steve Cohen sco...@javactivity.org wrote: I haven't used MDC's in awhile but today I thought I saw a way to put them to advantage for an application I'm working on. In doing so, though ,I stumbled upon an incompatibility between log4j's MDC and slf4j's MDC that I've not seen much comment on. The signatures for the get() and put() methods in the two MDC classes are incompatible. In log4j, it's public static Object get(String key) and public static void put(String key, Object o) while in slf4j (and logback), it's public static String get(String key) throws IllegalArgumentException and public static void put(String key, String val) throws IllegalArgumentException I'm not concerned about the exceptions as much as I am about the restriction to Strings. It so happens that the use case I came up with today much prefers objects to Strings as things to put on an MDC. Admittedly, my use case is a bit non-standard. Basically I want to defer to append-time in the case of one appender the decision as to whether to emit or not emit a log message. We are interfacing to a legacy system and want to use a JMS Queue Appender to send messages to the server for this legacy system. This system uses its own system of bitmapped filters to control output and we have to use it. We'd like to restrict logging to this appender, whereas, possibly not restrict it in the case of other optional local appenders on the client side, by this method. The way I hit upon to do that was to defer the go/no-go decision to the appender in the case of the JMS Queue appender. But to do that I need to put non-Strings on the MDC. Converting these longs to and from a String seems like a somewhat heavy penalty to pay just to be able to use slf4j instead of log4j which I'd much prefer to do otherwise. With non-Strings in the MDC, I just OR two longs together at the appender and abort the log. I suppose I could just or them together at logging time and store true or false in the MDC which only the JMS appender would look at. That's probably the best thing to do. But why was the ability to store non-Strings removed between log4j and slf4j in the first place? - 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 sample example with EAR application
I haven't used JBOSS in ages, so I have no specific instructions for you. But, ultimately, this is just a classloading question. Please consult your JBOSS classloading documentation. If you want a single instance of Log4j to be used across all applications, then you need to place the log4j jar and config in a location where it can be seen by all apps in a parent classloader. Jake On Mon, 17 Oct 2011 02:22:22 -0700 (PDT) shaikbaji.forums shaikbaji.for...@gmail.com wrote: Hi Jake, Thanks for your kind information. I am using JBOSS as server and I am using JBOSS Studio 2.0 as an IDE. Could you please send me any sample EAR application with log4j? Regards, Baji Shaik Jacob Kjome wrote: What server? If Weblogic, try placing log4j.jar in the EAR's APP-INF/lib and the config in APP-INF/classes. You won't need to place log4j in each webapp. Jake On 9/30/2011 8:12 AM, shaikbaji.forums wrote: Hi, I have designed a EAR project, It contains few EJB projects and one WEB project. I want to use the same log file across all the sub projects in that EAR so can you please send me any sample application which is same as my requirement. I just tried like as follow: 1)I have copied the same log4j.properties file in every EJB and WEB project SRC folder. 2)I have added the depended log4j.jar files to EAR and have given reference to the EJB projects. 3)I have copied the log4j.jar to WEB-INF/lib folder of my WEB project. When I am running my application, It's logging only my WEB project logs, It's not logging my EJB project logs. Kindly help me out. Thanks in advance!!! Regards, Baji - 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-sample-example-with-EAR-application-tp32569225p32665592.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 and Tomcat with multiple instances
Here's what I do, which is a bit different from the Tomcat instructions. I pretty much ignore #5 in their instructions 1. Modify $CATALINA_BASE/conf/catalina.properties. Change the single line... common.loader=${catalina.home}/lib,${catalina.home}/lib/*.jar ...to... common.loader=${catalina.base}/shared,${catalina.base}/shared/*.jar,${catalina.home}/shared,${catalina.home}/shared/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar I usually also modify $CATALINA_HOME/catalina.properties with the following, but you can skip this step if you never run Tomcat without using a separate CATALINA_BASE... common.loader=${catalina.home}/shared,${catalina.home}/shared/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar 2. Place log4j.jar and log4j.properties in ${catalina.home}/shared (create the directory if it doesn't exist). You can always override this per/instance by placing log4j.properties in ${catalina.base}/shared, but the default one will always be there and all instances can share log4j.jar from $CATALINA_HOME. Make sure log4j.properties references ${catalina.base} (as in Tomcat's' documentation) instead of ${catalina.home}. 3. Replace $CATALINA_HOME/bin/tomcat-juli.jar with tomcat-juli.jar from extras and put tomcat-juli-adapters.jar from extras into $CATALINA_HOME/lib or $CATALINA_HOME/shared That's about it. Hope I didn't miss anything. I'm kind of doing this from memory. Jake On Thu, 13 Oct 2011 16:49:31 +0200 Peter Magnusson pet.magnus...@gmail.com wrote: Hi, I have a problem with log4j. Im to set up log4j with tomcat and a basic setup works fine. Our setup is that we have multiple instances of Tomcat running on different ports with different $CATALINA_BASE but the same $CATALINA_HOME, we set this up to be able to start and stop applications independent from each other. If i set everything up as described here http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j (disregard #5) it works fine, only problem is that all instances of tomcat log to the same file. This is not what i want, i want each instance of tomcat to log to its own logfile. So i changed my setup accordning to #5 here http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j , but i cannot get this to work at all. Its not logging anything when its setup like this. First of all, is what im trying to achieve even possible ? If so, any idea what im doing wrong ? How can i troubleshoot this ? Any ideas are most welcome, thank you! Best regards Peter - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J not generating DEBUG messages
Ahh Yes, I didn't notice you had a threshold of INFO in your ConsoleAppender. Simply remove that. I don't see the point of it given the rest of your configuration. Jake On Wed, 14 Sep 2011 21:59:19 -0400 Konduru, Geetha geetha_kond...@medco.com wrote: Following may work... appender name=console class=org.apache.log4j.ConsoleAppender param name=Threshold value=DEBUG/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{dd/MMM/ HH:mm:ss.} %m%n/ /layout /appender -Original Message- From: Néstor Boscán [mailto:nestor.bos...@tcs.com.ve] Sent: Wednesday, September 14, 2011 6:25 PM To: Log4J Users List Subject: Re: Log4J not generating DEBUG messages That was an example. My original package is something like ve.com.company.app. That's whats inside package and my class is inside that package. Regards, Néstor Boscán On Wed, Sep 14, 2011 at 5:36 PM, Jacob Kjome h...@visi.com wrote: package is an odd logger name. How do you name your logger(s)? You stated the following in your original message: ...so that the classes in my package What package? A package named package? Name the logger after the actual package name, such as com.mycompany, rather than the likely non-existent package package and you will get the results you expect. Jake On Wed, 14 Sep 2011 16:44:21 -0430 Néstor Boscán nestor.bos...@tcs.com.ve wrote: This is the 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/http://jakarta.apache.org/log4j/ debug=false appender name=console class=org.apache.log4j.**ConsoleAppender param name=Threshold value=INFO/ layout class=org.apache.log4j.**PatternLayout param name=ConversionPattern value=%d{dd/MMM/ HH:mm:ss.} %m%n/ /layout /appender logger name=package additivity=false level value=all/ appender-ref ref=console/ /logger root level value=error/ appender-ref ref=console/ /root /log4j:configuration Regards, Néstor Boscán On Wed, Sep 14, 2011 at 10:37 AM, Konduru, Geetha geetha_kond...@medco.com**wrote: Would you please send the configuration... -Original Message- From: Néstor Boscán [mailto:nestor.bos...@tcs.com.**venestor.bos...@tcs.com.ve ] Sent: Wednesday, September 14, 2011 11:06 AM To: log4j-user@logging.apache.org Subject: Log4J not generating DEBUG messages Hi I have a log4j.xml file configured so that the classes in my package should generate ALL messages: When I create a simple test class and log info, warn and error it works but all debug messages are not generated. Any ideas? Regards, Néstor Boscán ** This e-mail message and any attachments contain confidential information from Medco. If you are not the intended recipient, you are hereby notified that disclosure, printing, copying, distribution, or the taking of any action in reliance on the contents of this electronic information is strictly prohibited. If you have received this e-mail message in error, please immediately notify the sender by reply message and then delete the electronic message and any attachments. --**--** - To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.orglog4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.**apache.orglog4j-user-h...@logging.apache.org --**--**- To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.orglog4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.**apache.orglog4j-user-h...@logging.apache.org ** This e-mail message and any attachments contain confidential information from Medco. If you are not the intended recipient, you are hereby notified that disclosure, printing, copying, distribution, or the taking of any action in reliance on the contents of this electronic information is strictly prohibited. If you have received this e-mail message in error, please immediately notify the sender by reply message and then delete the electronic message and any attachments. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user
Re: Log messages in multithreaded applications
See PatternLayout javadoc [1]. In any case, I think getLogger(Class) just creates confusion. It was added as a convenience because of the way most people name their loggers, using the package/class hierarchy. But really a logger name is just a string and getLogger(String) would have been sufficient (using getClass().getName()) and less confusing as it would have made clear to users that package/class is only one approach to naming loggers, not the only one. [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html Jake On 9/4/2011 2:53 AM, Antonio Rodriges wrote: Hello, In multithreaded applications I got messages like 2011-09-04/01:50:22.515/PDT [AwtEventQueue-1] INFO Received: message Thus, private final Logger LOG = Logger.getLogger(this.getClass()); this.getClass() does not really make sense? How to enable log4j more specific what class makes the message in multithreaded applications? Also, is there any way to log automatically the name of a method? Thank you - 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: Changing Level of Logging during runtime
There used to be a nice open source, Struts-based, Log4j configuration app out there, but it seems to have disappeared. There's a simple one in the Log4j-sandbox you can try... http://svn.apache.org/repos/asf/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/servlet/ConfigurationServlet.java Note that I specifically point to the tag LOG4J_SANDBOX_ALPHA3 because later tags were based on the now defunct Log4j-1.3 codebase and the trunk, I believe, continues to be based on the said defunct codebase. Jake On 9/2/2011 2:58 AM, Amitabh78 wrote: Hi, I want to change the level og logging during runtime. The change in level should be in immediate effect i.e. when admin changes the level og logging from Debug to Info through UI Screen, the logging at debug level should be stopped immediately. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: log4j is not printing in specified path
Run the app with -Dlog4j.debug=true This will make Log4j print out how it is configuring itself. Often times it turns out that it's picking up some other config file than the one you assume it should be picking up. Jake On Mon, 1 Aug 2011 13:16:28 -0700 (PDT) Sivaks sivakumar.subbura...@verizonwireless.com wrote: Hi, I am trying to log info statements using log4j. I have included log4j.xml (refer attachment). static Logger logger = Logger.getLogger(Example.class); logger.info( Test page1); After running the application, if i look at the specified path, I dont see any files which i mentioned in log4j.xml. Let me know if you need any clarification. Any help appreciated http://old.nabble.com/file/p32172797/log4j.xml log4j.xml Regards, Siva -- View this message in context: http://old.nabble.com/log4j-is-not-printing-in-specified-path-tp32172797p32172797.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: AW: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage
But in this case we're viewing a previously/currently written log4j file, hence the parsing. If you use a socket appender you can have Chainsaw capture the actual message events, just as you suggest. However, that may not be possible, nor even desirable, in many cases. I'm sure Scott Deboy can tell you more. Jake On 7/26/2011 12:49 AM, Stadelmann Josef wrote: Are you saying you write a parser for log file entries? Hmm. Why not taking log4j sources and find the point where you can catch the message events, the real objects and massage this objects. I say that because you say: Everything is displayed under Message column. Getting access to the Message Event objects would allow you to check certain fields and then access much better what you may call part of the message column content. So the question be allowed; why parsin? What do you like to parse, find, filter out? And yes. Unless you have a clear idea about how your real-messages must be structured it is even hard to write a working parser. Josef -Ursprüngliche Nachricht- Von: Ding, Qin [mailto:qin.d...@jpmchase.com] Gesendet: Montag, 25. Juli 2011 17:28 An: Log4J Users List Betreff: RE: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage Thank you Scott. It works for the local log file. Everything is displayed under Message column. I guess I need to try the different format to see how to parse the log file correctly. One reason it does not parse correctly is that the log entries are not always consistent. Once in a while there is a plain text entry shown up. I will try sftp again soon. Once again, thank you. QD -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Thursday, July 21, 2011 5:04 PM To: Log4J Users List Subject: Re: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage Here you go.. 1. start chainsaw 2. Choose the file, load chainsaw configuration menu item 3. When the dialog opens, choose the 'process a log file' option 4. Click the 'open file' button and choose the local file you'd like to process, or manually enter the sftp:// URL you want to use (I'd first try with a local file just to make sure it works, but once it is working, you can just change this to your sftp URL). 5. Leave Log file format type as 'LogFilePatternReceiver LogFormat' 6. Click the down arrow next to the Log file format drop down and choose 'MESSAGE' (it will put the entire log line in the 'message' field but you won't have issues with mismatched log entries, so we will see events come in to a tab). 7.don't worry about Log file timestamp format, since you don't have TIMESTAMP field defined in your log format 8. Click 'save configuration as' and browse to where you want to save it and give it a name (I just entered 'c:\new-logfile-receiver-config.xml' in the box) 9. Click the 'always start chainsaw with this configuration button' 10. Press ok Events should show up in a new tab, the tab name being the name of the log file you chose to process. If you open the receiver panel you should see a receiver whose name is the log file you chose to process. Here is the contents of 'new-logfile-receiver-config.xml' after I did this (it did create a tab for me, and I have a receiver defined) ?xml version=1.0 encoding=UTF-8? log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=true plugin class=org.apache.log4j.chainsaw.vfs.VFSLogFilePatternReceiver name=/C:/andyRILog.txt param name=appendNonMatches value=true/ param name=autoReconnect value=true/ param name=fileURL value=file:/C:/andyRILog.txt/ param name=logFormat value=MESSAGE/ param name=name value=/C:/andyRILog.txt/ param name=promptForUserInfo value=false/ param name=tailing value=true/ param name=timestampFormat value=-MM-dd HH:mm:ss,SSS/ param name=waitMillis value=2000/ /plugin /log4j:configuration Again, if you are going to try sftp after this, change promptForUserInfo to true and change your fileURL. You can play with the logFormat and timestampFormat once you have it working as well. This worked for me out of the box with the developer snapshot you downloaded from http://people.apache.org/~sdeboy Scott On Thu, Jul 21, 2011 at 2:51 PM, Ding, Qin qin.d...@jpmchase.com wrote: Scott: 1. I manually downloaded mylog.log; and define a logfilePatternReceiver within chainsaw. Pointing to mylog.log. after that, it just sits there, I see nothing. The last entry in the detail panel: setValueAt, 2, 1, value=file:///C:\MyDocs\logs\mylog.log, valueClassclass java.lang.String 2. I copied the provided configuration file and modified the VFSLogFilePatternReceiver and put it in a folder. Use the instruction you gave me to load it. But on the receiver panel I did not see anything. Manually define a VFSLogFilePatternReceiver. Don't see the GUI prompt for
Re: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage
The file isn't going to be loaded, nor written to, using an invalid URL with backslashes in it. Use all forward slashes. You have... file:///C:\MyDocs\logs\mylog.log It should be file:///C:/MyDocs/logs/mylog.log Or, simply... file:/C:/MyDocs/logs/mylog.log Jake On Thu, 21 Jul 2011 17:51:26 -0400 Ding, Qin qin.d...@jpmchase.com wrote: Scott: 1. I manually downloaded mylog.log; and define a logfilePatternReceiver within chainsaw. Pointing to mylog.log. after that, it just sits there, I see nothing. The last entry in the detail panel: setValueAt, 2, 1, value=file:///C:\MyDocs\logs\mylog.log, valueClassclass java.lang.String 2. I copied the provided configuration file and modified the VFSLogFilePatternReceiver and put it in a folder. Use the instruction you gave me to load it. But on the receiver panel I did not see anything. Manually define a VFSLogFilePatternReceiver. Don't see the GUI prompt for id/pwd. Would you please give me a detailed the instruction or your working sample configuration file? Thank you QD -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Thursday, July 21, 2011 1:36 PM To: Log4J Users List Subject: Re: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage Chainsaw settings are stored in $userhome/.chainsaw - in that folder has a chainsaw-settings.xml file that is used to store application-wide preferences. Here is how you can get the 'configurationURL' field to be set in that file via the GUI: Use the file-load Chainsaw configuration menu option, then select 'use a chainsaw config file' and browse to it, then check the 'always start chainsaw with this configuration' check box. Scott On Thu, Jul 21, 2011 at 11:29 AM, Ding, Qin qin.d...@jpmchase.com wrote: Scott, I already tried by removing the id/pwd and then set true to the promptforuserinfo. However, I don't see the GUI. After restarting the app, I still don't see the GUI. I think this issue might be related to the following problem: How does the app pick up receiver config file in my case log4j.xml? Yesterday, I have a log4j.xml file defined and placed it in the chainsaw folder. Today, after I download the new chainsaw and started the app, I didn't tell the app where to look for the log4j.xml, but it seems find it from the location (old chainsaw) I defined yesterday. I redefined a new log4j.xml and place it under the new chainsaw folder. In application-wide preference, I remove the old log4j.xml and use the new log4j.xml. After I restarted the app, the log4j.xml in use is still the old one. I will remove the old the application including the log4j.xml. QD -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Thursday, July 21, 2011 1:14 PM To: Log4J Users List Subject: Re: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage Try this: set promptforuserinfo to 'true' and take your username and password out of the sftp URL. You will get a GUI username/password prompt..maybe something with special characters in your password? ?xml version=1.0 encoding=UTF-8? log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=true plugin class=org.apache.log4j. chainsaw.vfs.VFSLogFilePatternReceiver name=sftp param name=appendNonMatches value=true/ param name=autoReconnect value=true/ param name=fileURL value=sftp://192.168.1.144/pathhere/log.txt http://username:userpass@192.168.1.144/pathhere/log.txt / param name=logFormat value=TIMESTAMP PROP(OUTERLEVEL) PROP(OUTERLOGGER)- * [THREAD] LEVEL LOGGER - MESSAGE/ param name=name value=sftp/ param name=promptForUserInfo value=true/ param name=tailing value=true/ param name=timestampFormat value=MMdd HH:mm:ss.SSS/ param name=waitMillis value=2000/ /plugin /log4j:configuration Scott On Thu, Jul 21, 2011 at 10:58 AM, Ding, Qin qin.d...@jpmchase.com wrote: Thank you, Scott. but I get use FileZilla sftp SSH File Transfer Protocol to get file. Use I guess I have to view the static file manually downloaded. Thank you very much. QD -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Thursday, July 21, 2011 11:36 AM To: Log4J Users List Subject: Re: Help Log4j Chainsaw - VFSLogFilePatternReceiver Usage If you are still having problems, the issue may be with your server. VFSLogFilePatternReceiver uses Jakarta Commons VFS, which uses the JSch library to support the 'sftp' protocol. According to their website, this is: *SSH File Transfer Protocol(version 0, 1, 2, 3) *I'd suggest verifying your server actually supports SFTP. It may support ssh connections but not support the SSH File Transfer Protocol. Scott On Thu, Jul 21, 2011 at 9:13 AM, Scott Deboy scott.de...@gmail.com wrote: Here is a configuration I just used to retrieve a log file from my Mac using the latest developer snapshot of Chainsaw V2 running on Vista. I don't
Re: How do I hook in before log4j starts?
Of course the quick fix is to manually set the log4j.defaultInitOverride property in code prior to calling LogManager.setRepositorySelector(rs,guard) using... System.setProperty(log4j.defaultInitOverride, true); That way, you don't have to depend on a user setting it. Jake On Tue, 19 Jul 2011 14:58:49 -0500 Turner, Jay jay.tur...@sabre-holdings.com wrote: I don't know how to submit a bug or a patch. I think the design just needs a little ... flexibility. Keep everything the same but provide an entry point or two that set things before configuring. The entire static block probably needs to be a method that is guarded and invoked once. Then a few static method can set things before the other static methods check the guard and configure when needed. I'll look at it and anyone feel free to take a stab at it too. Thank you, Jay Turner -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Tuesday, July 19, 2011 2:22 PM To: Log4J Users List Subject: Re: How do I hook in before log4j starts? That sounds like a bug that should be fixed. Mind submitting a bug? If you want to provide a patch we'd be happy to review it. Thanks Scott On Tue, Jul 19, 2011 at 12:18 PM, Turner, Jay jay.tur...@sabre-holdings.com wrote: I can do some lazy initialization, but there is still a basic problem. Looking at the source code for LogManager, I find that it has a static block of code. This static block will run as I try to do anything with LogManager. I can get it down to LogManager.setRepositorySelector(rs,guard) without trigerring the static block in LogManager. The mere call to setRepositorySelector runs the static block first, which runs code that calls OptionConverter.selectAndConfigure(...) unless log4j.defaultInitOverride is set. So there is no way to prepare log4j before it initializes unless the user is kind enough to set log4j.defaultInitOverride or define log4j.configuratorClass. Both of these require the user - instead of the library handling the logging on behalf of the user - to setup the environment correctly and without conflicting with any other application. Thank you, Jay Turner -Original Message- From: Scott Deboy [mailto:scott.de...@gmail.com] Sent: Monday, July 18, 2011 5:47 PM To: Log4J Users List Subject: Re: How do I hook in before log4j starts? Can you lazily initialize the ref to the root logger in your LoggerRepositoryHandler instead of passing it in to the constructor? It seems like that should resolve your problem. Scott On Mon, Jul 18, 2011 at 3:02 PM, Turner, Jay Jay.Turner@sabre-holdin gs.comwrote: The inherited code did have some public static final org.apache.log4j.Logger ... calls, thank you. Changing those allowed my code to be called first. However a Catch-22 still exists. Trying: private static final Object guard = new Object(); private static final LoggerRepositoryHandler handler = setupLoggerRepositoryHandler(); private static LoggerRepositoryHandler setupLoggerRepositoryHandler() { LoggerRepositoryHandler handle = new LoggerRepositoryHandler(org.apache.log4j.LogManager.getLoggerRepository().getRootLogger()); org.apache.log4j.LogManager.setRepositorySelector(new RepositorySelector() { public LoggerRepository getLoggerRepository() { return handler; }}, guard ); return handle; } This gets called first, but the org.apache.log4j.LogManager.getLoggerRepository() call to link my repository with the default repository invokes the log4j setup, which completes and uses the default repository before my new repository (with the parseUnrecognizedElement method) is setup. If I set the selector first then when I call getLoggerRepository() it will go through my selector which has no default repository setup. I can't get ahold of the log4j system to link in my parseUnrecognizedElement method first without letting log4j setup everything first. How has anyone every hooked parseUnrecognizedElement into log4j before it starts up? I just need to process multiple non-logger/appender-specific myKey=myValue parameters like this: ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; debug=true param name=myKey value=myValue/ Thank you, Jay Turner From: Scott Deboy ... more likely a static logger declaration or a logger instance be initialized prior to your configuration code being ran. - 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: append user details with exception stacktrace
Can you restate the question? It's not clear to me what you are trying to do, which is likely why you haven't received an answer. Jake On Thu, 14 Jul 2011 07:47:45 -0700 (PDT) fachhoch fachh...@gmail.com wrote: any help please ? I want to modify the message which log4j is going to log , please help me fachhoch wrote: can I add additional information when log4j logs exceptions ?, my root logger logs all errors , can I add a new line to the exception stacktrace ie user details which is in threadlocal , is there any customization I can do before message is logged to logs ? -- View this message in context: http://old.nabble.com/append-user-details--with-exception-stacktrace-tp32048303p32061804.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: configuring individually loggingf for every war application in an ear project
If the webapps are configured to use child-first, or parent-last, classloading and log4j.jar is in WEB-INF/lib and log4j.xml is in WEB-INF/classes (or you specify the config path yourself using the Spring configuration utility), then logging should be separated. Shared libraries located outside of WEB-INF/lib (such as in APP-INF/lib under Weblogic) can be problematic since they'll have dependency on Log4j and won't be able to reference it under each webapp's WEB-INF/lib. The other option is a repository selector, but that entails some more complication. There's documentation for it in the logging-log4j wiki [1]. You may still end up with problems when shared libraries log using static loggers, though, since they will be tied to the configuration of the first app that accesses them. [1] http://wiki.apache.org/logging-log4j/AppContainerLogging Jake On Tue, 21 Jun 2011 18:03:20 +0300 Melih U. Ünsal melihun...@gmail.com wrote: My ear project consists of two war applications. i want to create logs individually for every war. i mean every war projects must create its own logs. But, because of they run in the same jvm, i am not sure whether it is possible or not. how can i handle this issue? By the way, the war applications are spring projects. i created two log4j config files (log4j_app1.xml and log4j_app2.xml) and instantiated them in the applicationcontexts but it did not solve the problem. WAR_APP1 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app1.xml/value /list /property /bean WAR_APP2 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app2.xml/value /list /property /bean log4j_app1.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app1/app1.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender/ appender-ref ref=console/ /root /log4j:configuration log4j_app2.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender_ui class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app2/app2.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console_ui class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender_ui/ appender-ref ref=console_ui/ /root /log4j:configuration - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Getting Could not find root logger information but I don't see why
Is that a literal path? ...\my.ear\my.war\WEB-INF/log4j.xml First, it's invalid since it has 3 periods, rather than 1 or 2. Second, your slashes are inconsistent. If you want to be agnostic to the OS, just always use forward slashes (/), which will work under both Unix and Windows in Java. Third, when using relative paths, the path is going to be relative to the directory from which the JVM started. So, let's say this is... ${weblogic.home}/server/bin Log4j would be looking for your file in ${weblogic.home}/server/my.ear/my.war/WEB-INF/log4j.xml ...which is almost certainly incorrect. Also, keep in mind that because you are not [likely] using a logger repository selector, you will be using the default logger repository unless you are using child-first, or parent-last, classloading. If you want per/webapp logger configuration, this is a must. Otherwise, you might as well place log4j.xml in the server's classpath. And if you aren't doing anything special regarding setting runtime properties for you configuration to use, then it is rather pointless to use a custom Log4j init servlet. Just place log4j.xml in WEB-INF/classes and be done. Log4j will automatically pick this up and use it. Jake On Thu, 26 May 2011 01:27:42 + KARR, DAVID (ATTSI) dk0...@att.com wrote: Using log4j 1.2.16 in WebLogic 10.3.2. While my app is starting up, I'm seeing the following message: Log4JInitServlet is initializing log4j Initializing log4j with: ...\my.ear\my.war\WEB-INF/log4j.xml log4j: Could not find root logger information. Is this OK? This is the log4j.xml file it's reading: - ?xml version=1.0 encoding=UTF-8 ? !DOCTYPE log4j:configuration SYSTEM http://jakarta.apache.org/log4j.dtd; log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' appender name=consoleAppender class=org.apache.log4j.ConsoleAppender layout class=org.apache.log4j.TTCCLayout/ /appender logger name=org.springframework additivity=false level value=warn/ appender-ref ref=consoleAppender/ /logger logger name=org.apache.cxf additivity=false level value=warn/ appender-ref ref=consoleAppender/ /logger root priority value =warn / appender-ref ref=consoleAppender/ /root /log4j:configuration - I don't see anything wrong with this. - 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: Relative path of file appender
Yes. It will be relative to the directory from which the JVM started from. Jake On Thu, 26 May 2011 17:32:00 +0100 Jiafan Zhou zhoujia...@gmail.com wrote: The following log4j.properties uses a relative path for redirected file. Is it valid? log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=./output.log log4j.appender.file.MaxFileSize=10MB log4j.appender.file.MaxBackupIndex=5 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: using of system properties in subject of SMTPAppender
You might be interested in the it.openutils.log4j.AlternateSMTPAppender [1]. It allows for dynamic subjects and more. Note that I am not affiliated with this project. I just found it to be useful. [1] http://www.openmindlab.com/lab/tools/openutilslog4j/smtp.html Jake On Mon, 23 May 2011 16:18:20 +0200 Zbynek Vavros zbynek_vav...@cz.ibm.com wrote: Hi, I have a 1 server app and many clients app on different servers. Obviously I wanted to know from which server the email comes, so I used this: log4j.xml appender name=email class=org.apache.log4j.net.SMTPAppender param name=BufferSize value=512 / param name=SMTPHost value=my_smtp_host / param name=From value=AutoBot / param name=To value=my_em...@someserver.com / param name=Subject value=Agent on [${HOSTNAME}] has encountered error / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{HH:mm:ss} [%t] %p %C (%L) %x - %m%n / /layout filter class=org.apache.log4j.varia.LevelRangeFilter param name=LevelMin value=error / param name=LevelMax value=fatal / /filter /appender and since system property has to be setup before configuring log4j, I use this in my code. Main class //create system property to hold server name System.setProperty(HOSTNAME, InetAddress.getLocalHost ().getCanonicalHostName()); //reconfigure log4j so it picks up HOSTNAME property DOMConfigurator.configure(getClass().getClassLoader().getResource( log4j.xml)); Then Im receiving emails with subject like this: Agent on [127.0.0.1] has encountered error. So far so good. And now I have request to include customer name in subject. I have no problem to include it in stack trace, but since I cannot set customer name the same way as I did with IP (there are multiple customers handled by my app so I cannot just use System.setProperty(CUSTOMER, SOME NAME)). I though of solution to set this property when exception is catched and reconfigure log4j after setting proper customer name into system property. But I think it is politelly said ugly. Can some1 suggest a better way maybe? Thanks, Zbynek Kind Regards / Mit freundlichen Grüßen / Üdvözlettel / S pozdravem: Zbynek VAVROS (Embedded Development image moved to file: pic20342.gif) Delivery Centre 616 00, Brno Central Europe Technicka 21 Brno SITE Czech Republic (Embedded image moved to file: pic17964.gif)Phone: 420-53341- x6283 Mobile: E-mail: zbynek_vav...@cz.ibm.com IBM Global Services Delivery Center Czech Republic, s.r.o. Registered address: Brno, Technicka 2995/21, Zip code: 61600, Company ID: 26244535 Entered in the Commercial Register maintained by the Regional Court in Brno (Part C, Entry 39922) IBM Global Services Delivery Center
Re: Getting Could not find root logger information but I don't see why
Due to some other constraints, I appear to be forced to have my log4j.jar at both the EAR and WAR classpath level. In my WebLogic config, I'm doing everything I can to make it prefer the jars in the webapp. If you are using Weblogic 9.2+, then you may be able to use a FilteringClassLoader [1], so that application library contents of the EAR file are loaded in preference to those from the server classpath. In META-INF/weblogic-application.xml you'd add the following prefer-application-packages package-nameorg.apache.log4j.*/package-name /prefer-application-packages You'd simply make sure to place log4j.jar in the EAR's APP-INF/lib or add it as a manifest Class-Path entry in the EAR's manifest.mf. Note that I haven't verified whether this actually achieves per/app logging configuration. Maybe you can try it out and report results? [1] http://download.oracle.com/docs/cd/E13222_01/wls/docs92/programming/classloading.html#wp1097187 Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: log4j on WebSphere Application Server
You can reference Java system properties using the syntaxt ${somePropertyName}, e.g., log4j.appender.A1.File=${log.dir}/stdout.log You can set Java system properties on the command line using... java -Dlog.dir=/path/to/log/directory Jake On 4/1/2011 1:10 PM, nulll wrote: Hi, I configured my logging with log4j.properties file using a FileAppender. When I do my local development, I use Tomcat under Windows. When deploying on managed-environments (sys, acc, prod), I use WebSphere under Linux. Since my various environment use dedicated file structure, I'd like to know how I can set a log file location which is dynamic. I would actually want to have my log4j logging written into a file in the same folder as SystemOut.log. I defined a LOG_ROOT WebSphere variable but I don't think it's accessible to LOG4J. I made some research on the Internet but still didn't find any way to do that. Any help is appreciated. Thanks! - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Why There isn't a Log File?
You can use an XML config file just fine under Tomcat (with caveats... see below). I see two issues with your current XML config, though 1. The doctype should be... !DOCTYPE log4j:configuration SYSTEM log4j.dtd 2. The path in... param name=File value=c:\myproj\myapp\logs\mylog.log / ...should be either... param name=File value=c:\\myproj\\myapp\\logs\\mylog.log / ...or... param name=File value=c:/myproj/myapp/logs/mylog.log / I mentioned a caveat above about using XML config files in Tomcat. By that, I mean using it specifically for Tomcat logging, not just general application logging. You can, unless you choose to reference Tomcat loggers named using square brackets, as they are disallowed by the DTD. For instance, to reference Tomcat's localhost logger, you'd use... org.apache.catalina.core.ContainerBase.[Catalina].[localhost] Using XML, it would be... logger name=org.apache.catalina.core.ContainerBase.[Catalina].[localhost] additivity=false level value=INFO/ appender-ref ref=LOCALHOST/ /logger But the name doesn't attribute doesn't allow square brackets and the config file fails DTD validation because the name attribute is defined as type ID. That said, I think there might be a workaround. If you use the deprecated category rather than logger it might work because, for the former, the name attribute is of type CDATA rather than ID. So, all you'd have to do is use... category name=org.apache.catalina.core.ContainerBase.[Catalina].[localhost] additivity=false level value=INFO/ appender-ref ref=LOCALHOST/ /category Try that and see if it works. Jake On 3/30/2011 11:15 AM, Cindy Wong wrote: To answer my own question, according to Tomcat document, the problem is with TC. I need to use the property configuration file format instead. I have used log4j before with the property file configuration. For this new project, I have the XML configuration. The console output seems to be fine. Any changes on log level and layout will reflect on log messages on the console right away. I, however, can't get any log file for some reasons. To my understanding, to use a log file, I need to use the log4j-user-subscr...@logging.apache.org class and what is the name is important. The followings are the xml configuration and the dtd. Can someone tell me what is wrong? ?xml version=1.0 encoding=UTF-8? !-- !DOCTYPE log4j:configuration PUBLIC -//LOGGER log4j.dtd -- !DOCTYPE log4j:configuration PUBLIC -//log4j/log4j Configuration//EN log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; !-- log4j:configuration debug=true -- !-- Appenders -- appender name=console class=org.apache.log4j.ConsoleAppender param name=Target value=System.out / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%-5p: %c{1}:%L - %m%n / /layout /appender appender name=file class=org.apache.log4j.RollingFileAppender param name=maxFileSize value=100KB / param name=maxBackupIndex value=5 / param name=File value=c:\myproj\myapp\logs\mylog.log / param name=Append value=true / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d %-5p [%t] %C{2} (%F:%L) - %m%n/ /layout /appender !-- Application Loggers -- logger name=com.mycom.myapp level value=debug / /logger !-- 3rdparty Loggers -- ... !-- Root Logger -- root priority value=warn / appender-ref ref=console / /root /log4j:configuration ?xml version=1.0 encoding=UTF-8 ? !-- A configuration element consists of optional renderer elements,appender elements, categories and an optional root element. -- !ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?, categoryFactory?) !-- The threshold attribute takes a level value such that all -- !-- logging statements with a level equal or below this value are -- !-- disabled. -- !-- Setting the debug enable the printing of internal log4j logging -- !-- statements. -- !-- By default, debug attribute is null, meaning that we not do touch -- !-- internal log4j logging settings. The null value for the threshold -- !-- attribute can be misleading. The threshold field of a repository -- !-- cannot be set to null. The null value for the threshold attribute -- !-- simply means don't touch the threshold field, the threshold field -- !-- keeps its old value. -- !ATTLIST log4j:configuration xmlns:log4j CDATA #FIXED http://jakarta.apache.org/log4j/; threshold(all|debug|info|warn|error|fatal|off|null) null debug
Re: Log4j debug for one method in application
You could set it to debug for a specific class logger without issue, no? Wouldn't you be using that same logger for all methods in the class anyway? Otherwise, create multiple logger named after the class and method and enable debug for the one you care about. Jake On 3/28/2011 1:46 PM, log4jlog4j wrote: Hi, Just want to check can we set debug for any specific method in the applciation using log4j. This will be very useful if we have this feature in log4j so trying to check on this. I have a application running on production and to check on one very complicated issue want to check if we can set debug for any specific method. Due to volume and performance we dont want to do debug at applciation level on production and we are not able to reproduce that on our test environment. - 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
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 org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement
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
-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
logger name=special.example.com additivity=false level value=INFO/ appender-ref ref=STDERR/ /logger Jake On Wed, 23 Feb 2011 17:34:26 -0500 Mikhail T. mi+t...@aldan.algebra.com wrote: Hello! I'm trying to create a log4j.xml file, that would send all messages from certain special classes into one location and everything else into another: logger name=special.example.com level value=INFO/ appender-ref ref=STDERR/ /logger root level value=DEBUG/ appender-ref ref=SERVERLOG/ /root Unfortunately, when I use root, ALL messages get logged into the second location (SERVERLOG) -- including those from the special classes -- the special messages appear in both locations, instead of ONLY in the STDERR. How can I fix it without explicitly listing all other classes? Thanks! Yours, -mi - 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: Setting properties for log4j.xml configuration file
You're right, I did miss something. I didn't see log4j.logdir being set within the file in the original example. Sorry about that. Your original answer appears to be right on the money. Jake On Mon, 21 Feb 2011 22:54:31 -0600 Curt Arnold carn...@apache.org wrote: I read the question as how do I define parameters once in an XML configuration file and the use of system properties was just a convenient way of doing that in property file configurations. The property file example included setting log4j.logdir in the file and I'm not aware of any capability in XML configuration files to set system properties. If the property was already set externally, then you could use the same type of expressions as in the example. On Feb 21, 2011, at 8:05 PM, Jacob Kjome wrote: Curt, Maybe I'm missing something, but how does using XML entity refs do anything for referencing Java system properties? The simple answer is that Log4j XML config files support exactly the same syntax as properties files, e.g., param name=File value=${log4j.logdir}/MyAppender1.log/ I don't recall whether/where it's specifically documented or not, but it works. Jake On 2/20/2011 10:30 PM, Curt Arnold wrote: XML entity references can be used for that purpose and are defined in the XML Recommendation (http://www.w3.org/TR/xml/#sec-references). !DOCTYPE log4j:configuration [ !ENTITY logdir c:/data/logfiles ] log4j:configuration ... param name=file value=logdir;/ ... /log4j:configuration On Feb 20, 2011, at 6:35 AM, Thomas Wiedmann wrote: Hello, usually in flat plain text log4j.config files global system properties can be defined, which may be referenced in the configuration of different appenders, e. g. log4j.logdir=C:/Data/logfiles ... log4j.appender.MyAppender1.File=${log4j.logdir}/MyAppender1.log ... log4j.appender.MyAppender2.File=${log4j.logdir}/MyAppender2.log I found this is a very convenient way to define (and to administer) such parameters only once globally for the entire log configuration and to use it on several references as here in the appenders configuration. How can such global system properties be defined in xml-based configuration files (log4j.xml)? Where is it documented? I'd found no hint about it. Thomas Wiedmann - 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 - 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: Setting properties for log4j.xml configuration file
Curt, Maybe I'm missing something, but how does using XML entity refs do anything for referencing Java system properties? The simple answer is that Log4j XML config files support exactly the same syntax as properties files, e.g., param name=File value=${log4j.logdir}/MyAppender1.log/ I don't recall whether/where it's specifically documented or not, but it works. Jake On 2/20/2011 10:30 PM, Curt Arnold wrote: XML entity references can be used for that purpose and are defined in the XML Recommendation (http://www.w3.org/TR/xml/#sec-references). !DOCTYPE log4j:configuration [ !ENTITY logdir c:/data/logfiles ] log4j:configuration ... param name=file value=logdir;/ ... /log4j:configuration On Feb 20, 2011, at 6:35 AM, Thomas Wiedmann wrote: Hello, usually in flat plain text log4j.config files global system properties can be defined, which may be referenced in the configuration of different appenders, e. g. log4j.logdir=C:/Data/logfiles ... log4j.appender.MyAppender1.File=${log4j.logdir}/MyAppender1.log ... log4j.appender.MyAppender2.File=${log4j.logdir}/MyAppender2.log I found this is a very convenient way to define (and to administer) such parameters only once globally for the entire log configuration and to use it on several references as here in the appenders configuration. How can such global system properties be defined in xml-based configuration files (log4j.xml)? Where is it documented? I'd found no hint about it. Thomas Wiedmann - 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
Re: FileAppender problem
I suggest using a ServletContextLister and calling LogManager.shutdown() when your webapp is stopped. http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/LogManager.html#shutdown%28%29 http://stackoverflow.com/questions/839255/how-do-i-properly-log4j-closing-all-appenders-and-therefore-files Jake On Tue, 15 Feb 2011 10:06:57 +0530 Umesh Awasthi umeshawas...@gmail.com wrote: Josef, Thanks for the help.i able to solve the problem and here is the casue of the problem'. since i was creating fileappender instance appender = new FileAppender(layout, sb.toString(), false); inside the constructor of my class and i was of impression that log4j is responsible for closing the appender which in my case was not happening at all. so after looking in to the FileAppender source code i got the hint since in the code they tried to close the appender but code was indicating that there may be some cases where appender might still be open and my problem was in this section,so after doing my work i simply closed the appender and it solved the whole issue. still i am not sure how tomcat was keeping refrence of all the appender created by the code since i was cleaning up my code and was making all refrences null. any one have idea,please do share On Mon, Feb 14, 2011 at 11:23 PM, Stadelmann Josef josef.stadelm...@axa-winterthur.ch wrote: In case you have conflicts, it is a good Idea to consolidate all different log4j.properties into one big log4j.properties and have that used when TOMCAT starts. This just fior a test. If then all runs, then your problems may be that of a access conflict; i.e. trying to open a file or a channel which is already open. It helped for me in many case. Josef -Ursprüngliche Nachricht- Von: Umesh Awasthi [mailto:umeshawas...@gmail.com] Gesendet: Montag, 14. Februar 2011 15:35 An: log4j-user Betreff: Re: FileAppender problem Hi All, Can any one help me in this,it seems the my tomcat server keeping a refrence of all fileappender On Sat, Feb 12, 2011 at 11:22 AM, Umesh Awasthi umeshawas...@gmail.com wrote: Hi All, I am working on a webapplication and i have a requirment to generate log files at run time for my impex process.here is the use case i am validating an XML file and validation error is being handled by custom Error handler.This error hanlde will be passed to the underlying validator (Jaxb 2.x validator),so i have to create the log file when the instance of this error hanlder is being created. here is the code to create log file at run time FileAppender appender; try { appender = new FileAppender(layout, sb.toString(), false); log.addAppender(appender); log.setAdditivity(false); log.setLevel(Level.WARN); } catch (IOException e) { e.printStackTrace(); } everything is working fine and file is being created correctly as well being written by the logger to the respective place. but if i restart my server real problem starts and logger starting appending the log content not only to its pareent class as well other classes.here is the details lets suppose i have 3 log (A,B,C) files already at the location with 3 lines in each log file and C was the latest file created in the process. so when i restart my server it some how appending data in to previos all log files in this fashin C has still 3 lines B has now 6 lines A has now 9 lines it seems that the appender i hace created is still open or have refrence not sure what exactly going on. any help in this regard will be helpfull. -- With Regards Umesh Awasthi http://www.travellingrants.com/ -- With Regards Umesh Awasthi http://www.travellingrants.com/ - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org -- With Regards Umesh Awasthi http://www.travellingrants.com/ - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Get the following error: NoClassDefFoundError: org.apache.log4j.Logger
I presume you are running using something like?... java -jar myapp.jar Correct? Note that if you try to add -classpath as a command line switch while using the -jar command line switch, it will be ignored. In this case, you'll have to update your MANIFEST.MF file to include the Log4j library in the Class-Path. Otherwise, just run without the -jar switch and the -classpath info will no longer be ignored. Jake On Wed, 2 Feb 2011 10:21:13 + (GMT) henry human henry_hu...@yahoo.de wrote: Hi I get the following error when I try to call a smal java application(hello friends!) which i placed in a jar file. the application has the log4j.jar in its lib directory (and classpath) and calls the log4j.logger like this: private static final Logger LOGGER = Logger.getLogger(Hello.class); It works when i run the application in eclipse but not when I pack it as a JAR application! (he application is not running on tomcat an is only a smal commandline application) Error: Exception in thread main java.lang.NoClassDefFoundError: org/apache/log4j/Logger Thanks for your advice - 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 to log to different files for each JVM instance
Use placeholders in the config file and set system properties on the command line starting the JVM process. Jake On 12/29/2010 11:19 PM, lalpop kumar wrote: how can I configure log4j to log to different files for each JVM instance in the same host? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: set the placeholder in the log4j.properties file
Log4j will attempt to auto-configure itself by looking for log4j.xml and then log4j.properties in the root of the claspath upon the first call to getLogger(). And yes, this may very well be before your init servlet runs. Note that the new configuration (done manually in the init servlet) will have things configured as you want them. There is a solution. You can set system properties -Dapppath=/my/logging/directory And, optionally -Dlog4j.configuration=file:///path/to/log4j.properties That said, you could just place a minimal config file in the classpath pointing all logging to the Console and then let your init servlet configure the preferred config file as you are doing. I guess it all depends on how important it is for you to get all logging to your preferred file, even logging that occurs prior to your init servlet running. Jake On 12/27/2010 12:26 AM, maven apache wrote: Hi: I want the logs created by log4j put under the app dir,so I set the placeholder in the log4j.properties: # chartstdout is set to be a ConsoleAppender. log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x - %m%n log4j.appender.chartfileout=org.apache.log4j.FileAppender log4j.appender.chartfileout.File=${apppath}/logs/log.html log4j.appender.chartfileout.Append=true log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout log4j.rootLogger=debug, chartstdout,chartfileout Then in my servlet whose load-on-startup attribute is 0 I set the property apppath,but it does not work. It seems that the log4j read the log4j.properties and config the log before I modify the property. public void init() { DbManager.init(); // log String context = getServletConfig().getServletContext().getRealPath(/); Properties p = new Properties(); p.setProperty(apppath, context); try { p.load(InitServlet.class.getResourceAsStream(/log4j.properties)); } catch (IOException e) { e.printStackTrace(); } PropertyConfigurator.configure(p); } Of course,I can rename the log4j.properties,then the log4j will not find the file but I can. However some other libs which I used in my appliction require log4j also,they need the log4j.properties to generate there logs. Any ideas? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: performance problem in multithread environment
You will get better performance by not logging at all, no question. However, there are tuning possibilities. I see you mention logger.info(). In production, I generally only have warn() and above for the vast majority of loggers. In fact, I configure the root logger up with the WARN level and selectively set other loggers to something less than WARN (if need be). The other thing you might look at is whether you are concatenating strings in your logging statements. For instance the following will incur an unnecessary cost in concatenating strings even when the DEBUG level is not enabled logger.debug(product: + someProduct + , price: + somePrice); A more efficient way to define this in your code is if (logger.isDebugEnabled()) { logger.debug(product: + someProduct + , price: + somePrice); } In this case, you will only incur the cost of a simple boolean check when DEBUG is disabled. Note that this is unnecessary if you are not concatenating, as isDebugEnabled() is called internally to the debug() method prior to sending your message to the appender anway. Avoiding concatenation altogether in your logging statements is generally recommended, but really doesn't hurt much if you are only doing it for trace(), debug(), or info() statements that are surrounded by is[Level]Enabled() and you only have WARN and above enabled in production. So, when you are profiling, you must take into account how your loggers perform logging in the code as well as the configuration you are using. Simply saying that logging is super costly without taking these issues into account is not useful. Feel free to post more specifics, especially if you feel you truly are taking these issues into account and are still getting ridiculously bad performance while using Log4j. Jake On Mon, 13 Dec 2010 09:54:04 +0800 betterjo...@hotmail.com wrote: I need your help!!! Please help me ,thanks. 2010-12-13 2010-12-11 01:52:03 Log4J Users List Re: Re: performance problem in multithread environment hi, through jprofiler I found that many thread are blocked at logger.info(message).I saw that each logger.info() call will cost 2,200 us,the application are running at a machine which has one phyical cpu(64 virtual cpu),1.5Ghz,32G memory,solaris 10. If I comment all logger message(means no logging message),the application performance will be faster more than ten times. If I crate new logger instance for each log message,the application performance will be faster more than four times. Could tell me the difference between category and logger. Api shows that logger extends category,logger.info() just is category.info()。 The code show that synchronization is by category,but code category = this,shows that at this time category just is logger. BTW: In my application,when process one order,it will log about 700 messages. With log,application will process three orders one second,But without log,application will process 40 orders one second. Is there any mistakes by using log4j?need more config? thanks. 2010-12-11 Sebastien Tardif 2010-12-11 01:10:40 log4j-user Re: performance problem in multithread environment The code show that synchronization is by category. If appendLoopOnAppenders is faster, like if the underline code use asynchronous appender, that should not be a problem. So you should investigate what the thread having the lock is doing. - 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 with multiple files converting to xml
I suggest that you take a crack at the configuration yourself. If you still have questions, post it and we can help you tweak it. Jake On Wed, 8 Dec 2010 08:16:44 -0800 (PST) Refr Bruhl refr_br...@yahoo.com wrote: Greetings I tried searching for this on the mail archives link, the link seems to be changed. My goal: I have 4 files for logging. ConLogger - logs to console, lgLogger - logs to a log file, qryLogger that logs to a log file, delLogger that logs to a log file, and exLogger that logs to a log file lgLogger logs generall aplication activity. I have used addAppender to ensure everything logged to the console is also logged to lgLogger qryLogger logs nothing but query information exLogger logs all exception errors All 4 of these files can support debug thru fatal entries. I have used this same pattern in several batch type jobs for about 4 years now. These files are configured in the primary java class. What I want to do is change the configuration from hard coding these log files in the app to using xml files for configuration. The problem I am running into is it seems when using xml or property files log4j makes the assumption of only one logger with multiple appenders per xml file. I want or think I want 4 distinct loggers with each having a separate appender. Is this correct? Has anyone else tried to do something similar with log4j? Any idea on how to achieve this? Thanks! --Refr inn gra Wars are to be won with swords and spears, not with rice and salt. -- Uesugi Kenshin - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4j with multiple files converting to xml
You can configure your entire logging system via a single config file. You are not limited to one logger/appender per config file. Besides, children of the the logger inherit from the parent, by default, so when you configure a given logger, e.g., the root logger, that same config applies to all children (unless you set additivity to false at some point in the hierarchy). I assure you, there is no need for multiple config files. The manual [1] shows examples of properties config files. The wiki [2] provides examples of XML config files. And any search engine will provide lots of extra resources showing how to write Log4j config files. Please read these resources and take a crack at the config. Feel free to post your config if you have more questions. [1] http://logging.apache.org/log4j/1.2/manual.html [2] http://wiki.apache.org/logging-log4j/Log4jXmlFormat Jake On Wed, 8 Dec 2010 09:35:28 -0800 (PST) Refr Bruhl refr_br...@yahoo.com wrote: Well been doing that already. Lets start with the basics What is the syntax for configuring multiple loggers using an xml file? If I use log4j.xml or log4j.properties I can configure one logger with code straight from a tutorial... org.apache.log4j.Logger conLogger = Logger.getLogger(BaseConfig.class); Using this as a model I would think I would want org.apache.log4j.Logger qryLogger = Logger.getLogger(BaseConfig.class); org.apache.log4j.Logger lgLogger = Logger.getLogger(BaseConfig.class); org.apache.log4j.Logger exLogger = Logger.getLogger(BaseConfig.class); Yet if I use this construct, even if I set loggers in the xml file, the last defined file will write console output to its log. So it seems to me that instead of basing a logger on a class, I need to base a logger on a unique xml file. I can use URL url = Loader.getResource(conLogger.xml); DOMConfigurator.configure(url); again from the same tutorial.. but it only works with 1 xml file. So if I am limited to 1 xml file how do I configure separate loggers and appenders in 1 xml file or is there a way I can have 4 separate xml files with a unique logger and appender for each? --Refr inn gra Wars are to be won with swords and spears, not with rice and salt. -- Uesugi Kenshin From: Jacob Kjome h...@visi.com To: Log4J Users List log4j-user@logging.apache.org Sent: Wed, December 8, 2010 11:12:08 AM Subject: Re: Log4j with multiple files converting to xml I suggest that you take a crack at the configuration yourself. If you still have questions, post it and we can help you tweak it. Jake On Wed, 8 Dec 2010 08:16:44 -0800 (PST) Refr Bruhl refr_br...@yahoo.com wrote: Greetings I tried searching for this on the mail archives link, the link seems to be changed. My goal: I have 4 files for logging. ConLogger - logs to console, lgLogger - logs to a log file, qryLogger that logs to a log file, delLogger that logs to a log file, and exLogger that logs to a log file lgLogger logs generall aplication activity. I have used addAppender to ensure everything logged to the console is also logged to lgLogger qryLogger logs nothing but query information exLogger logs all exception errors All 4 of these files can support debug thru fatal entries. I have used this same pattern in several batch type jobs for about 4 years now. These files are configured in the primary java class. What I want to do is change the configuration from hard coding these log files in the app to using xml files for configuration. The problem I am running into is it seems when using xml or property files log4j makes the assumption of only one logger with multiple appenders per xml file. I want or think I want 4 distinct loggers with each having a separate appender. Is this correct? Has anyone else tried to do something similar with log4j? Any idea on how to achieve this? Thanks! --Refr inn gra Wars are to be won with swords and spears, not with rice and salt. -- Uesugi Kenshin - 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: Extra RollingFileAppender with NLOG4j
NLog4j is not an Apache Logging project. It's a fork of Log4j hosted outside of Apache Logging. Please try with an official Log4j version and respond back if you run into issues. Jake On Wed, 3 Nov 2010 11:55:29 -0400 kenneth@barclayscapital.com wrote: I'm trying to get the RollingFileAppender from the extra log4j companion file working but I'm having problems configuring the appender. I am using this with the most current version of NLOG4J The following is my config file: ?xml version=1.0 encoding=UTF-8 ? !DOCTYPE log4j:configuration SYSTEM log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=console class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%-5p %c{1} - %m%n/ /layout /appender appender name=logFileAppender class=org.apache.log4j.rolling.RollingFileAppender rollingPolicy class=org.apache.log4j.rolling.TimeBasedRollingPolicy param name=FileNamePattern value=/log/metrics.%d{-MM-dd-HH}.log / /rollingPolicy layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%m%n / /layout /appender !-- -- !-- Loggers -- !-- -- logger name=com.barcap.eq.common.metric.LoggingMetric additivity=false level value=INFO / appender-ref ref=console / appender-ref ref=logFileAppender / /logger root priority value =debug / appender-ref ref=console / /root /log4j:configuration At startup, I get the following errors: log4j:ERROR Element type rollingPolicy must be declared. log4j:ERROR The content of element type appender must match (errorHandler?,param*,layout?,filter*,appender-ref*). If I attempt to write to the appender, I then get: log4j:WARN Please set a rolling policy for the RollingFileAppender named 'logFileAppender' log4j:ERROR No output stream or file set for the appender named [logFileAppender]. I think the issue is that the rollingPolicy element isn't defined in log4j.dtd but I'm not sure how to proceed with this. Is NLOG4J not compatible with the companion jar? Thanks. ___ This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ___ - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Extending Logger
I would tend to have a minimal log4j.xml containing basic configuration for the root logger, which I usually set to WARN to avoid being bombarded with annoying messages from libraries I don't care about. However, there is no necessity to have a log4j.xml (or log4j.properties). Log4j can be configured via config file or programmatically (or both), but if Log4j can't find any config file, it will say as much in System.err, which I generally try to avoid. All the other stuff can be configured programmatically as Bender suggested. Jake On Tue, 2 Nov 2010 14:46:52 +0100 Bender Heri hben...@ergonomics.ch wrote: I don't know. You have to try if the log4j.xml can be omitted. Heri -Original Message- From: Mohan.Radhakrishnan [mailto:moh...@fss.co.in] Sent: Tuesday, November 02, 2010 2:39 PM To: log4j-user@logging.apache.org Subject: RE: Extending Logger Yes. I am responding to your suggestion. The setup performance is not very important. The runtime performance though is. If I setup everything programmatically log4j.xml is not at all needed ? -- View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113852.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
Re: [SCL-2] Re: Multiple log files, multiple logger names and the same appender
Depends how many individual loggers you are concerned with. If there are, say, 3 named loggers, then just create 3 appenders; one for each logger. However, if the number of logger names cannot be known at build time, then you will probably need a custom appender that you assign to some base logger name. For each logger that sends info to the appender, the appender can evaluate whether to write it to an existing log file or create a new one. Jake On Mon, 18 Oct 2010 00:34:42 -0700 (PDT) Mohan.Radhakrishnan moh...@fss.co.in wrote: Jacob, What you are suggesting can be done using the XML itself ? I think this new appender is required due to the limitation in associating an individual logger with its own file. Thanks, Mohan -- View this message in context: http://old.nabble.com/Multiple-log-files%2C-multiple-logger-names-and-the-same-appender-tp28024737p29988016.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: [SCL-2] Re: Multiple log files, multiple logger names and the same appender
If you have a limited set of loggers you are concerned with, just create a separate appender for each file you want created. So, if you have 5 loggers you care about, just create 5 appenders; each with its own file. Then associate the appropriate appender with the appropriate logger. In that case, there's no need to create a custom appender. Jake On 10/15/2010 7:46 AM, Mohan.Radhakrishnan wrote: My initial idea is to pass multiple file names in the XML in the appender section and maintain a list in the custom appender Java code and then based on the logger name or some other parameter pick the correct file name. Performance is one of our major concerns. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: [SCL-2] Re: Multiple log files, multiple logger names and the same appender
I think for what you want (separate file/logger), you'll need to write a custom appender unless Bender Heri's suggestion suffices for you. Jake On 10/14/2010 3:30 AM, Mohan.Radhakrishnan wrote: Hope to revive this thread. Is there any way to use the feature I have described. 1. Use the logger hierarchy like Heri had suggested. 2. Use a separate logger file for each logger in the hierarchy. Thanks, Mohan - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: RollingFileAppender + TimeBasedRollingPolicy
Not that I can see. I think a FixedWindowRollingPolicy + SizeBasedTriggeringPolicy would do what you need. Of course, it won't roll based on time, but on size. Basically, you'd get a maximum backup of 12 (or less depending on what you configure) archived log files, which is hardly different than deleting old files. That said, you might be able to [ab]use a FilterBasedTriggeringPolicy to trigger rolling based on time (and/or size). Note that I have not tested this myself. It would be interesting to learn of your results. Jake On 10/14/2010 4:50 AM, Corey Scott wrote: Hi there, Is there some param i can set in the log4j.xml to have the TimeBasedRollingPolicy delete old files after x days? Im sorry if this is handled in the doco and Im too stupid to find it :) Cheers, Corey - 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: locating my log4j.properties file
On 10/8/2010 3:37 PM, Don Raikes wrote: Hello again, Ok so I solved some of my issues, but now I have others. In my log4j.properties file, I have configured 3 appenders. A1console apppender A2file appender to my errors.log file A3file appender to my fulltrace log file (see below) When I run the test program using -Dlog4j.debug, I can see that all the appenders are being created no problem. However, nothing is being written to either of my file appenders a2 or a3 even though my console appender (a1) is receiving all the output). Any suggestions on how I have misconfigured things would be appreciated. I don't see any problems at all, other than, likely, a misunderstanding of what is supposed to occur. I see 2 loggers with A2 and A3 appenders attached, respectively log4j.logger.org.apache.log4j.errors=ERROR, A2 log4j.logger.org.apache.log4j.fulltrace=DEBUG, A3 Given that neither of these logger names match up with any package/class you would be using, it makes perfect sense that you'd see no logging output for this. And I'm not sure where you came up with these logger names anyway, other than possibly some documentation relating to the abandoned Log4j-1.3 effort which attempted to use itself for logging. Try the following logger definitions. And note that I set the root logger to WARN rather than DEBUG. That way, annoying debug messages coming from various frameworks like Spring, some of the various apache commons frameworks, etc..., won't unnecessarily pollute your logs. Also, I added Threshold=ERROR to the A2 appender so that it will reject any logging messages lower than ERROR (I didn't know what your package was so I called it org.mypackage. Change as needed.)... log4j.rootLogger=WARN, A1 log4j.logger.org.mypackage=DEBUG, A2, A3 log4j.appender.A2.Threshold=ERROR Jake -- beginning of ma11yMonitor-log4j.properties --- # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the License); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an AS IS BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Attach appender A1 to root. Set root level to Level.DEBUG. log4j.rootLogger=DEBUG, A1 # A1 is set to be a FileAppender sending its output to # System.out. However, only error messages and above will be printed # in A1 because A1's threshold is set to Level.ERROR. # The fact that the root level is set to Prority.DEBUG only influences # log requests made to the root logger. It has no influence on the # *appenders* attached to root. log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) - %m%n # Set the level of the logger named org.apache.log4j.errors to # Level.INFO, attach appender A2. log4j.logger.org.apache.log4j.errors=ERROR, A2 # Appender A2 writes to the file test in user's home. log4j.appender.A2=org.apache.log4j.FileAppender log4j.appender.A2.File=${user.home}/a11yMonitor-errors.log # Truncate 'test' if it aleady exists. log4j.appender.A2.Append=false # Appender A2 uses the PatternLayout. log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n log4j.logger.org.apache.log4j.fulltrace=DEBUG, A3 # Appender A2 writes to the file a11y-fulltrace.log in user's home. log4j.appender.A3=org.apache.log4j.FileAppender log4j.appender.A3.File=${user.home}/a11yMonitor-fulltrace.log # Truncate 'test' if it aleady exists. log4j.appender.A3.Append=false # Appender A3 uses the PatternLayout. log4j.appender.A3.layout=org.apache.log4j.PatternLayout log4j.appender.A3.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n --- end of a11yMonitor-log4j.properties --- --- class constructor --- public class Monitor implements FocusListener, WindowFocusListener { static final Logger logger = Logger.getLogger(Monitor.class); private String log4jPropertiesFile = null; public Monitor() { log4jPropertiesFile = System.getProperty(user.home) + System.getProperty(file.separator) + a11yMonitor-log4j.properties; PropertyConfigurator.configure(log4jPropertiesFile); setupListeners(); logger.info(Loading
Re: locating my log4j.properties file
It's great that you got it working, but it doesn't appear you fully understand why... configure(String) [1] takes a java.io.File path. Given that you have provided a relative path, rather than a fully qualified one, location of the file is going to be relative to the directory from which you started your JVM. In your case, it happens to be the same directory in which your Jar file exists. But you can't depend on this because your JVM may be started from another directory and this relative location may become invalid. And you generally want to avoid the File system anyway in your Java programs to keep them from being coupled to a particular environment setup. For these reasons, I suggest that you use a URL [2] instead and load your config file from the classpath, e.g., URL url = getClass().getClassLoader().getResource(com/mypackage/log4j-config-file.properties); PropertyConfigurator.configure(url); But lets step back for a second. Unless you are doing something special as far as loading the config file, there's no reason you can't rename your config file to log4j.properties. This will get picked up automatically without you having to manually configure Log4j. Just place it in the root package on your classpath and it will get picked up (unless log4j.xml also exists, in which case it will be used in preference to log4j.properties). The other option, which also avoids manual, programmatic, configuration is to set the property log4j.configuration, e.g., Example of a URL on Windows... -Dlog4j.configuration=file:/C:/some/path/to/my/log4j-config-file.properties Example of a URL on UNIX... -Dlog4j.configuration=file:/some/path/to/my/log4j-config-file.properties [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.lang.String%29 [2] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.net.URL%29 Jake On 10/8/2010 9:45 AM, Don Raikes wrote: Christian, Thanks, with the -Dlog4j.debug, I was able to figure out that log4j was looking for a default log4j.xml file which I do not have, but I then copied the a11yMonitor-log4j.properties into the same folder as my test application's jar file and that worked. Getting log4j output now! -Original Message- From: Christian Grobmeier [mailto:grobme...@gmail.com] Sent: Thursday, October 07, 2010 10:40 PM To: Log4J Users List Subject: Re: locating my log4j.properties file Hello start your programm with: -Dlog4j.debug This will show you information were it looks for your properties file. It usually helps me in this case Cheers Christian On Fri, Oct 8, 2010 at 12:39 AM, Don Raikes don.rai...@oracle.com wrote: Hello, I have a java project which I compile and then package in a jar file which goes into my jdk_home\jre\lib\ext folder (it is an extension to my jdk). In the main class of my application I tell log4j to use a specific log4j.properties file PropertyConfigurator.configure(a11yMonitor-log4j.properties); Where do I actually place the a11yMonitor-log4j.properties file? I tried in jdk_home\jre\lib and jdk_home\jre\lib\ext but both times I tried to run my extension, I get a message saying that log4j cannot find the properties file. Any help would be greatly appreciated. -- Sincerely, HYPERLINK http://www.oracle.com; \nOracle Donald Raikes | Accessibility Specialist Phone: HYPERLINK tel:+16028246213+16028246213 | Mobile: HYPERLINK tel:+15202717608+15202717608 | VOIP: HYPERLINK tel:+16028246213+16028246213 Oracle JDeveloper Quality Assurance | Tucson, Arizona HYPERLINK http://www.oracle.com/commitment; \nGreen Oracle Oracle is committed to developing practices and products that help protect the environment - 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
Re: How to use a second log4j.properties file for a special java program?
On Sun, 29 Aug 2010 02:40:43 -0700 (PDT) BenXS bxsto...@yahoo.co.uk wrote: Jacob Kjome wrote: 1. If you deploy your app as a WAR file, then you can utilize child-first classloading. As long as you include log4j.jar in WEB-INF/lib and log4j.properties (or log4j.xml) in WEB-INF/classes, then you will end up using your own config rather than the server's. Ok, thank you. Can I omit the own, second log4j.jar and use only the own,second log4j.properties file? Or is my own, private log4j.properties file not recognized if I do not attach my own log4j.jar ? You need to follow the instructions completely 1. Set your webapp to child-first (otherwise known as parent-last) classloading. This is the default classloading behavior in Tomcat 4/5/6/7 standalone, BTW. You'll have to set it explicitly when using other containers. Check the documentation of the container you are using for further info. 2. Add log4j.jar to WEB-INF/lib 3. Add log4j.properties to WEB-INF/classes Jake Ben -- View this message in context: http://old.nabble.com/How-to-use-a-second-log4j.properties-file-for-a-special-java-program--tp29540603p29564582.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: How to use a second log4j.properties file for a special java program?
2 ways (both assuming you don't want to blow away the configuration for the server, but still use custom configuration for your application) 1. If you deploy your app as a WAR file, then you can utilize child-first classloading. As long as you include log4j.jar in WEB-INF/lib and log4j.properties (or log4j.xml) in WEB-INF/classes, then you will end up using your own config rather than the server's. 2. Use a Repository Selector. For more info, see http://wiki.apache.org/logging-log4j/AppContainerLogging Jake On Thu, 26 Aug 2010 11:49:08 +0200 Ben Stover bxsto...@yahoo.co.uk wrote: Assume a default log4j.properties file is setup for a whole application server. Now I deploy a new, own java program into the application server which contains logging statements like log.info(); as well. Currently the log output go to the default log file defined in the overall log4j.properties file. But I want to use another, different logfile. This should be defined (as far as I can see) in a second log4j.properties file. But how can I access this jog4j.properties file when creating the logger in the java program? Resp. how can I tell the environment to use another log4j.properties file ? Ben - 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: configuring email appending for WARN and above
This is documented in the SMTPAppender Javadoc [1]. log4j.appender.email.EvaluatorClass=com.mypackage.MyCustomTriggeringEventEvaluator ...where the latter class implements TriggeringEventEvaluator [2]. [1] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SMTPAppender.html [2] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/TriggeringEventEvaluator.html Jake On Mon, 16 Aug 2010 12:25:42 -0500 Curtis Garman curt.gar...@gmail.com wrote: Can someone tell if it is possible to configure the smtp email appender to send email for WARN level message and above? I seem to only be able to get ERROR level stuff to come back in email form. log4j.appender.email=org.apache.log4j.net.SMTPAppender log4j.appender.email.SMTPHost=smtp.server log4j.appender.email.SMTPDebug=false log4j.appender.email.bufferSize=1 log4j.appender.email.from=f...@domain.com log4j.appender.email.to...@domain.com log4j.appender.email.subject=subject log4j.appender.email.threshold=WARN log4j.appender.email.layout=org.apache.log4j.PatternLayout log4j.appender.email.layout.ConversionPattern=[%p] %d{ISO8601}%n%n%c:%L%n%n%m%n -- Curtis - 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
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: catalina.out flooded
Well, you have some specific loggers set to INFO and DEBUG. Which loggers are causing the excessive output? I suspect the following definitions... log4j.logger.org.apache=info,ApacheLogs log4j.logger.org.apache.axis=debug,ApacheLogs If you really want all the apache libraries logging at the info level, and the Axis library logging at the debug level (yikes), but you don't want your console log flooded with messages from these loggers, then set additivity to false. log4j.additivity.org.apache=false No need to do this specifically for the Axis logger, as additivity to the root logger will have been cut off at its parent org.apache logger. Jake On 7/28/2010 7:41 PM, Johan Martinez wrote: A webapp is flooding tomcat's catalina.out file and I would like to verify if there is something wrong with my log4j configuration. Below is the configuration I have in WEB-INF/classes/log4j.properties of the webapp. Any suggestions or thoughts on what might be wrong with it?? I suspect logs are getting duplicated in catalina.out and following log4j-defined files, but I am not 100% sure on this (difficult to verify due to large file sizes). Thanks, jM. log4j # Set root category priority to WARN and its only appender to A1. log4j.rootCategory=ERROR, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c{2} [%t,%M:%L] %m%n # Display any warnings generated by our code log4j.category.org.ca=INFO # ApacheLogs Appender log4j.appender.ApacheLogs=org.apache.log4j.DailyRollingFileAppender log4j.appender.ApacheLogs.File=${catalina.home}/logs/apache.log log4j.appender.ApacheLogs.Append=true log4j.appender.ApacheLogs.layout=org.apache.log4j.PatternLayout log4j.appender.ApacheLogs.DatePattern='.'--MM-DD log4j.appender.ApacheLogs.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}%L %m%n # GlobusLogs Appender log4j.appender.GlobusLogs=org.apache.log4j.DailyRollingFileAppender log4j.appender.GlobusLogs.File=${catalina.home}/logs/wsrf.log log4j.appender.GlobusLogs.Append=true log4j.appender.GlobusLogs.layout=org.apache.log4j.PatternLayout log4j.appender.GlobusLogs.DatePattern='.'--MM-DD log4j.appender.GlobusLogs.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}%L %m%n # Define loggers log4j.logger.org.apache=info,ApacheLogs log4j.logger.org.apache.axis=debug,ApacheLogs log4j.category.org.globus=INFO,GlobusLogs log4j.logger.org.globus.wsrf.handlers.MessageLoggingHandler=DEBUG,GlobusLogs /log4j - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation
On Wed, 21 Jul 2010 02:13:21 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Thanks Jake. Yes, I am running server in standalone mode (~/bin/startup.sh) [OS - Linux/Solaris]. No IDE is being used. My application is deployed on tomcat server under ~/webapps/cp/. I couldn't find my application specific pom.xml file, so I did update the one present in log4j.jar. If that is not the correct way to do this, can I use web.xml to define dependency? The instructions presume you are using Maven2 to perform your builds. Apparently that is not the case for you. Modifying pom.xml inside log4j.jar will do you no good (nor harm). It is totally inconsequential to your issue. Whatever build you are using (Ant?), make sure that it places the following 2 jars inside WEB-INF/lib of your WAR file (or directory) ~/webapps/cp/WEB-INF/lib/log4j.jar ~/webapps/cp/WEB-INF/lib/log4j-extras.jar Also, we are using ~/webapps/cp/WEB-INF/etc/log-conf.xml file to add following configuration: !-- Presentation Server Access log appender -- appender name=access-log class=org.apache.log4j.rolling.RollingFileAppender FileWEB-INF/log-files/access.log/File rollingPolicy class=org.apache.log4j.rolling.TimeBasedRollingPolicy FileNamePatternWEB-INF/log-files/access.log.%d{-MM-dd}.log/FileNamePa ttern /rollingPolicy layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{dd.MM. HH:mm:ss,SSS} [%t] %c %x%n %-5p - %m%n/ /layout /appender Like I mentioned before, this configuration looks like it is for Logback. Log4j doesn't support stuff like File and FileNamePattern elements. The link you originally provided gives you the correct configuration info https://wiki.jasig.org/display/UPM30/log4j.xml And that doc points to this doc, which provides the defacto information... http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html What I want is that a new log file should be created in the mid night, and logging should be continued in that file. Old log file should be renamed with access.log.date. Read the above links. They provide all the information you need. Jake Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Tuesday, July 20, 2010 3:21 AM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation On Tue, 20 Jul 2010 00:57:48 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Sorry, Jake. But I think you've missed the server name in my first email. It's Apache Tomcat. *** Tomcat version: apache-tomcat-5.5.27 *** Whoops. I guess I did miss that. That presents a problem, though. Tomcat uses child-first classloading by default, at least when running under the standalone scripts. How are you running it? Are you running it within an IDE or something? Also, I took a closer look at your config. It looks like Logback configuration, not Log4j configuration. See here for config... http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/r olling/RollingFileAppender.html The config at the link you mentioned ( https://wiki.jasig.org/display/UPM30/log4j.xml ) actually looks correct to me, but is different than what you mentioned below. You also mention that you edited the pom.xml file in log4j.jar? That's not he pom file to edit. The pom.xml to edit is your own pom.xml to contain the dependency. Please check the resultant WAR file to ensure that the files you think are supposed to be there actually are there. Jake Thanks for your help. Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Tuesday, July 20, 2010 12:38 AM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation What server do you use? This should be part of your server documentation, but if it's Weblogic I might be able to tell you. But that also depends on the server version. Jake On Tue, 20 Jul 2010 00:00:37 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Dear Jake, Thanks for replying this query. Could you please tell me how to configure the application to use child-first classloading? Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Monday, July 19, 2010 10:54 PM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation My guess is that you have classloading issues. What server are you using? I'll bet it is not configured to use child-first (a.k.a parent-last) classloading and that the server has a copy of log4j.jar in the server classpath. In this situation, the log4j.jar in the server
Re: getting error log4j:ERROR setFile(null,true) on windows
Does the logs directory exist relative to the base directory (i.e., the directory from which the application was started)? I know it was an issue in older Log4j versions that it wouldn't make directories. I'm not sure if this was addressed in later versions or not? But you can avoid this by ensuring that the directory you want the file to exist within already exists prior to application startup. Jake On Tue, 20 Jul 2010 19:28:26 +0530 sasanka pusapati spusapati...@gmail.com wrote: Hi All, I am getting the file not found exception error when running my application using the below properties file . Why is log4j unable to create the logs directory on its own? This problem is seen only on windows , its working fine on linux. Can some one please help me on this. Error : log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: logs\test.log (The system cannot find the path sp ecified) 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:272) at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java :156) at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:151) - -- log4j Properties file invoked using PropertyConfigurator.configure : log4j.rootLogger = debug ,console ,logfile log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{M/dd/yy hh:mm:ss.SSS a z} [%-3p] [%t] [%c] %m%n log4j.appender.logfile=org.apache.log4j.RollingFileAppender log4j.appender.logfile.File=logs/test.log log4j.appender.logfile.MaxFileSize=2048KB log4j.appender.logfile.MaxBackupIndex=3 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d{M/dd/yy hh:mm:ss.SSS a z} [%-3p] [%t] [%c] %m%n --- Thanks in advance, SAS. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation
My guess is that you have classloading issues. What server are you using? I'll bet it is not configured to use child-first (a.k.a parent-last) classloading and that the server has a copy of log4j.jar in the server classpath. In this situation, the log4j.jar in the server classpath would take precedence to any log4j.jar you included in WEB-INF/lib and be unable to find the rolling.RollingFileAppender located in the extras jar stored in WEB-INF/lib. You can resolve this either by placing the extras jar in the server classpath alongside the log4j.jar already there or configure your application to use child-first classloading. Jake On Mon, 19 Jul 2010 22:27:11 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Hi Friends, Tomcat version: apache-tomcat-5.5.27 Operating System: SunOS 10.0 / Linux Problem: I've tried many times to configure apache-log4j-extras-1.0 with apache-log4j-1.2.16, but it is still failing to load classes from configure apache-log4j-extras-1.0 JAR file. What I want to do: Actually I want to do time based log rotation the my application specific log files. I could able to configure using 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, but few problems are reported on Apache site for this class. Solution I can think of: So, I have to look for another option for 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, and I found 'org.apache.log4j.rolling.RollingFileAppender' class and can use 'org.apache.log4j.rolling.TimeBasedRollingPolicy' in that. Steps I performed so far: 1. Downloaded apache-log4j-extras-1.0 with apache-log4j-1.2.16 JAR files from web. 2. Renamed apache-log4j-1.2.16.jar to simple 'log4j.jar'. 3. Copied apache-log4j-extras-1.0.jar in ~/WEB-INF/lib directory, where my old log4j is present. 4. Extracted new log4j.jar (1.2.16). 5. Edited the pom.xml file from new 'log4j.jar' to include 'apache-log4j-extras-1.0'. Steps are described here: ( https://wiki.jasig.org/display/UPM30/log4j.xml https://wiki.jasig.org/display/UPM30/log4j.xml). 6. Created jar file again, after editing pom.xml. 7. Then I added following configuration block, in my application specific log-conf.xml (present in ~/WEB-INF/etc/): !-- Presentation Server Access log appender -- appender name=access-log class=org.apache.log4j.rolling.RollingFileAppender FileWEB-INF/log-files/access.log/File rollingPolicy class=org.apache.log4j.rolling.TimeBasedRollingPolicy FileNamePatternWEB-INF/log-files/access.log.%d{-MM-dd}.log/FileNamePa ttern /rollingPolicy layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{dd.MM. HH:mm:ss,SSS} [%t] %c %x%n %-5p - %m%n/ /layout /appender but, still I am getting following exception: 7202 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse invite request mappings: [The XPath='invite-requests/invite-mapping' does not exist] 7214 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse known profiles request mappings: [The XPath='known-profiles-requests/known-profiles-mapping' does not exist] 8114 [main] ERROR net.cp.ps.sdk.server.ServerConfig - thread[main] Missing configuration: couldn't find value for /ps-conf/regex-whitespace-keyword log4j:ERROR Could not create an Appender. Reported error follows. java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav a:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav a:1232) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.log4j.helpers.Loader.loadClass(Loader.java:160) Can someone please help me with this, what's going wrong and what I am missing here? Thanks in advance. Regards, Saurabh Agrawal - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation
What server do you use? This should be part of your server documentation, but if it's Weblogic I might be able to tell you. But that also depends on the server version. Jake On Tue, 20 Jul 2010 00:00:37 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Dear Jake, Thanks for replying this query. Could you please tell me how to configure the application to use child-first classloading? Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Monday, July 19, 2010 10:54 PM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation My guess is that you have classloading issues. What server are you using? I'll bet it is not configured to use child-first (a.k.a parent-last) classloading and that the server has a copy of log4j.jar in the server classpath. In this situation, the log4j.jar in the server classpath would take precedence to any log4j.jar you included in WEB-INF/lib and be unable to find the rolling.RollingFileAppender located in the extras jar stored in WEB-INF/lib. You can resolve this either by placing the extras jar in the server classpath alongside the log4j.jar already there or configure your application to use child-first classloading. Jake On Mon, 19 Jul 2010 22:27:11 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Hi Friends, Tomcat version: apache-tomcat-5.5.27 Operating System: SunOS 10.0 / Linux Problem: I've tried many times to configure apache-log4j-extras-1.0 with apache-log4j-1.2.16, but it is still failing to load classes from configure apache-log4j-extras-1.0 JAR file. What I want to do: Actually I want to do time based log rotation the my application specific log files. I could able to configure using 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, but few problems are reported on Apache site for this class. Solution I can think of: So, I have to look for another option for 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, and I found 'org.apache.log4j.rolling.RollingFileAppender' class and can use 'org.apache.log4j.rolling.TimeBasedRollingPolicy' in that. Steps I performed so far: 1. Downloaded apache-log4j-extras-1.0 with apache-log4j-1.2.16 JAR files from web. 2. Renamed apache-log4j-1.2.16.jar to simple 'log4j.jar'. 3. Copied apache-log4j-extras-1.0.jar in ~/WEB-INF/lib directory, where my old log4j is present. 4. Extracted new log4j.jar (1.2.16). 5. Edited the pom.xml file from new 'log4j.jar' to include 'apache-log4j-extras-1.0'. Steps are described here: ( https://wiki.jasig.org/display/UPM30/log4j.xml https://wiki.jasig.org/display/UPM30/log4j.xml). 6. Created jar file again, after editing pom.xml. 7. Then I added following configuration block, in my application specific log-conf.xml (present in ~/WEB-INF/etc/): !-- Presentation Server Access log appender -- appender name=access-log class=org.apache.log4j.rolling.RollingFileAppender FileWEB-INF/log-files/access.log/File rollingPolicy class=org.apache.log4j.rolling.TimeBasedRollingPolicy FileNamePatternWEB-INF/log-files/access.log.%d{-MM-dd}.log/File NamePa ttern /rollingPolicy layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{dd.MM. HH:mm:ss,SSS} [%t] %c %x%n %-5p - %m%n/ /layout /appender but, still I am getting following exception: 7202 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse invite request mappings: [The XPath='invite-requests/invite-mapping' does not exist] 7214 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse known profiles request mappings: [The XPath='known-profiles-requests/known-profiles-mapping' does not exist] 8114 [main] ERROR net.cp.ps.sdk.server.ServerConfig - thread[main] Missing configuration: couldn't find value for /ps-conf/regex-whitespace-keyword log4j:ERROR Could not create an Appender. Reported error follows. java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoad er.jav a:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoad er.jav a:1232) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.log4j.helpers.Loader.loadClass(Loader.java:160) Can someone please help me with this, what's going wrong and what I am missing here? Thanks in advance. Regards, Saurabh Agrawal - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation
On Tue, 20 Jul 2010 00:57:48 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Sorry, Jake. But I think you've missed the server name in my first email. It's Apache Tomcat. *** Tomcat version: apache-tomcat-5.5.27 *** Whoops. I guess I did miss that. That presents a problem, though. Tomcat uses child-first classloading by default, at least when running under the standalone scripts. How are you running it? Are you running it within an IDE or something? Also, I took a closer look at your config. It looks like Logback configuration, not Log4j configuration. See here for config... http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html The config at the link you mentioned ( https://wiki.jasig.org/display/UPM30/log4j.xml ) actually looks correct to me, but is different than what you mentioned below. You also mention that you edited the pom.xml file in log4j.jar? That's not he pom file to edit. The pom.xml to edit is your own pom.xml to contain the dependency. Please check the resultant WAR file to ensure that the files you think are supposed to be there actually are there. Jake Thanks for your help. Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Tuesday, July 20, 2010 12:38 AM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation What server do you use? This should be part of your server documentation, but if it's Weblogic I might be able to tell you. But that also depends on the server version. Jake On Tue, 20 Jul 2010 00:00:37 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Dear Jake, Thanks for replying this query. Could you please tell me how to configure the application to use child-first classloading? Regards, Saurabh Agrawal -Original Message- From: Jacob Kjome [mailto:h...@visi.com] Sent: Monday, July 19, 2010 10:54 PM To: Log4J Users List; saurabh.agra...@criticalpath.net Subject: Re: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1 for time based log rotation My guess is that you have classloading issues. What server are you using? I'll bet it is not configured to use child-first (a.k.a parent-last) classloading and that the server has a copy of log4j.jar in the server classpath. In this situation, the log4j.jar in the server classpath would take precedence to any log4j.jar you included in WEB-INF/lib and be unable to find the rolling.RollingFileAppender located in the extras jar stored in WEB-INF/lib. You can resolve this either by placing the extras jar in the server classpath alongside the log4j.jar already there or configure your application to use child-first classloading. Jake On Mon, 19 Jul 2010 22:27:11 +0530 Saurabh Agrawal saurabh.agra...@criticalpath.net wrote: Hi Friends, Tomcat version: apache-tomcat-5.5.27 Operating System: SunOS 10.0 / Linux Problem: I've tried many times to configure apache-log4j-extras-1.0 with apache-log4j-1.2.16, but it is still failing to load classes from configure apache-log4j-extras-1.0 JAR file. What I want to do: Actually I want to do time based log rotation the my application specific log files. I could able to configure using 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, but few problems are reported on Apache site for this class. Solution I can think of: So, I have to look for another option for 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, and I found 'org.apache.log4j.rolling.RollingFileAppender' class and can use 'org.apache.log4j.rolling.TimeBasedRollingPolicy' in that. Steps I performed so far: 1. Downloaded apache-log4j-extras-1.0 with apache-log4j-1.2.16 JAR files from web. 2. Renamed apache-log4j-1.2.16.jar to simple 'log4j.jar'. 3. Copied apache-log4j-extras-1.0.jar in ~/WEB-INF/lib directory, where my old log4j is present. 4. Extracted new log4j.jar (1.2.16). 5. Edited the pom.xml file from new 'log4j.jar' to include 'apache-log4j-extras-1.0'. Steps are described here: ( https://wiki.jasig.org/display/UPM30/log4j.xml https://wiki.jasig.org/display/UPM30/log4j.xml). 6. Created jar file again, after editing pom.xml. 7. Then I added following configuration block, in my application specific log-conf.xml (present in ~/WEB-INF/etc/): !-- Presentation Server Access log appender -- appender name=access-log class=org.apache.log4j.rolling.RollingFileAppender FileWEB-INF/log-files/access.log/File rollingPolicy class=org.apache.log4j.rolling.TimeBasedRollingPolicy FileNamePatternWEB-INF/log-files/access.log.%d{-MM-dd}.log/Fil e NamePa ttern /rollingPolicy layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{dd.MM. HH:mm:ss,SSS} [%t] %c %x%n %-5p - %m%n/ /layout /appender but, still I am getting
Re: Default Initialization under Tomcat (5, 6)
On Thu, 15 Jul 2010 13:49:06 -0700 Kevin Kruzich kkruz...@mshift.com wrote: You are going to have to be more precise about what exactly you don't understand about these instructions. If you follow them, you will see Tomcat logging through Log4j. I've done it and I know it works. If you find these instructions a pain in the [you know what], I don't blame you. But the cause of the pain has nothing to do with Log4j and everything to do with Tomcat. If you have complaints, I encourage you to send them to the Tomcat team. This right here. Textbook case: # Build or download the additional logging components. See the extras components documentation for details. (http://tomcat.apache.org/tomcat-6.0-doc/extras.html) Ok, this is my last comment on this. Again this is a TOMCAT issue not a Log4j issue. Please send further questions about this process to Tomcat. There is no documentation here or in the resultant links that mention anything about log4j. Also A number of additional third party components may be used with Apache Tomcat. may be used means I don't want to use them. I read the instructions. They say to build or download. http://tomcat.apache.org/tomcat-6.0-doc/extras.html#Downloading Those instructions pointed me to (they don't link to it, they just say the Tomcat download page, which this is) http://tomcat.apache.org/download-60.cgi Then they say to select Browse form the Quick Navigation links. The specific link will change depending on the mirror being used, but the link provided to me was http://apache.ziply.com/tomcat/tomcat-6/v6.0.28 Then they say to go into the bin/extras directory and download the following components http://apache.ziply.com/tomcat/tomcat-6/v6.0.28/bin/extras/tomcat-juli.jar http://apache.ziply.com/tomcat/tomcat-6/v6.0.28/bin/extras/tomcat-juli-adapters.jar Now that you have these, re-read the instructions provided at... http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j This section is absent from the 5.5 docs. Is it entirely necessary? The logging system they use in Tomcat6 does not apply to Tomcat5.5. It is new, hence the reason why you didn't have to bother with this in Tomcat 5.5. --- I'm understanding there are mainly 2x things necessary for log4j to work: log4j.jar and log4j.properties. Just an hour ago I dropped both of these into a tomcat5 install and boom, it works. tomcat6... I've moved the files around to at least 5 different places and nothing. Because, again, you didn't follow the instructions which I have exhaustively detailed above. Fortunately I'm prototyping on virtual machines and I can do an install from scratch quickly. I'm doing a new tomcat6 from scratch (centos 5, jpackage tomcat6) --so we'll see how this one goes. This is mainly about getting central logging. Whether it's from apps, servers, or both... I don't care right now. I just need something feeding a file, feeding syslog. For future reference, please read the documentation first and follow the instructions provided. Keep in mind that your question is really off-topic. It has to do with Tomcat, not Log4j. I'm about the only person on this list that would bother answering a Tomcat question here. I only do it because I understand Tomcat6 logging and figured I could be of help. What I did not imagine that I'd have to do is spell out another product's documentation for you. I will not be doing such a thing in the future. We support Log4j here, not Tomcat. Jake Jacob Kjome said the following on 7/15/10 1:20 PM: On Thu, 15 Jul 2010 11:09:37 -0700 Kevin Kruzich kkruz...@mshift.com wrote: Thanks Jake -- My /etc/tomcat6/catalina.properties: common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar That works too --but I'm unable to see where ${catalina.base} and ${catalina.home} are defined. That isn't so immediately relevant though. These can be set in your environment as the following OS system properties CATALINA_BASE CATALINA_HOME The Tomcat scripts pick these up and uses them to set the following Java system properties catalina.base catalina.home The scripts will use defaults if you don't provide them. And catalina.base will be set to the value of catalina.home if not not explicitly set to something else. At this point I have no preference as to whether the logging is server or app. I just want *something* --and I had that *something* with tomcat5 without too much trouble. But what that something is is an important question which you have yet to answer. Do you want to see logging from your own application or from Tomcat? What you have set up so far is sufficient for the former, but not the latter. Keep in mind, this is *not* a Log4j question, but a Tomcat question. From Log4j standpoint, auto-configuration is working. I will give you a bit further advice here
Re: Default Initialization under Tomcat (5, 6)
Tomcat's catalina.properties contains... common.loader=${catalina.home}/lib,${catalina.home}/lib/*.jar This means that, assuming that /usr/share/tomcat6 is the path set for ${catalina.home}, the following should work fine... /usr/share/tomcat6/lib/log4j.jar /usr/share/tomcat6/lib/log4j.properties That said, is you purpose application logging or server logging (or both)? For application logging, this should be fine, though you'll share a logger repository with all apps under Tomcat (unless you include log4j.jar in WEB-INF/lib and log4j.properties or log4j.xml in WEB-INF/classes or you use a logger repository selector). For server logging, you need to following the instructions you already referenced http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j Jake On Thu, 15 Jul 2010 10:20:59 -0700 Kevin Kruzich kkruz...@mshift.com wrote: I was able to get log4j working with syslog without too much trouble using tomcat5. Yet with tomcat6 I'm having a heck of a time trying to figure out where log4j.properties should go. tomcat5: JAVA_OPTS=$JAVA_OPTS -Dcatalina.ext.dirs=$CATALINA_HOME/shared/lib:$CATALINA_HOME/common/lib /var/lib/tomcat5/common/lib/log4j.jar /var/lib/tomcat5/common/classes/log4j.properties works great! --- tomcat6: tomcat9995 0.5 1.2 649772 24900 ?Sl 21:01 0:03 /usr/bin/java -classpath :/usr/share/tomcat6/bin/bootstrap.jar:/usr/share/tomcat6/bin/tomcat-juli.jar:/usr/bin/build-classpath: error: JVM_LIBDIR /usr/lib/jvm-exports/java-1.6.0 does not exist or is not a directory -Dcatalina.base=/usr/share/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat6/temp -Djava.util.logging.config.file=/usr/share/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start /usr/share/tomcat6/lib/log4j.jar /usr/share/tomcat6/lib/log4j.properties (and many other locations) fails, fails... *?* Do I need a dir like /usr/share/tomcat6/common These instructions are over 8 years old so I imagine this section, in particular has changed quite a bit Default Initialization under Tomcat http://logging.apache.org/log4j/1.2/manual.html --- And lastly, there's this snippet on the Apache website -- is all this necessary? http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j # Download Log4J (v1.2 or later) and place the log4j jar in $CATALINA_HOME/lib. # Build or download the additional logging components. See the extras components documentation for details. # Replace $CATALINA_HOME/bin/tomcat-juli.jar with output/extras/tomcat-juli.jar. # Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib. # Delete $CATALINA_BASE/conf/logging.properties to prevent java.util.logging generating zero length log files. # Start Tomcat - 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: Default Initialization under Tomcat (5, 6)
On Thu, 15 Jul 2010 11:09:37 -0700 Kevin Kruzich kkruz...@mshift.com wrote: Thanks Jake -- My /etc/tomcat6/catalina.properties: common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar That works too --but I'm unable to see where ${catalina.base} and ${catalina.home} are defined. That isn't so immediately relevant though. These can be set in your environment as the following OS system properties CATALINA_BASE CATALINA_HOME The Tomcat scripts pick these up and uses them to set the following Java system properties catalina.base catalina.home The scripts will use defaults if you don't provide them. And catalina.base will be set to the value of catalina.home if not not explicitly set to something else. At this point I have no preference as to whether the logging is server or app. I just want *something* --and I had that *something* with tomcat5 without too much trouble. But what that something is is an important question which you have yet to answer. Do you want to see logging from your own application or from Tomcat? What you have set up so far is sufficient for the former, but not the latter. Keep in mind, this is *not* a Log4j question, but a Tomcat question. From Log4j standpoint, auto-configuration is working. I will give you a bit further advice here, but if you want more you need to re-read the introduction of the Tomcat Logging page, not just the Log4j specific instructions and/or contact the Tomcat user list. What's most important to me is that I can see something running through syslog. syslog seems to imply you want Tomcat logging. If you read a bit more closely, you'll understand why you see no logging from Tomcat. Specifically [begin quote] By default, only java.util.logging is available for the logs generated by the Tomcat internal loggers, as Tomcat uses a package renamed commons logging implementation which is hardcoded to use java.util.logging. Use of alternative logging frameworks requires building or downloading the extras components which include a full commons-logging implementation. Instructions for configuring the extras components to enable log4j to be used for Tomcat's internal logging may be found below. [end quote] This isn't working for me: /usr/share/tomcat6/lib/log4j.jar /usr/share/tomcat6/lib/log4j.properties Actually, it is, from Log4j's perspective. The logger repository is getting auto-configured using the log4j.properties you provided. That you see no Tomcat logging is because you have not yet followed the instructions below. ...and I wonder if these instructions are why. If these instructions require precise applicaton then what do these instructions mean? You are going to have to be more precise about what exactly you don't understand about these instructions. If you follow them, you will see Tomcat logging through Log4j. I've done it and I know it works. If you find these instructions a pain in the [you know what], I don't blame you. But the cause of the pain has nothing to do with Log4j and everything to do with Tomcat. If you have complaints, I encourage you to send them to the Tomcat team. http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j # Download Log4J (v1.2 or later) and place the log4j jar in $CATALINA_HOME/lib. # Build or download the additional logging components. See the extras components documentation for details. # Replace $CATALINA_HOME/bin/tomcat-juli.jar with output/extras/tomcat-juli.jar. # Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib. # Delete $CATALINA_BASE/conf/logging.properties to prevent java.util.logging generating zero length log files. # Start Tomcat Jake Jacob Kjome said the following on 7/15/10 10:40 AM: Tomcat's catalina.properties contains... common.loader=${catalina.home}/lib,${catalina.home}/lib/*.jar This means that, assuming that /usr/share/tomcat6 is the path set for ${catalina.home}, the following should work fine... /usr/share/tomcat6/lib/log4j.jar /usr/share/tomcat6/lib/log4j.properties That said, is you purpose application logging or server logging (or both)? For application logging, this should be fine, though you'll share a logger repository with all apps under Tomcat (unless you include log4j.jar in WEB-INF/lib and log4j.properties or log4j.xml in WEB-INF/classes or you use a logger repository selector). For server logging, you need to following the instructions you already referenced http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j Jake On Thu, 15 Jul 2010 10:20:59 -0700 Kevin Kruzich kkruz...@mshift.com wrote: I was able to get log4j working with syslog without too much trouble using tomcat5. Yet with tomcat6 I'm having a heck of a time trying to figure out where log4j.properties should go. tomcat5: JAVA_OPTS=$JAVA_OPTS -Dcatalina.ext.dirs
Re: log4j
When -Dlog4j.debug=true is set, Log4j prints its configuration progress to System.err. With this, you should be able to see which config file is being picked up. You can run your appender at a specified time by not placing log4j.properties in the classpath. But then you'll have to manually configure it at some later point. Note that if you also place a log4j.jar with WEB-INF/lib and another Log4j config file in WEB-INF/classes of your webapp, you will get a separate logger repository from the server containing a different configuration. If you remove your config file from WEB-INF/classes, you'll still have a separate logger repository from the server but use the same config as the server. Jake On Thu, 8 Jul 2010 10:21:39 +0530 Kaushal Shriyan kaushalshri...@gmail.com wrote: On Wed, Jul 7, 2010 at 8:28 PM, Jacob Kjome h...@visi.com wrote: Where did you put log4j.properties? For Tomcat 5.5.xx, it should be in CATALINA_HOME/common/classes. Try adding the following to CATALINA_OPTS -Dlog4j.debug=true Jake Hi Jake Thanks for the quick reply. is there a way to run log4j appender at a specified time? log4j.rootLogger=INFO, R log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=${catalina.home}/logs/catalina.out log4j.appender.R.DatePattern='.'-MM-dd log4j.appender.R.layout=org.apache.log4j.PatternLayout I have put the log4j.properties under /opt/tomcat0/common/classes and have added -Dlog4j.debug=true under CATALINA_OPTS variable. where do i look for the debug logs. Please suggest. Thanks and Regards Kaushal - 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
On Thu, 8 Jul 2010 17:59:23 +0530 Kaushal Shriyan kaushalshri...@gmail.com wrote: On Thu, Jul 8, 2010 at 5:48 PM, Jacob Kjome h...@visi.com wrote: When -Dlog4j.debug=true is set, Log4j prints its configuration progress to System.err. With this, you should be able to see which config file is being picked up Thanks Jake. Thanks, I could see it on catalina.out file where in system.out and system.err files goes. You can run your appender at a specified time by not placing log4j.properties in the classpath. But then you'll have to manually configure it at some later point. Please help me understand by providing examples. Basically if i set log4j.appender.R.DatePattern='.'-MM-dd in log4j.properties It rolls over at midnight. is there a way to roll over at say 12:00 Noon afternoon Oh, I see. Sorry, I thought you were asking if you could delay instantiation of your appender. Rather, you want to define when it rolls. See: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html As you can see, DailyRollingFileAppender is somewhat lacking in flexibility. You may have more luck with the Log4j-extras companion [1]. Specifically, RollingFileAppender [2] with a TimeBasedRollingPolicy [3]. [1] http://logging.apache.org/log4j/companions/extras/index.html [2] http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html [3] http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html Jake Please suggest/guide further Thanks, Kaushal - 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
On Thu, 8 Jul 2010 18:32:31 +0530 Kaushal Shriyan kaushalshri...@gmail.com wrote: On Thu, Jul 8, 2010 at 6:14 PM, Jacob Kjome h...@visi.com wrote: On Thu, 8 Jul 2010 17:59:23 +0530 Kaushal Shriyan kaushalshri...@gmail.com wrote: On Thu, Jul 8, 2010 at 5:48 PM, Jacob Kjome h...@visi.com wrote: When -Dlog4j.debug=true is set, Log4j prints its configuration progress to System.err. With this, you should be able to see which config file is being picked up Thanks Jake. Thanks, I could see it on catalina.out file where in system.out and system.err files goes. You can run your appender at a specified time by not placing log4j.properties in the classpath. But then you'll have to manually configure it at some later point. Please help me understand by providing examples. Basically if i set log4j.appender.R.DatePattern='.'-MM-dd in log4j.properties It rolls over at midnight. is there a way to roll over at say 12:00 Noon afternoon Oh, I see. Sorry, I thought you were asking if you could delay instantiation of your appender. Rather, you want to define when it rolls. See: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html As you can see, DailyRollingFileAppender is somewhat lacking in flexibility. You may have more luck with the Log4j-extras companion [1]. Specifically, RollingFileAppender [2] with a TimeBasedRollingPolicy [3]. [1] http://logging.apache.org/log4j/companions/extras/index.html [2] http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html [3] http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html Jake Jake, I referred to http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html it has only two options /wombat/folder/foo.%d (Daily rollover (at midnight). Due to the omission of the optional time and date pattern for the %d token specifier, the default pattern of -MM-dd is assumed, which corresponds to daily rollover.) /wombat/foo.%d{-MM}.log (Rollover at the beginning of each month.) Not sure though how it would fit it into my specific needs. You're not reading closely enough. The first example leaves off the optional time and date. The second example leaves off the optional time. Using the optional time is the key. The Logback docs contain some more documentation on the TimeBasedRollingPolicy, which shows some time configuration. That said, it doesn't provide an example for using a specific time of day. You might want to post a separate thread on the Log4j-user list or even the Logback list to see if someone knows the proper syntax. It seems like it should be possible. http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy You should be able to go by this documentation as both the Log4j-extras and Logback implementations have the same origin: the discontinued Log4j 1.3 effort. Jake Apologies for bugging Please suggest/further Thanks and Regards Kaushal - 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
Where did you put log4j.properties? For Tomcat 5.5.xx, it should be in CATALINA_HOME/common/classes. Try adding the following to CATALINA_OPTS -Dlog4j.debug=true Jake On Wed, 7 Jul 2010 11:58:23 +0530 Kaushal Shriyan kaushalshri...@gmail.com wrote: Hi, I am running tomcat server apache-tomcat-5.5.27. I have set the below parameters in log4j.properties log4j.rootLogger=INFO, R log4j.appender.R=org.apache.log4j.ISTDailyRollingFileAppender log4j.appender.R.File=${catalina.home}/logs/catalina.out log4j.appender.R.DatePattern='.'-MM-dd log4j.appender.R.layout=org.apache.log4j.PatternLayout ist-appender.jar,log4j-1.2.15.jar and commons-logging-1.1.1.jar under common/lib directory. The above settings didnot worked. is there a way to know why it didnot worked Please suggest/guide Thanks Kaushal - 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: Cannot configure apache-log4j-extras-1.0 with apache-log4j-1????
This a clearly a classloading/environment issue unique to uPortal. I suggest you ask on their list. There's nothing I can see that Log4j is doing wrong, at least not at this point. In any more standard environment, like Tomcat6, placing log4j.jar and log4j-extras.jar in WEB-INF/lib would work fine. One thing you could check is the type of classloading behavior you have configured. Is it parent-first (Java's standard classloading) or parent-last (often provided by containers to deal with classloading issues unique to JEE environments). If parent-first, you should check if log4j.jar exists in the server's classpath. If it is there, then it will be loaded in preference to the lgo4j.jar in WEB-INF/lib. Then if log4j.jar in the server's classpath tries to load something from log4j-extra.jar in WEB-INF/lib, it won't find it. Most servers allow you configure classloading behavior. Find the option to set it to parent-last and your problem may go away. Jake On 6/25/2010 12:26 PM, aalok95 wrote: Hi Friends, Problem: I've tried many times to configure apache-log4j-extras-1.0 with apache-log4j-1.2.16, but it is still failing to load classes from configure apache-log4j-extras-1.0 JAR file. What I want to do: Actually I want to do time based log rotation the my application specific log files. I could able to configure using 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, but few problems are reported on Apache site for this class. Solution I can think of: So, I have to look for another option for 'net.cp.ps.sdk.util.log.DailyRollingFileAppender' class, and I found 'org.apache.log4j.rolling.RollingFileAppender' class and can use 'org.apache.log4j.rolling.TimeBasedRollingPolicy' in that. Steps I performed so far: 1. Downloaded apache-log4j-extras-1.0 with apache-log4j-1.2.16 JAR files from web. 2. Renamed apache-log4j-1.2.16.jar to simple 'log4j.jar'. 3. Copied apache-log4j-extras-1.0.jar in ~/WEB-INF/lib directory, where my old log4j is present. 4. Extracted new log4j.jar (1.2.16). 5. Edited the pom.xml file from new 'log4j.jar' to include 'apache-log4j-extras-1.0'. Steps are described here: (https://wiki.jasig.org/display/UPM30/log4j.xml). 6. Created jar file again, after editing pom.xml. 7. Then I added following configuration block, in my application specific log-conf.xml (present in ~/WEB-INF/etc/): WEB-INF/log-files/access.log WEB-INF/log-files/access.log.%d{-MM-dd}.log but, still I am getting following exception: 7202 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse invite request mappings: [The XPath='invite-requests/invite-mapping' does not exist] 7214 [main] WARN net.cp.ps.sdk.server.ServerConfig - thread[main] Unable to parse known profiles request mappings: [The XPath='known-profiles-requests/known-profiles-mapping' does not exist] 8114 [main] ERROR net.cp.ps.sdk.server.ServerConfig - thread[main] Missing configuration: couldn't find value for /ps-conf/regex-whitespace-keyword log4j:ERROR Could not create an Appender. Reported error follows. java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.log4j.helpers.Loader.loadClass(Loader.java:160) Can someone please help me with this, what's going wrong? Thanks in advance. Regards, Saurabh Agrawal - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org