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 Robert Bowen <sy...@yahoo.com> on 2006/06/06 13:55:23 UTC

Seperate log files for Tomcat / Java errors and application info

I have been scouring the list and have found a few mentions of how to maintain two seperate log files but I can't find examples and in any case what I would like to do is something a little different although I'm sure easy to do.

My app spits out all kinds of info in a certain, precise format. Tomcat startup/shutdown and Java exceptions are sneaking into my log. I would like tobe able to have all non-app messages go to one log, and app messages to another.

I am using xml format andmy log4j.xml is dirt simple. Can anyone tell me how to do this, or point me to a link? The documentation is enormous and they seem to explain just about everything you can possibly do with log4j ... except what I want to do. :(

Thanks in advance, log4j.xml follows,
Bob


<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
      <appender-ref ref="DAILYFILE"/>
    </appender>

    <appender name="DAILYFILE" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${log.dir}vcache_sys"/>
        <param name="datePattern" value="'.'yyyy-MM-dd"/>
        <param name="threshold" value="INFO"/>
        <param name="append" value="true"/>
        <param name="immediateFlush" value="true"/>
        
        <layout class="org.apache.log4j.PatternLayout">
               <param name="conversionPattern" value="%m%n"/>
        </layout>
    </appender>
    
    <root>
        <priority value="info"/>
        <appender-ref ref="ASYNC"/>
    </root>
</log4j:configuration>
		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.

Re: Seperate log files for Tomcat / Java errors and application info

Posted by Juha Laiho <Ju...@iki.fi>.
Robert Bowen wrote:
> I have been scouring the list and have found a few mentions of how to maintain two seperate log files but I can't find examples and in any case what I would like to do is something a little different although I'm sure easy to do.
> 
> My app spits out all kinds of info in a certain, precise format. Tomcat startup/shutdown and Java exceptions are sneaking into my log. I would like tobe able to have all non-app messages go to one log, and app messages to another.

So, you've placed log4j jar somewhere where Tomcat itself finds it (and 
as Tomcat uses Jakarta commons-logging, the commons-logging configures 
itself to use log4j whenever it finds log4j classes on the classpath).

Two solutions:
- move log4j jar somewhere where it doesn't end up in Tomcat framework
   classpaths, but only in webapp classpaths
   see: http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
- if you don't use commons-logging in your own code, configure
   commons-logging to use some other logging implementation than log4j
   see: 
http://jakarta.apache.org/commons/logging/commons-logging-1.0.2/docs/api/org/apache/commons/logging/package-summary.html

For the first, you could move log4j jar out of the classpath, somewhere 
where it is found by the shared classloader.

For the second, you need to add a system property 
org.apache.commons.logging.Log to Tomcat startup with the value 
specifying your desired Tomcat logging implementation.

-- 
..Juha

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Seperate log files for Tomcat / Java errors and application info

Posted by Javier Gonzalez <ja...@gmail.com>.
On 6/9/06, Robert Bowen <sy...@yahoo.com> wrote:
> Many thanks for the tip. I still haven't gotten around to implementing it because there are so few examples of xml files out there (there are many more .properties examples) so I am not sure exactly how to "attach the app appender to the highest point of your app hierachy". Currently I attach my ASYNC appender to root like this:
>
> <root>
>  <appender-ref ref="ASYNC"/>
> </root>

Suppose, as I said, that all your application packages are inside the
com.robertbowen.app hierachy. (And that you defined your loggers using
the class name as logger name :)

Then, assuming you have an appender called "AppAppender", you'd do this:

<logger name="com.robertbowen.app">
  <level value="INFO"/>
  <appender-ref ref="AppAppender"/>
</logger>

That way, any Logger of the com.robertbowen.app hierachy, say, the
class com.robertbowen.app.MyLogicClass will send messages up the
hierachy, and the appender AppAppender will get the log object and
write it. The log object will keep climbing the hierachy until root,
unless we disable additivity...

> ... but I am not sure how to do what you say, nor how to turn off additivity. Again, I've seen it done with .properties but not with xml. I haven't really gotten around to playing around with it, that being said, I just wanted to write back and say thanks, I think your tip is what I needed to know. When I get it working I'll let you know.

For additivity, you do it like this:

<logger name="com.robertbowen.app" additivity="false">
  <appender-ref ref="AppAppender"/>
</logger>

This way the log object doesn't reach the root logger, which means it
doesn't get written to the ASYNC appender.

Note, once again, that this approach assumes that you are naming your
loggers after the FQN of your classes. Something like this:

package com.robertbowen.app

public class MyClass {

       private static final Logger LOG = Logger.getLogger(MyClass.class);

       // this would also work: private Logger LOG =
Logger.getLogger(getClass());

}

-- 
Javier González Nicolini

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Seperate log files for Tomcat / Java errors and application info

Posted by Robert Bowen <sy...@yahoo.com>.
Many thanks for the tip. I still haven't gotten around to implementing it because there are so few examples of xml files out there (there are many more .properties examples) so I am not sure exactly how to "attach the app appender to the highest point of your app hierachy". Currently I attach my ASYNC appender to root like this:

<root>
 <appender-ref ref="ASYNC"/>
</root>

