You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Igor Cicimov <ic...@gmail.com> on 2011/04/18 07:38:54 UTC

Log rotate catalina.out

Hi all,

I have a question about rotating catalina.out file. Is there any way to
accomplish this through Tomcat without using external tool like logrotate
for example as shown in the following thread:

http://marc.info/?t=105544472600001&r=1&w=2

I understand that this might be a matter of bad coding practice but since
I'm not the developer of the applications running on the server I can't do
much about it. The applications are configured to use log4j but the
developers say they can't do much to redirect the applications console
output to the log files.

Thanks in advance for any help.

Igor

Re: Log rotate catalina.out

Posted by Thomas Freitag <th...@freit.ag>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Igor,

sorry for answering this late, I was quite busy the last days....

On 04/19/2011 09:04 AM, Igor Cicimov wrote:
> Hi Thomas,
> 
> Yes I have reference in the catalina.sh to the log4j.properties file:
> 
> LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/log4j.properties"
> 
> this is what I get in the catalina.out on restart:

Ok to round thinks up, you have do not set the correct system property
for log4j configuration, this is one problem (correct one is:
log4j.configuration, as I wrote in my previous mail).

> INFO: Configuring Log4j from File:
> /data/apache-tomcat-6.0.29/webapps/application/WEB-INF/etc/log4j-configuration.xml
> 19/04/2011 4:16:24 PM org.apache.catalina.core.ApplicationContext log
> INFO:  Log4J context Initialized
> 
> where log4j-configuration.xml is the application XML file located as given
> in the above log line. So that is being loaded ok.

