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 Pat Farrell <pf...@pfarrell.com> on 2009/02/16 21:54:18 UTC
sending output from separate java packages to separate files
I know this can be done, but I can't figure out how to configure
log4j.properties to send log messages from libraries/packages to
separate streams. I get all of my output in one log file.
I've read all of "The complete log4j manual" by Ceki Gülcü, and just
don't get it.
I want all msgs from com.baz.* to go one place,
all msgs from com.foo.* to go to another
all from net.sourceforge.stripes to go to a third.
the log4j file looks like:
1. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
2. log4j.appender.stdout.Target=System.out
3. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4. log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p
%c{1}:%L - %m%n
5.
6. log4j.appender.baz=org.apache.log4j.FileAppender
7. log4j.appender.baz.File=/tmp/baz.log
8.
9. log4j.appender.stripesfile=org.apache.log4j.FileAppender
10. log4j.appender.stripesfile.File=/tmp/stripes.log
11.
12. log4j.appender.foo=org.apache.log4j.FileAppender
13. log4j.appender.foo.File=/tmp/foo.log
14. log4j.rootLogger=INFO, stdout, base
15. log4j.logger.net.sourceforge.stripes=DEBUG, stdout, stripesfile
16. log4j.logger.com.foo=DEBUG, stdout, fnfbookfile
17. log4j.logger.com.baz=DEBUG, stdout, fnfbookfile
When I test it, it all goes to the same place
Test code looks like:
1. Logger aLog =
Logger.getLogger("net.sourceforge.stripes.action.Resolution");
2. aLog.error("this is an error");
5. Logger cLog = Logger.getLogger("com.foo.busobj.Address");
6. cLog.error("this is an error address");
7. Logger dLog =
Logger.getLogger("com.baz.database.DBConnectionPool");
8. dLog.error("this is an error DBConnPool");
Thanks
--
Pat Farrell
http://www.pfarrell.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
problem on dailyrolling appender
Posted by Santhoo Kumar <sa...@yahoo.com>.
hai,
i'm using following xml file for my log4j configuration, it is giving proper result when i using one file appender and chainsaw client. when i add 2 more dailyrollingfileappdender it is making problem like it is creating file at midnight but it is unable to keep backup of previous day files, i.e it is overwrite the log files at night, any one suggest me what i have to do for this to make it works.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<!--<log4j:configuration>-->
<appender name="file11" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
<param name="File" value=".../Trigger1.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy:MM:dd:HH:mm:ss} - %m%n" />
</layout>
</appender>
<appender name="file22" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
<param name="File" value="..../Trigger2.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy:MM:dd:HH:mm:ss} - %m%n" />
</layout>
</appender>
<appender name="file33" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
<param name="File" value=".../Trigger3.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy:MM:dd:HH:mm:ss} - %m%n" />
</layout>
</appender>
<appender name="CHAINSAW_CLIENT" class="org.apache.log4j.net.SocketAppender">
<param name="RemoteHost" value="10.50.0.90" />
<param name="port" value="4445" />
<param name="LocationInfo" value="true" />
<param name="threshold" value="debug" />
</appender>
<category name="file" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="CHAINSAW_CLIENT"/>
</category>
<category name="file1" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="CHAINSAW_CLIENT"/>
</category>
<category name="file2" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="CHAINSAW_CLIENT"/>
</category>
<category name="File11" additivity="false">
<level value="INFO"/>
<appender-ref ref="file1"/>
</category>
<category name="File22" additivity="false">
<level value="INFO"/>
<appender-ref ref="file2"/>
</category>
<category name="File33" additivity="false">
<level value="INFO"/>
<appender-ref ref="file3"/>
</category>
<root>
<priority value="debug"></priority>
<appender-ref ref="file1" />
<appender-ref ref="file2" />
<appender-ref ref="file3" />
<appender-ref ref="CHAINSAW_CLIENT" />
</root>
</log4j:configuration>
thanks in advance
Regards,
Santhoo
Re: sending output from separate java packages to separate files
Posted by Pat Farrell <pf...@pfarrell.com>.
Curt Arnold wrote:
> You define appenders named "stdout", "baz" and "foo", then you attach
> appenders named
Thanks. I tried to edit the property file to protect the innocent, and
mangled it.
> Since "base" and "stripesfile" are not defined, the only place for the
> messages to go is to "stdout".
Actually, they were always going to one of the log files. But you
pointed me in the right direction.
Thanks
My real problem was that Netbeans was putting the log4j.properties file
in the sublibrary, and it was getting read first.
> Since you are not setting additivity to false, all messages sent to
> "com.foo.*" will be sent to stdout twice, once for its attachment at
> "com.foo" and once for its attachment to the rootLogger.
I've read and re-read the complete manual, and I think I get the concept
of "additivity" but I don't understand how to control them in the
properties file.
Is there a source for more examples of log4j.properties files and
options, syntax, etc? The manual has lots more on XML formats and
controlling it from within Java than it has on simple properties.
Even the Wiki seems to not have much (or much I can find) on properties
files.
Where possible, I much prefer good ol Java properties files.
Thanks
Pat
--
Pat Farrell
http://www.pfarrell.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: sending output from separate java packages to separate files
Posted by Curt Arnold <ca...@apache.org>.
On Feb 16, 2009, at 3:54 PM, Pat Farrell wrote:
> I know this can be done, but I can't figure out how to configure
> log4j.properties to send log messages from libraries/packages to
> separate streams. I get all of my output in one log file.
>
> I've read all of "The complete log4j manual" by Ceki Gülcü, and just
> don't get it.
> I want all msgs from com.baz.* to go one place,
> all msgs from com.foo.* to go to another
> all from net.sourceforge.stripes to go to a third.
>
> the log4j file looks like:
>
> 1. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> 2. log4j.appender.stdout.Target=System.out
> 3. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> 4. log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p
> %c{1}:%L - %m%n
> 5.
> 6. log4j.appender.baz=org.apache.log4j.FileAppender
> 7. log4j.appender.baz.File=/tmp/baz.log
> 8.
> 9. log4j.appender.stripesfile=org.apache.log4j.FileAppender
> 10. log4j.appender.stripesfile.File=/tmp/stripes.log
> 11.
> 12. log4j.appender.foo=org.apache.log4j.FileAppender
> 13. log4j.appender.foo.File=/tmp/foo.log
> 14. log4j.rootLogger=INFO, stdout, base
> 15. log4j.logger.net.sourceforge.stripes=DEBUG, stdout, stripesfile
> 16. log4j.logger.com.foo=DEBUG, stdout, fnfbookfile
> 17. log4j.logger.com.baz=DEBUG, stdout, fnfbookfile
>
>
> When I test it, it all goes to the same place
>
> Test code looks like:
>
>
> 1. Logger aLog =
> Logger.getLogger("net.sourceforge.stripes.action.Resolution");
> 2. aLog.error("this is an error");
> 5. Logger cLog = Logger.getLogger("com.foo.busobj.Address");
> 6. cLog.error("this is an error address");
> 7. Logger dLog =
> Logger.getLogger("com.baz.database.DBConnectionPool");
> 8. dLog.error("this is an error DBConnPool");
>
>
> Thanks
>
> --
> Pat Farrell
> http://www.pfarrell.com/
>
>
You define appenders named "stdout", "baz" and "foo", then you attach
appenders named "stdout", "base" and "stripesfile" to various
loggers. Since "base" and "stripesfile" are not defined, the only
place for the messages to go is to "stdout".
Since you are not setting additivity to false, all messages sent to
"com.foo.*" will be sent to stdout twice, once for its attachment at
"com.foo" and once for its attachment to the rootLogger.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org