You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Mikhail T." <mi...@aldan.algebra.com> on 2011/02/23 23:34:26 UTC
Separating some classes' messages from
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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Separating some classes' messages from
Posted by "Mikhail T." <mi...@aldan.algebra.com>.
On 24.02.2011 12:26, Jacob Kjome wrote:
> -Dlog4j.defaultInitOverride=true
> -Dlog4j.configuration=file:/url/path/to/log4j.xml
>
> See more at...
> http://logging.apache.org/log4j/1.2/manual.html#defaultInit
For the record, the -Dlog4j.defaultInitOverride should *not* be used, if
all one is changing is the location of the configuration file. When I
set both of these flags, I get:
log4j: Default initialization of overridden by
log4j.defaultInitOverrideproperty.
log4j:WARN No appenders could be found for logger
(org.serviio.console.ServiioConsole).
log4j:WARN Please initialize the log4j system properly.
Removing the flag -- and using the -Dlog4j.configuration /only/ --
causes the specified file to be properly parsed and everything gets
peachy...
I guess, one would want to override the default initialization if one's
application does its own configuration somehow. If all you are changing
is the config-file location, then you still want the default
initialization procedure to take place -- just with a different input.
Yours,
-mi
Re: Separating some classes' messages from
Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
ah. a good point. you probably just want the 2nd one:
-Dlog4j.configuration=file:/url/path/to/log4j.xml
you can just try it also (along with the -Dlog4j.debug=true suggested
previously)
■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com
"A wrong note played hesitatingly is a wrong note. A wrong note played
with conviction is interpretation."
"Mikhail T." <mi...@aldan.algebra.com>
02/24/2011 12:33 PM
Please respond to
"Log4J Users List" <lo...@logging.apache.org>
To
Jacob Kjome <ho...@visi.com>
cc
log4j-user@logging.apache.org
Subject
Re: Separating some classes' messages from <root>
On 24.02.2011 12:26, Jacob Kjome wrote:
> -Dlog4j.defaultInitOverride=true
> -Dlog4j.configuration=file:/url/path/to/log4j.xml
Thanks! Do I need the first of these switches for the second one to have
effect?
> See more at...
> http://logging.apache.org/log4j/1.2/manual.html#defaultInit
The manual says:
1. Setting the log4j.defaultInitOverride system property to any other
value then "false" will cause log4j to skip the default
initialization procedure (this procedure).
Which leaves things a bit unclear... Yours,
-mi
Re: Separating some classes' messages from
Posted by "Mikhail T." <mi...@aldan.algebra.com>.
On 24.02.2011 12:26, Jacob Kjome wrote:
> -Dlog4j.defaultInitOverride=true
> -Dlog4j.configuration=file:/url/path/to/log4j.xml
Thanks! Do I need the first of these switches for the second one to have
effect?
> See more at...
> http://logging.apache.org/log4j/1.2/manual.html#defaultInit
The manual says:
1. Setting the log4j.defaultInitOverride system property to any other
value then "false" will cause log4j to skip the default
initialization procedure (this procedure).
Which leaves things a bit unclear... Yours,
-mi
Re: Separating some classes' messages from
Posted by Jacob Kjome <ho...@visi.com>.
-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...@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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Separating some classes' messages from
Posted by "Mikhail T." <mi...@aldan.algebra.com>.
On 24.02.2011 10:49, Jacob Kjome wrote:
> Seems to me that Log4j is just setting up the Root logger defined in
> the config file, which references the SERVERLOG appender and,
> therefore, configures said appender.
>
> It is only coincidence that this has anything to do with the
> "org.serviio.console.ServiioConsole" class performing logging.
> Apparently, this is the first logger to be called and since Log4j was
> not yet configured, it configures itself using the log4j.xml config file.
>
> Your problem is that the root logger is referencing an appender, which
> points to a file that the user running your application has no
> permission to create. This has nothing whatsoever to do with
> additivity. Your config is fine. Your user's file system permissions
> need tweaking (or you need to point to a different file system
> location in your config).
Thank you very much, Jacob, for the analysis. Here is some more
information...
The application I'm dealing with -- serviio <http://www.serviio.org/> --
consists of two parts: the server daemon and the GUI console. As
distributed by the author, they share some settings, including the
log4j.xml file.
The daemon-part starts automatically at boot and runs under its own
user-ID. I want the daemon's log-messages in the log-file.
The console-piece can be started by any local user of the system -- and
no such user should be able to write to the server's log -- hence the
restrictive permissions... I want the console's log-messages to go to
stderr only, as is normal for interactive programs.
There are only two log4j-using classes used by the console, so it was
practical to enumerate them explicitly sending all their entries to
stderr. The catch-all Root-logger would not be used by the console at
all -- or so I thought... I'd consider it a bug, that the files
referenced by the file-appenders are opened /in advance/ instead of,
/lazily/ -- when needed -- which in this case would be never.
If there is no setting to tell log4j to postpone opening the files until
there is an actual message ready to be written there, I guess, my only
option is to have two distinct configuration files -- one for each piece
of the application... Is there a way to specify an alternative file
(rather than the default log4j.xml) on command-line with an environment
variable or -D/something/? Or must I create a separate directory for the
different log4j.xml? Thanks! Yours,
-mi
Re: Separating some classes' messages from
Posted by Jacob Kjome <ho...@visi.com>.
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...@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(DOMConfigurator.java:523)
> at
> org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:492)
> at
> org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:1001)
> at
> org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:867)
> at
> org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:773)
> at
> org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
> at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
> at
> org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
> at
> org.serviio.console.ServiioConsole.<clinit>(ServiioConsole.java:59)
>
> Any ideas? Thanks! Yours,
>
> -mi
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Separating some classes' messages from
Posted by "Mikhail T." <mi...@aldan.algebra.com>.
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(DOMConfigurator.java:523)
at
org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:492)
at
org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:1001)
at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:867)
at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:773)
at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at
org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
at
org.serviio.console.ServiioConsole.<clinit>(ServiioConsole.java:59)
Any ideas? Thanks! Yours,
-mi
Re: Separating some classes' messages from
Posted by Jacob Kjome <ho...@visi.com>.
<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...@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-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org