Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Communication Patterns: A Guide for Developers and Architects
this week in the
Design and Architecture
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Java in General
Appenders in log4j
xeon costa
Greenhorn
Posts: 15
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I've a
java
file that declares a class and an inner class. Both classes must log to distinct log files. 'A' class must log to A.log and 'B' must log to B.log. How can I set these classes to the respective appenders?
Below are the files:
package com.psc; import org.apache.log4j.Logger; public class A { private static final Logger LOG = Logger.getLogger(A.class); public void test() { LOG.info("TOMA1"); B b = new B(); b.test(); } private static class B { private static final Logger LOG2 = Logger.getLogger(B.class); public void test() { LOG2.debug("TOMA2"); } } public static void main(String[] args) { A a = new A(); a.test(); } }
# Root logger option log4j.rootLogger=INFO, stdout,A,B # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n # Direct log messages to a log file log4j.appender.com.psc=org.apache.log4jFileAppender log4j.appender.com.psc.File=a.log log4j.appender.A.Threshold=INFO log4j.appender.com.psc.layout=org.apache.log4j.PatternLayout log4j.appender.com.psc.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n # Direct log messages to a log file log4j.appender.B=org.apache.log4j.FileAppender log4j.appender.B.File=b.log log4j.appender.B.Threshold=DEBUG log4j.appender.B.layout=org.apache.log4j.PatternLayout log4j.appender.B.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
Thanks,
Campbell Ritchie
Marshal
Posts: 79670
381
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This question is too difficult for “beginning” and would fit better into a different forum, so I am moving it.
The fastest and most reliable components of any system are those that are not there. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Log4j - How to direct log messages to their respective log message file
Log4j - log in different files, same jar , different Main classes
Help Please -log4j:WARN No appenders could be found for logger
How can i add Log4j suppourt to my Application
Confusion in using Log4j
More...