Your application uses a custom placed log4j configuration file, setting
the log4j property will break this, but if you follow the advices in the
docs (don't set the property, instead place your log4j.properties in
$CATALINA_HOME/lib (or for more recent versions of Tomcat in
$CATALINA_BASE/lib).


For using log4j with Tomcat you need some additional files (read the
documentation carefully:
http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j).

> If I remove CONSOLE from the list of root loggers, isn't this going to
> prevent anything from being logged in the catalina.out file? I would like to
> keep the useful info from the restart process.

Yes it will prevent any log4j lines from being logged to catalina.out.
Just look in the real log files.

Please don't top post, it really confused me, when I was rereading this
mail.

HTH and regards,
- -- 
Thomas Freitag
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk25vGcACgkQGE5pHr3PKuUCZACfSNhMJ3aKb1Y2Chy5dI2kp7pw
uSsAmwRxzqK0hm0WFisviccmO7oF6F3/
=BKkV
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Log rotate catalina.out

Posted by Igor Cicimov <ic...@gmail.com>.
Hi Thomas,

Yes I have reference in the catalina.sh to the log4j.properties file:

LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/log4j.properties"

this is what I get in the catalina.out on restart:

INFO: Configuring Log4j from File:
/data/apache-tomcat-6.0.29/webapps/application/WEB-INF/etc/log4j-configuration.xml
19/04/2011 4:16:24 PM org.apache.catalina.core.ApplicationContext log
INFO:  Log4J context Initialized

where log4j-configuration.xml is the application XML file located as given
in the above log line. So that is being loaded ok.

If I remove CONSOLE from the list of root loggers, isn't this going to
prevent anything from being logged in the catalina.out file? I would like to
keep the useful info from the restart process.

Thanks,
Igor

On Mon, Apr 18, 2011 at 4:54 PM, Thomas Freitag <th...@freit.ag> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Igor,
>
> On 04/18/2011 08:23 AM, Igor Cicimov wrote:
> > Hi Thomas,
> >
> > First thanks for your reply. This is the relevant section in the
> > $CATALINA_BASE/conf/log4j.properties file:
>
> Do you use the JAva System Property
> - -Dlog4j.configuration=file:$CATALINA_BASE/conf/log4j.properties to
> reference this file? If not, it will never be loaded.
>
> >
> > log4j.debug=true
> > log4j.rootLogger=INFO, CATALINA, CONSOLE
> > .
> > .
> > .
> > log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> > log4j.appender.CONSOLE.encoding=UTF-8
> > log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> > log4j.appender.CONSOLE.DatePattern = '.'yyyy-MM-dd
> > log4j.appender.CONSOLE.layout.conversionPattern=%d{ISO8601} - %X{login} -
> > %X{device} - %X{uri} - %X{log} - %X{sessionId} - %m%n
>
> Remove CONSOLE from the list of root loggers.
>
> > and this is the log4j.properties file (relevant console section) for the
> > application:
> >
> >         <appender name="LOGOUT.CONSOLE"
> > class="org.apache.log4j.DailyRollingFileAppender">
> >                 <param name="File"
> > value="$CATALINA_BASE/logs/application-console.log"/>
> >                 <param name="Append" value="true"/>
> >                 <param name="datePattern" value="'.'yyyy-MM-dd"/>
> >                 <layout class="org.apache.log4j.PatternLayout">
> >                         <param name="ConversionPattern"
> value="%d{HH:mm:ss}
> > [%c] %m%n"/>
> >                 </layout>
> >         </appender>
>
> This is a XML configuration, you can not mix this with a properties
> configuration. Where is this file located WAR!WEB-INF/classes? If you
> use the system property I mentioned before this file will never be loaded.
>
> > but I can still see the application console output going into
> 'catalina.out'
> > instead in the 'application-console.log' file which never gets created.
>
> I don't believe your log4j configuration get loaded, check the
> catalina.out for log4j debug messages (at least during Tomcat startup,
> some lines with prefix "LOG4J" should appear).
>
> > And this is what I have in the application context:
> >
> > <Context .... swallowOutput="true"> .... </Context>
> >
> > Thanks,
> > Igorr,
>
>
> Regards,
> - --
> Thomas Freitag
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAk2r4C0ACgkQGE5pHr3PKuW+/ACeKaT7UbhhQHMe9G/gUlgnLuSv
> +/YAn0z6AOITkg+v4QsjCxmC6vIxQHxz
> =YwFi
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Log rotate catalina.out

Posted by Thomas Freitag <th...@freit.ag>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Igor,

On 04/18/2011 08:23 AM, Igor Cicimov wrote:
> Hi Thomas,
> 
> First thanks for your reply. This is the relevant section in the
> $CATALINA_BASE/conf/log4j.properties file:

Do you use the JAva System Property
- -Dlog4j.configuration=file:$CATALINA_BASE/conf/log4j.properties to
reference this file? If not, it will never be loaded.

> 
> log4j.debug=true
> log4j.rootLogger=INFO, CATALINA, CONSOLE
> .
> .
> .
> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> log4j.appender.CONSOLE.encoding=UTF-8
> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> log4j.appender.CONSOLE.DatePattern = '.'yyyy-MM-dd
> log4j.appender.CONSOLE.layout.conversionPattern=%d{ISO8601} - %X{login} -
> %X{device} - %X{uri} - %X{log} - %X{sessionId} - %m%n

Remove CONSOLE from the list of root loggers.

> and this is the log4j.properties file (relevant console section) for the
> application:
> 
>         <appender name="LOGOUT.CONSOLE"
> class="org.apache.log4j.DailyRollingFileAppender">
>                 <param name="File"
> value="$CATALINA_BASE/logs/application-console.log"/>
>                 <param name="Append" value="true"/>
>                 <param name="datePattern" value="'.'yyyy-MM-dd"/>
>                 <layout class="org.apache.log4j.PatternLayout">
>                         <param name="ConversionPattern" value="%d{HH:mm:ss}
> [%c] %m%n"/>
>                 </layout>
>         </appender>

This is a XML configuration, you can not mix this with a properties
configuration. Where is this file located WAR!WEB-INF/classes? If you
use the system property I mentioned before this file will never be loaded.

> but I can still see the application console output going into 'catalina.out'
> instead in the 'application-console.log' file which never gets created.

I don't believe your log4j configuration get loaded, check the
catalina.out for log4j debug messages (at least during Tomcat startup,
some lines with prefix "LOG4J" should appear).

> And this is what I have in the application context:
> 
> <Context .... swallowOutput="true"> .... </Context>
> 
> Thanks,
> Igorr,


Regards,
- -- 
Thomas Freitag
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk2r4C0ACgkQGE5pHr3PKuW+/ACeKaT7UbhhQHMe9G/gUlgnLuSv
+/YAn0z6AOITkg+v4QsjCxmC6vIxQHxz
=YwFi
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Log rotate catalina.out

Posted by Igor Cicimov <ic...@gmail.com>.
Hi Thomas,

First thanks for your reply. This is the relevant section in the
$CATALINA_BASE/conf/log4j.properties file:

log4j.debug=true
log4j.rootLogger=INFO, CATALINA, CONSOLE
.
.
.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.encoding=UTF-8
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.DatePattern = '.'yyyy-MM-dd
log4j.appender.CONSOLE.layout.conversionPattern=%d{ISO8601} - %X{login} -
%X{device} - %X{uri} - %X{log} - %X{sessionId} - %m%n

and this is the log4j.properties file (relevant console section) for the
application:

        <appender name="LOGOUT.CONSOLE"
class="org.apache.log4j.DailyRollingFileAppender">
                <param name="File"
value="$CATALINA_BASE/logs/application-console.log"/>
                <param name="Append" value="true"/>
                <param name="datePattern" value="'.'yyyy-MM-dd"/>
                <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d{HH:mm:ss}
[%c] %m%n"/>
                </layout>
        </appender>

but I can still see the application console output going into 'catalina.out'
instead in the 'application-console.log' file which never gets created.

And this is what I have in the application context:

<Context .... swallowOutput="true"> .... </Context>

Thanks,
Igor


On Mon, Apr 18, 2011 at 3:56 PM, Thomas Freitag <th...@freit.ag> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Igor,
>
> On 04/18/2011 07:38 AM, Igor Cicimov wrote:
> > I have a question about rotating catalina.out file. Is there any way to
> > accomplish this through Tomcat without using external tool like logrotate
> > for example as shown in the following thread:
> >
> > http://marc.info/?t=105544472600001&r=1&w=2
>
> No, catalina.out is is just redirected STDOUT and STDERR, you need an
> external tool for rotating it.
>
> > I understand that this might be a matter of bad coding practice but since
> > I'm not the developer of the applications running on the server I can't
> do
> > much about it. The applications are configured to use log4j but the
> > developers say they can't do much to redirect the applications console
> > output to the log files.
>
> If log4j is really used check the configuration for a ConsoleAppender
> (and disable it). If no logging framework is used, "swallowOutput" in
> your context configuration (see
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html) might help
> to keep your catalina.out clean.
>
> Regards,
> - --
> Thomas Freitag
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAk2r0o0ACgkQGE5pHr3PKuUotwCfadypG387UpnSkEwkSeudlPsi
> PmgAn0dWtrgaPIn5Ky8znLCzeMeWJ+OW
> =HbCM
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Log rotate catalina.out

Posted by Thomas Freitag <th...@freit.ag>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Igor,

On 04/18/2011 07:38 AM, Igor Cicimov wrote:
> I have a question about rotating catalina.out file. Is there any way to
> accomplish this through Tomcat without using external tool like logrotate
> for example as shown in the following thread:
> 
> http://marc.info/?t=105544472600001&r=1&w=2

No, catalina.out is is just redirected STDOUT and STDERR, you need an
external tool for rotating it.

> I understand that this might be a matter of bad coding practice but since
> I'm not the developer of the applications running on the server I can't do
> much about it. The applications are configured to use log4j but the
> developers say they can't do much to redirect the applications console
> output to the log files.

If log4j is really used check the configuration for a ConsoleAppender
(and disable it). If no logging framework is used, "swallowOutput" in
your context configuration (see
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html) might help
to keep your catalina.out clean.

Regards,
- -- 
Thomas Freitag
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk2r0o0ACgkQGE5pHr3PKuUotwCfadypG387UpnSkEwkSeudlPsi
PmgAn0dWtrgaPIn5Ky8znLCzeMeWJ+OW
=HbCM
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org