You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Le, Hong D." <HO...@saic.com> on 2012/05/15 16:04:33 UTC

Tomcat Stdout Rotate

Hi, 

 

I have tried so many ways to rotate tomcat stdout log file daily or by
size but unable to achieve the goal. My log file grows very quick
because I have to set ssl and handshake to debug mode. I appreciate if
you can help me how to do.

 

Thank you so much.


Re: Tomcat Stdout Rotate

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hong,

On 5/15/12 12:05 PM, Le, Hong D. wrote:
> It's a tomcat on windows so some options of logs or files rotation 
> available on Li/Unix won't work.

Oh, that's really too bad.

> I tried to write script to rotate but failed b/c as you said, I
> can't move log files while tomcat is running.

Yeah, that's just how things work.

> Neither Log4j.

Well, you can't make log4j take-over stdout (at least not that I know of).

You might be able to hack Tomcat to to this for you, though. If you
write a component like a LifecycleListener that runs a) in Tomcat's
ClassLoader and b) has all security permissions (if running under a
SecurityManager), you might be able to re-assign System.out to a
stream of your choosing.

Of course, you'd have to write a stream that was capable of doing what
you want, but you might even be able to just pipe everything (probably
broken by newlines) to a "real" logger that can do rotation, such as
j.u.logging or even log4j.

> I also tried swallowOutput (mine is Tomcat7), but it doesn't work
> for me.

That's only for webapps, not for the core of Tomcat. So, you're out of
luck where swallowOutput is concerned.

> I have to deal with it on production. That's the problem. Please 
> don't ask me why, just b/c that's the business I have.

I certainly don't envy your position. What are you doing with all that
debugging information? It's non-standard, probably impossible to
parse, etc. Why not use a Filter that captures the information you
*actually need* and log that appropriately? I realize you are probably
operating under  policy of stupidity that you can't change, but maybe
you haven't thought of everything ;)

> So maybe another question is how to do logging-pipe and rotate (as 
> you said) for JSSE?

I couldn't find any JSSE-specific logging configuration, so I suspect
that stdout is what you get with no other choices. That said, you
still might have options. I don't know how stable pipes are on win32,
but I would be comfortable launching a piped log process on *NIX to
monitor a log file as long as necessary. You could definitely try it
on win32 and see what happens. Something like this:

http://httpd.apache.org/docs/2.2/logs.html#piped

Those instructions are for Apache httpd. You can't configure Tomcat to
log in this way, but you can do your own shell-based output
redirection using "[...] | rotatelogs [...]" instead of "[...] >
logs/catalina.out [...]" -- just hack catalina.bat.

If you are running Tomcat as a service, I think you are pretty much
entirely out of luck, unless there is some commons-daemon option that
I don't know about to pipe stdout to a process instead of a file on
the disk. Does win32 have named-pipes?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+yjCsACgkQ9CaO5/Lv0PBysACfVg5wokI5XG3pOP2jvEHa1adU
va8AnjeX+K1ZWQAWCXu71DGmVxZqgRlz
=M7pN
-----END PGP SIGNATURE-----

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


Re: Tomcat Stdout Rotate

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dan,

On 5/15/12 12:41 PM, Daniel Mikusa wrote:
> ----- Original Message -----
>> Chris,
>> 
>> Thank you so much for the suggestions.
>> 
>> It's a tomcat on windows so some options of logs or files 
>> rotation available on Li/Unix won't work. I tried to write
>> script to rotate but failed b/c as you said, I can't move log
>> files while tomcat is running. Neither Log4j.
> 
> Are you running Tomcat as a Windows Service?  If so, you'll be 
> using a wrapper script.  The wrapper script should allow you to 
> rotate the stdout / stderr log file.  What wrapper script are you 
> using?

This prompted to actually *look* at commons-demon and it looks like
there is some support:

https://issues.apache.org/jira/browse/DAEMON-95

If you issue a SIGUSR1 to the process, it will re-open the output
files. I suspect that you could do something like this to rotate:

> STAMP=[obtain timestamp] ren catalina.out catalina.out.%STAMP% 
> pskill SIGUSR1 %CATALINA_PID%

You can get 'pskill' from Sysinternals, but I'm not sure if it will
work. This is obviously a very *NIX-oriented feature.

I would head-on over to the commons list and ask about log rotation
suggestions on win32.

That is, if you are using Tomcat's service launcher. You probably
should be, honestly.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+yjo4ACgkQ9CaO5/Lv0PCbqQCfTlovQW06feOq9nNaosg9dUkv
bWEAoIoFqUed8lPHrrXcE9BCoN7nGO1z
=xFEl
-----END PGP SIGNATURE-----

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


Re: Tomcat Stdout Rotate

Posted by Daniel Mikusa <dm...@vmware.com>.

----- Original Message -----
> Chris,
> 
> Thank you so much for the suggestions.
> 
> It's a tomcat on windows so some options of logs or files rotation
> available on Li/Unix won't work. I tried to write script to rotate
> but failed b/c as you said, I can't move log files while tomcat is
> running. Neither Log4j.

Are you running Tomcat as a Windows Service?  If so, you'll be using a wrapper script.  The wrapper script should allow you to rotate the stdout / stderr log file.  What wrapper script are you using?

Dan