... but I am not sure how to do what you say, nor how to turn off additivity. Again, I've seen it done with .properties but not with xml. I haven't really gotten around to playing around with it, that being said, I just wanted to write back and say thanks, I think your tip is what I needed to know. When I get it working I'll let you know.

Thanks again,
Bob

----- Original Message ----
From: Javier Gonzalez <ja...@gmail.com>
To: Log4J Users List <lo...@logging.apache.org>
Sent: Tuesday, June 6, 2006 4:30:37 PM
Subject: Re: Seperate log files for Tomcat / Java errors and application info

Follow these steps:

1.- define one file appender for app messages and one appender for
non-app messages.

2.- attach non-app appender to the root logger

3.- attach the app appender to the highest point of your app hierachy.
Here I'm assuming you app is organized with a package hierachy that
can be traced to a package that is the father of all your packages,
and that you name your loggers after your classes, i.e. if your app is
organized within a package hierachy that is called
"com.robertbowen.app.*",  you want to attach your app logger to
"com.robertbowen.app".

4.- turn off additivity in the com.robertbowen.app logger. Very
important, if you don't do this your app output will mingle with your
non-app output at the root logger.

5.- Done! With this approach, you can also have your app on DEBUG and
non-app messages on INFO or WARNING.

On 6/6/06, Robert Bowen <sy...@yahoo.com> wrote:
> I have been scouring the list and have found a few mentions of how to maintain two seperate log files but I can't find examples and in any case what I would like to do is something a little different although I'm sure easy to do.
>
> My app spits out all kinds of info in a certain, precise format. Tomcat startup/shutdown and Java exceptions are sneaking into my log. I would like tobe able to have all non-app messages go to one log, and app messages to another.
>
> I am using xml format andmy log4j.xml is dirt simple. Can anyone tell me how to do this, or point me to a link? The documentation is enormous and they seem to explain just about everything you can possibly do with log4j ... except what I want to do. :(
>
> Thanks in advance, log4j.xml follows,
> Bob
>
>
> <log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/";>
> <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
>       <appender-ref ref="DAILYFILE"/>
>     </appender>
>
>     <appender name="DAILYFILE" class="org.apache.log4j.DailyRollingFileAppender">
>         <param name="file" value="${log.dir}vcache_sys"/>
>         <param name="datePattern" value="'.'yyyy-MM-dd"/>
>         <param name="threshold" value="INFO"/>
>         <param name="append" value="true"/>
>         <param name="immediateFlush" value="true"/>
>
>         <layout class="org.apache.log4j.PatternLayout">
>                <param name="conversionPattern" value="%m%n"/>
>         </layout>
>     </appender>
>
>     <root>
>         <priority value="info"/>
>         <appender-ref ref="ASYNC"/>
>     </root>
> </log4j:configuration>
>
> ---------------------------------
> Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
>


-- 
Javier González Nicolini

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org





Re: Seperate log files for Tomcat / Java errors and application info

Posted by Javier Gonzalez <ja...@gmail.com>.
Follow these steps:

1.- define one file appender for app messages and one appender for
non-app messages.

2.- attach non-app appender to the root logger

3.- attach the app appender to the highest point of your app hierachy.
Here I'm assuming you app is organized with a package hierachy that
can be traced to a package that is the father of all your packages,
and that you name your loggers after your classes, i.e. if your app is
organized within a package hierachy that is called
"com.robertbowen.app.*",  you want to attach your app logger to
"com.robertbowen.app".

4.- turn off additivity in the com.robertbowen.app logger. Very
important, if you don't do this your app output will mingle with your
non-app output at the root logger.

5.- Done! With this approach, you can also have your app on DEBUG and
non-app messages on INFO or WARNING.

On 6/6/06, Robert Bowen <sy...@yahoo.com> wrote:
> I have been scouring the list and have found a few mentions of how to maintain two seperate log files but I can't find examples and in any case what I would like to do is something a little different although I'm sure easy to do.
>
> My app spits out all kinds of info in a certain, precise format. Tomcat startup/shutdown and Java exceptions are sneaking into my log. I would like tobe able to have all non-app messages go to one log, and app messages to another.
>
> I am using xml format andmy log4j.xml is dirt simple. Can anyone tell me how to do this, or point me to a link? The documentation is enormous and they seem to explain just about everything you can possibly do with log4j ... except what I want to do. :(
>
> Thanks in advance, log4j.xml follows,
> Bob
>
>
> <log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
> <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
>       <appender-ref ref="DAILYFILE"/>
>     </appender>
>
>     <appender name="DAILYFILE" class="org.apache.log4j.DailyRollingFileAppender">
>         <param name="file" value="${log.dir}vcache_sys"/>
>         <param name="datePattern" value="'.'yyyy-MM-dd"/>
>         <param name="threshold" value="INFO"/>
>         <param name="append" value="true"/>
>         <param name="immediateFlush" value="true"/>
>
>         <layout class="org.apache.log4j.PatternLayout">
>                <param name="conversionPattern" value="%m%n"/>
>         </layout>
>     </appender>
>
>     <root>
>         <priority value="info"/>
>         <appender-ref ref="ASYNC"/>
>     </root>
> </log4j:configuration>
>
> ---------------------------------
> Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
>


-- 
Javier González Nicolini

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org