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 alekoc <al...@mail.ru> on 2009/02/23 12:24:46 UTC
One .log file for two different applications
I have two web applications on one Tomcat server and would like to log each
application into the separate “xxx.log” file. Accordingly Log4j manual I can
do this, if I will use different file names, but I have a problem. Both logs
go to the same “xxx.log” file! Usually to the last one, that was active.
What is wrong in my log4j.properties?
First application properties:
<code>
log4j.rootLogger=DEBUG, F
log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F.Encoding=UTF-8
log4j.appender.F.File=${catalina.home}/logs/flat.log
log4j.appender.F.DatePattern='.'yyyy-MM-dd
log4j.appender.F.layout=org.apache.log4j.PatternLayout
log4j.appender.F.layout.conversionPattern=%d{ddMMyy HHmmss} %5c{2} %5p %-50m
%-18F %-12M:%-4L %t%n
</code>
Second application properties:
<code>
log4j.rootLogger=DEBUG, F
log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F.Encoding=UTF-8
log4j.appender.F.File=${catalina.home}/logs/cbrs.log
log4j.appender.F.DatePattern='.'yyyy-MM-dd
log4j.appender.F.layout=org.apache.log4j.PatternLayout
log4j.appender.F.layout.conversionPattern=%d{ddMMyy HHmmss} %5c{2} %5p %-50m
%-18F %-12M:%-4L %t%n
</code>
The logging result in my case looks like this:
<code>
040109 143812 cbrs DEBUG …
040109 145937 flat INFO …
040109 150530 flat INFO …
040109 150719 cbrs INFO …
040109 150719 cbrs INFO …
</code>
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22159737.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
RE: Fallback Handlers....
Posted by Chandresh Turakhia <ch...@bhartitelesoft.com>.
Dear all :
Does Fallback Handler work with SocketAppender. It works fine if I use FileAppender as Primary appender.
Question ) Which file does LogLog.debug("XXXX") gets written ??? How to run to see all these messages of log4j
Chand
-----Original Message-----
From: Chandresh Turakhia
Sent: Wednesday, February 25, 2009 12:00 PM
To: Log4J Users List
Cc: Chandresh Turakhia
Subject: Fallback Handlers....
Dear all :
I use bit modified version of SocketAppender ( NewSocketAppender ); and FileAppender ( NewFileAppender ).
Question 1 ) Why is Fallback error not working ... is there something wrong in the file
Question 2 ) I want fallback handler for each logger Database; ChannelGatewayLogs; BalanceLog; ConnectURL
Although Each write to same SocketAppender; How do I separate then at Fallback Handler level.
Thanks in advance for suggestions and help.
Chand
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1"
class="org.apache.log4j.net.NewSocketAppender">
<errorHandler
class="org.apache.log4j.varia.FallbackErrorHandler">
<root-ref />
<appender-ref ref="fallback" />
</errorHandler>
<param name="remoteHost" value="172.16.1.215" />
<param name="port" value="5999" />
</appender>
<appender name="fallback" class="org.apache.log4j.NewFileAppender">
<param name="File" value="fallback1.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%r [%t] %-5p %c{2} %x - %m%n" />
</layout>
</appender>
<logger name="com.mmoney.utilities.Database">
<level value="ERROR" />
</logger>
<logger name="com.mmoney.common.ChannelGatewayLogs">
<level value="INFO" />
</logger>
<logger name="com.mmoney.common.BalanceLog">
<level value="INFO" />
</logger>
<logger name="com.mmoney.sms.ConnectURL">
<level value="INFO" />
</logger>
<root>
<priority value="INFO" />
<appender-ref ref="A1" />
</root>
</log4j:configuration>
-----Original Message-----
From: alekoc [mailto:ale4349koc@mail.ru]
Sent: Wednesday, February 25, 2009 2:09 AM
To: log4j-user@logging.apache.org
Subject: Re: One .log file for two different applications
Thank you, Jacob
I thought Log4j is reentrant, but it is not. If so, everything is clear.
Yes, I put log4j-1.2.14.jar file into Apache\apache-tomcat\lib and tried to
use it for all my web applications. An idea was to decrease WAR file sizes.
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22190071.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
This e-mail and all material transmitted with it are for the use of the intended recipient(s) ONLY and contains confidential and/or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken pursuant to the contents of the present e-mail is strictly prohibited and is unlawful.
The recipient acknowledges that Bharti Telesoft Limited or its management or directors, are unable to exercise control or ensure the integrity over /of the contents of the information contained in e-mail. Any views expressed herein are those of the individual sender only and no binding nature of the contents shall be implied or assumed unless the sender does so expressly with due authority of Bharti Telesoft Limited. E-mail and any contents transmitted with it are prone to viruses and related defects despite all efforts to avoid such by Bharti Telesoft Limited.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Fallback Handlers....
Posted by Chandresh Turakhia <ch...@bhartitelesoft.com>.
Dear all :
I use bit modified version of SocketAppender ( NewSocketAppender ); and FileAppender ( NewFileAppender ).
Question 1 ) Why is Fallback error not working ... is there something wrong in the file
Question 2 ) I want fallback handler for each logger Database; ChannelGatewayLogs; BalanceLog; ConnectURL
Although Each write to same SocketAppender; How do I separate then at Fallback Handler level.
Thanks in advance for suggestions and help.
Chand
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1"
class="org.apache.log4j.net.NewSocketAppender">
<errorHandler
class="org.apache.log4j.varia.FallbackErrorHandler">
<root-ref />
<appender-ref ref="fallback" />
</errorHandler>
<param name="remoteHost" value="172.16.1.215" />
<param name="port" value="5999" />
</appender>
<appender name="fallback" class="org.apache.log4j.NewFileAppender">
<param name="File" value="fallback1.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%r [%t] %-5p %c{2} %x - %m%n" />
</layout>
</appender>
<logger name="com.mmoney.utilities.Database">
<level value="ERROR" />
</logger>
<logger name="com.mmoney.common.ChannelGatewayLogs">
<level value="INFO" />
</logger>
<logger name="com.mmoney.common.BalanceLog">
<level value="INFO" />
</logger>
<logger name="com.mmoney.sms.ConnectURL">
<level value="INFO" />
</logger>
<root>
<priority value="INFO" />
<appender-ref ref="A1" />
</root>
</log4j:configuration>
-----Original Message-----
From: alekoc [mailto:ale4349koc@mail.ru]
Sent: Wednesday, February 25, 2009 2:09 AM
To: log4j-user@logging.apache.org
Subject: Re: One .log file for two different applications
Thank you, Jacob
I thought Log4j is reentrant, but it is not. If so, everything is clear.
Yes, I put log4j-1.2.14.jar file into Apache\apache-tomcat\lib and tried to
use it for all my web applications. An idea was to decrease WAR file sizes.
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22190071.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
This e-mail and all material transmitted with it are for the use of the intended recipient(s) ONLY and contains confidential and/or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken pursuant to the contents of the present e-mail is strictly prohibited and is unlawful.
The recipient acknowledges that Bharti Telesoft Limited or its management or directors, are unable to exercise control or ensure the integrity over /of the contents of the information contained in e-mail. Any views expressed herein are those of the individual sender only and no binding nature of the contents shall be implied or assumed unless the sender does so expressly with due authority of Bharti Telesoft Limited. E-mail and any contents transmitted with it are prone to viruses and related defects despite all efforts to avoid such by Bharti Telesoft Limited.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
RE: One .log file for two different applications
Posted by Chandresh Turakhia <ch...@bhartitelesoft.com>.
-----Original Message-----
From: alekoc [mailto:ale4349koc@mail.ru]
Sent: Wednesday, February 25, 2009 2:09 AM
To: log4j-user@logging.apache.org
Subject: Re: One .log file for two different applications
Thank you, Jacob
I thought Log4j is reentrant, but it is not. If so, everything is clear.
Yes, I put log4j-1.2.14.jar file into Apache\apache-tomcat\lib and tried to
use it for all my web applications. An idea was to decrease WAR file sizes.
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22190071.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
This e-mail and all material transmitted with it are for the use of the intended recipient(s) ONLY and contains confidential and/or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken pursuant to the contents of the present e-mail is strictly prohibited and is unlawful.
The recipient acknowledges that Bharti Telesoft Limited or its management or directors, are unable to exercise control or ensure the integrity over /of the contents of the information contained in e-mail. Any views expressed herein are those of the individual sender only and no binding nature of the contents shall be implied or assumed unless the sender does so expressly with due authority of Bharti Telesoft Limited. E-mail and any contents transmitted with it are prone to viruses and related defects despite all efforts to avoid such by Bharti Telesoft Limited.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: One .log file for two different applications
Posted by alekoc <al...@mail.ru>.
Thank you, Jacob
I thought Log4j is reentrant, but it is not. If so, everything is clear.
Yes, I put log4j-1.2.14.jar file into Apache\apache-tomcat\lib and tried to
use it for all my web applications. An idea was to decrease WAR file sizes.
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22190071.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: One .log file for two different applications
Posted by Jacob Kjome <ho...@visi.com>.
On Tue, 24 Feb 2009 01:11:13 -0800 (PST)
alekoc <al...@mail.ru> wrote:
>
> Thank you, Arnauld
> I am new in Log4j. I just found it convenient for logging and decided to use
> it. I would like to ask you few questions, please.
>
> Why the shared/common directory relates to Log4j work? I had a hope that
> Log4j is a local re-enterable package and not important how do I call it. It
> should provide its main function – logging of process. Accordingly your
> response it is not exactly so.
>
> What means “loaded only once”? How can new web application use Log4j from
> another web application? I deploy them separately and each of them has its
> personal log4j.properties file.
>
Log4j lives within the rules of Java classloading. Just like any other
library, where you put in in the classloader hierarchy matters. If you want
two apps to use the same Log4j instance, then you need to place log4j in a
location where both apps can see it. Place log4j under each app's WEB-INF/lib
directory and not in some common location and you can't expect both to use a
single instance of Log4j. This is common sense.
A given instance of Log4j will perform auto-initialization once, as it runs in
a static block of the LogManager class. If each app has it's own Log4j
instance, then each app will have auto-initialization performed for it. If
Log4j is in a common classloader, then auto-initialization will occur once,
and only once no matter how many applications there are.
Of course, this doesn't mean you can't separate logging per/application using
a single shared instance of Log4j. I suggest you read the docs and search the
lists for the concept of the Repository Selector. By default, each instance
of Log4j initializes its default Logger Repository. If all apps use the
default, then they'll only be using a single configuration and logging to
appenders defined in that configuration. However, by using a Repository
Selector, one can store multiple configurations. A Repository Selector
implementation would contain logic on how each configuration (or Logger
Repository) is identified and selected. One common way is using JNDI.
Another is by using classloaders (though this can cause classloading issues in
environments where apps are restarted without shutting down the parent JVM,
such as under a JEE container).
> What is “debug flag” you are talking about? How I can start to use/not use
> it?
>
When you run your app, add -Dlog4j.debug=true to the Java command line
Jake
> --
> View this message in context:
>http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22178447.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: One .log file for two different applications
Posted by alekoc <al...@mail.ru>.
Thank you, Arnauld
I am new in Log4j. I just found it convenient for logging and decided to use
it. I would like to ask you few questions, please.
Why the shared/common directory relates to Log4j work? I had a hope that
Log4j is a local re-enterable package and not important how do I call it. It
should provide its main function – logging of process. Accordingly your
response it is not exactly so.
What means “loaded only once”? How can new web application use Log4j from
another web application? I deploy them separately and each of them has its
personal log4j.properties file.
What is “debug flag” you are talking about? How I can start to use/not use
it?
--
View this message in context: http://www.nabble.com/One-.log-file-for-two-different-applications-tp22159737p22178447.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: One .log file for two different applications
Posted by Arnauld Van Muysewinkel <ar...@gmail.com>.
Probably your log4j library is not in the correct directory.If it's in a
shared/common directory, it will be loaded only once (by the first app to
request it), and the config file will be loaded only once.
Hint: try to start using the log4j debug flag and see what's happening in
details.
Yours faithfully,
--
Arnauld Van Muysewinkel
On Mon, Feb 23, 2009 at 12:24 PM, alekoc <al...@mail.ru> wrote:
>
> I have two web applications on one Tomcat server and would like to log each
> application into the separate "xxx.log" file. Accordingly Log4j manual I
> can
> do this, if I will use different file names, but I have a problem. Both
> logs
> go to the same "xxx.log" file! Usually to the last one, that was active.
> What is wrong in my log4j.properties?
>
> First application properties:
> <code>
> log4j.rootLogger=DEBUG, F
> log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.F.Encoding=UTF-8
> log4j.appender.F.File=${catalina.home}/logs/flat.log
> log4j.appender.F.DatePattern='.'yyyy-MM-dd
> log4j.appender.F.layout=org.apache.log4j.PatternLayout
> log4j.appender.F.layout.conversionPattern=%d{ddMMyy HHmmss} %5c{2} %5p
> %-50m
> %-18F %-12M:%-4L %t%n
> </code>
> Second application properties:
> <code>
> log4j.rootLogger=DEBUG, F
> log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.F.Encoding=UTF-8
> log4j.appender.F.File=${catalina.home}/logs/cbrs.log
> log4j.appender.F.DatePattern='.'yyyy-MM-dd
> log4j.appender.F.layout=org.apache.log4j.PatternLayout
> log4j.appender.F.layout.conversionPattern=%d{ddMMyy HHmmss} %5c{2} %5p
> %-50m
> %-18F %-12M:%-4L %t%n
> </code>
>
> The logging result in my case looks like this:
> <code>
> 040109 143812 cbrs DEBUG …
> 040109 145937 flat INFO …
> 040109 150530 flat INFO …
> 040109 150719 cbrs INFO …
> 040109 150719 cbrs INFO …
> </code>
>