> 
> I also tried swallowOutput (mine is Tomcat7), but it doesn't work for
> me. If
> 
> I have to deal with it on production. That's the problem. Please
> don't ask me why, just b/c that's the business I have.
> 
> So maybe another question is how to do logging-pipe and rotate (as
> you said) for JSSE?
> 
> Thanks.
> 
> 
> -----Original Message-----
> From: users-return-234255-HONG.D.LE=saic.com@tomcat.apache.org
> [mailto:users-return-234255-HONG.D.LE=saic.com@tomcat.apache.org] On
> Behalf Of Christopher Schultz
> Sent: Tuesday, May 15, 2012 11:02 AM
> To: Tomcat Users List
> Subject: Re: Tomcat Stdout Rotate
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hong,
> 
> On 5/15/12 10:04 AM, Le, Hong D. wrote:
> > I have tried so many ways to rotate tomcat stdout log file daily or
> > by
> > size but unable to achieve the goal.
> 
> What did you try?
> 
> > My log file grows very quick because I have to set ssl and
> > handshake
> > to debug mode.
> 
> This isn't in production, is it? You certainly don't want anything in
> debug mode in production - at least not for long.
> 
> > I appreciate if you can help me how to do.
> 
> Obviously, the best thing is not to dump a lot of stuff to stdout.
> Recent versions of Tomcat (you didn't say what you've got) have a
> "swallowOutput" option on specific webapps, but that is unlikely to
> affect JSSE debug logging.
> 
> Since Tomcat's logs/catalina.out is done using shell redirection, the
> stream moves with the file, so you can't just re-name the file:
> you'd have to restart Tomcat after moving the file which isn't
> really a good option.
> 
> You could try to use a logging-pipe that knows how to rotate files
> and hack catalina.sh to use that instead of "[...] >
> logs/catalina.out"
> that is in there currently.
> 
> Good luck,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk+yb9IACgkQ9CaO5/Lv0PBUEgCgrc9eirH0c+bRCzkkpkkgsyyb
> W9sAmwfRhP2C4OihZa27P3UkSnuCAhsy
> =g4yl
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

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


RE: Tomcat Stdout Rotate

Posted by "Le, Hong D." <HO...@saic.com>.
Chris,

Thank you so much for the suggestions.

It's a tomcat on windows so some options of logs or files rotation available on Li/Unix won't work. I tried to write script to rotate but failed b/c as you said, I can't move log files while tomcat is running. Neither Log4j.

I also tried swallowOutput (mine is Tomcat7), but it doesn't work for me. If

I have to deal with it on production. That's the problem. Please don't ask me why, just b/c that's the business I have.

So maybe another question is how to do logging-pipe and rotate (as you said) for JSSE?

Thanks.


-----Original Message-----
From: users-return-234255-HONG.D.LE=saic.com@tomcat.apache.org [mailto:users-return-234255-HONG.D.LE=saic.com@tomcat.apache.org] On Behalf Of Christopher Schultz
Sent: Tuesday, May 15, 2012 11:02 AM
To: Tomcat Users List
Subject: Re: Tomcat Stdout Rotate

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hong,

On 5/15/12 10:04 AM, Le, Hong D. wrote:
> I have tried so many ways to rotate tomcat stdout log file daily or by 
> size but unable to achieve the goal.

What did you try?

> My log file grows very quick because I have to set ssl and handshake 
> to debug mode.

This isn't in production, is it? You certainly don't want anything in debug mode in production - at least not for long.

> I appreciate if you can help me how to do.

Obviously, the best thing is not to dump a lot of stuff to stdout.
Recent versions of Tomcat (you didn't say what you've got) have a "swallowOutput" option on specific webapps, but that is unlikely to affect JSSE debug logging.

Since Tomcat's logs/catalina.out is done using shell redirection, the stream moves with the file, so you can't just re-name the file: you'd have to restart Tomcat after moving the file which isn't really a good option.

You could try to use a logging-pipe that knows how to rotate files and hack catalina.sh to use that instead of "[...] > logs/catalina.out"
that is in there currently.

Good luck,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+yb9IACgkQ9CaO5/Lv0PBUEgCgrc9eirH0c+bRCzkkpkkgsyyb
W9sAmwfRhP2C4OihZa27P3UkSnuCAhsy
=g4yl
-----END PGP SIGNATURE-----

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


Re: Tomcat Stdout Rotate

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hong,

On 5/15/12 10:04 AM, Le, Hong D. wrote:
> I have tried so many ways to rotate tomcat stdout log file daily or
> by size but unable to achieve the goal.

What did you try?

> My log file grows very quick because I have to set ssl and
> handshake to debug mode.

This isn't in production, is it? You certainly don't want anything in
debug mode in production - at least not for long.

> I appreciate if you can help me how to do.

Obviously, the best thing is not to dump a lot of stuff to stdout.
Recent versions of Tomcat (you didn't say what you've got) have a
"swallowOutput" option on specific webapps, but that is unlikely to
affect JSSE debug logging.

Since Tomcat's logs/catalina.out is done using shell redirection, the
stream moves with the file, so you can't just re-name the file: you'd
have to restart Tomcat after moving the file which isn't really a good
option.

You could try to use a logging-pipe that knows how to rotate files and
hack catalina.sh to use that instead of "[...] > logs/catalina.out"
that is in there currently.

Good luck,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+yb9IACgkQ9CaO5/Lv0PBUEgCgrc9eirH0c+bRCzkkpkkgsyyb
W9sAmwfRhP2C4OihZa27P3UkSnuCAhsy
=g4yl
-----END PGP SIGNATURE-----

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