2011/12/21 Konstantin Kolinko <knst.koli...@gmail.com>:
> 2011/12/20 Christopher Schultz <ch...@christopherschultz.net>:
>> -----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.
>
> FileAppender docs say that Append=true by default. Though I wonder
> what will happen during log rotation.
>
> Anyway entries from three servers in the same log file where they
> cannot be distinguished from each other are of little help.
>
>>
>>> 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.
>>

It is not really a hack in log4j configuration to redirect the logs in
stdout, as it is exactly what does the ConsoleAppender by default...

The idea here is that we (the developpers) can focus on *what* get
logged by configuring the log categories and the log pattern in the
log4.properties file using a simple ConsoleAppender.

Our infrastructure team (responsible for the server configuration and
resources) can focus on *where* the logs go (a file, a rolling file, a
JMS queue, syslog, or whatever the need) in the Tomcat configuration.

This has the other advantage to have a log4.configuration file and a
web application that are not too much dependant of the environment
(Unix file path vs Windows file path for example)...

I guess this why the <stdout /> feature is available in Resin... At
least it would help in this use case !


>>> 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.
>
> That is fragile. It depends on who catches the value of System.out
> first, Tomcat or a logging framework.
>
>>
>> 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.
>>
>
> 5. Configure it to write ${catalina.base}/logs.
>
> (That is if all webapps are on different Tomcat instances, as opposed
> to having several different-named webapps on the same Tomcat)
>
> If you want that to be written to /var/logs, you can replace
> ${catalina.base}/logs with a symlink to /var/logs/instance-N/.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

Thank you for your ideas and advices, it will definitely help me a lot !

Regards,

Simon

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

Reply via email to