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

Simon,

On 12/19/11 11:54 AM, Simon wrote:
> log4j.appender.file.File=/var/log/webapp.log
> 
> Thus, there is 3 identical webapps logging into the same log file 
> simultaneously :

It's more likely that the last one wins: the first 2 logs was probably
lost entirely.

> My hypothesis is that as every webapp log to the same log file from
> a different JVM (the tomcat instances), there could be some
> concurrency issues when the rolling from log4j occurs !!!

"Some" issues definitely. You need to change this.

> I would like that each webapp logs to a particular file without
> having a different log4j configuration packaged in the webapp.war
> archive. My first idea was to modify the log4j configuration so the
> webapp will log to the console (stdout) and then find a way to
> redirect the stdout inside a Tomcat instance to a particular file

That sounds awful: a hack (in log4j config) to go to stdout and then
another hack (in Tomcat config) to redirect to a file. Yuck.

> Is there a way to mimic this behaviour in Tomcat ?

*Sigh* if you have to, you can use the "swallowOutput" attribute on
your <Context> definition. Then you have to configure Tomcat's logging
system to put the logs where you want them.

IMO a better idea would be to configure log4j properly. I think you
have several options:

1. Modify the log4j.properties file in each WAR file to specify
   the proper filename. You said you didn't want to do this.

2. Use a log4j.properties file that is outside your WAR file.
   You'll have to figure out how to get your webapp to detect
   the right file so that your 3 separate copies don't end up
   reading the same file and reproducing the same issue described
   above.

3. In your log4j startup code, set a property based upon some
   configuration or environment (context path?) that can be used
   by log4j during configuration and setup of the logging system.
   I personally favor this approach. If you are running in separate
   JVMs, I think you can use system properties and have those
   replaced by log4j when parsing the configuration file(s).
   Read the documentation to be sure.

4. Configure log4j to log to syslog, and have syslog take care of
   the file situation. Of course, you'll have to identify each
   separate instance of your webapp if you want to be able to
   sort-out which log came from which source. So, you still
   have to somehow identify these webapps uniquely.

Hope that helps,
- -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/

iEYEARECAAYFAk7w0ZIACgkQ9CaO5/Lv0PAnlgCgmSXshaoYgwz1XRd+bl9JJZ2a
dF0An15eYuAzMy5w8A2AwZN4FEF229/A
=WE6F
-----END PGP SIGNATURE-----

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

Reply via email to