Forums Register Login

Configure two log4j loggers in one application

+Pie Number of slices to send: Send
Hi all,

I have two log4j logger classes in one application, there are two configuration files for the two loggers.

But I found that some time only one logger works, another logger's log writes to another logger.

Since these two loggers are working in one JVM, is it mean that only one log4j logger is available in one JVM?


Best regards,
Leon
[ December 11, 2005: Message edited by: Leon Pu ]
+Pie Number of slices to send: Send
You can have as many loggers as you like. It's the appenders that you define in your configuration, not the loggers. But the log4j system only has one central point of configuration, so having more than one configuration file doesn't make sense.
+Pie Number of slices to send: Send
There are two sub projects need logger, each sub project will be compiled to one jar file.

I hope one project's logger class can write to one file, and another project's logger class write to another file. The level and other configuration for the appender are same.

Is it possible to configure the log4j xml configuration file to receive certain logger class?
+Pie Number of slices to send: Send
If you want to be logging to two different files, then you need two different appenders to log to those files. I don't know what you mean by a "logger class" but you can certainly configure a specific logger to use a specific appender.
+Pie Number of slices to send: Send
Logger class is my wrapper class to hide log4j from the invoker.

Could you give a sample to get logger with appender?
+Pie Number of slices to send: Send
Could anybody give a hint to get Logger by appender?

Thanks.
+Pie Number of slices to send: Send
I don't even know what that means. If I guess what it might mean, I have no idea why you would want to do that anyway. Or are you asking how to configure log4j?
+Pie Number of slices to send: Send
Hi Paul,

thank you for your reply.

I have two services in one application. In IDE environment, they are two sub projects, and will be compiled to two jars. So I want to save their logs to different files.

The problem is although they are separate projects, they will be deployed to one war. They will work in same JVM.

I have defined their own appender for different log file output in xml configuration file. My question is how can I get the instance of org.apache.log4j.Logger which uses the certain appender for different service?


Best regards,
Leon
+Pie Number of slices to send: Send
In log4j.xml, create two appenders e.g. service1 and service2, writing to two different files. Then add package level filter to each appender

<logger name="com.company.service1">
<appender-ref ref="service1"/>
</logger>

<logger name="com.company.service2">
<appender-ref ref="service2"/>
</logger>

Padma
+Pie Number of slices to send: Send
 

Originally posted by Padma Lalwani:
In log4j.xml, create two appenders e.g. service1 and service2, writing to two different files. Then add package level filter to each appender

<logger name="com.company.service1">
<appender-ref ref="service1"/>
</logger>

<logger name="com.company.service2">
<appender-ref ref="service2"/>
</logger>

Padma



It works. But I met a problem that one logger doesn't log the first time log, later it works without problem.
Normally trees don't drive trucks. Does this tiny ad have a license?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5127 times.
Similar Threads
Getting log4j to write to multiple log files
WARN level is not working
Writing Log4J for my appliaction
log4j category
Tomcat 5.5 logging internal process in tomcat_out.log
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:37:10.