Results 1 to 1 of 1
- 07-15-2010, 01:23 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
Log4J : logs of a specific category to a file, but only errors to the file AND stdout
Hello,
Need help on configuring log4j.
Let's say, we have following logger :
and this log4j configuration file :Java Code:Logger a = Logger.getLogger("a");
The test code looks like this :log4j.rootLogger=ERROR, stdout
log4j.category.a=TRACE, a
##### STDOUT
log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
log4j.appender.stdout.layout=org.apache.log4j.Patt ernLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%d{dd MM yyyy HH:mm:ss.SSS}] %l - %m%n
##### a
log4j.appender.a=org.apache.log4j.DailyRollingFile Appender
log4j.appender.a.File=c:\\logs\\a.log
log4j.appender.a.layout=org.apache.log4j.PatternLa yout
log4j.appender.a.layout.ConversionPattern=%-5p [%d{dd MM yyyy HH:mm:ss.SSS}] %l - %m%n
log4j.appender.a.DatePattern='.'yyyy-MM-dd
log4j.appender.a.ImmediateFlush=true
I see both of these lines in the file created AND in stdout :a.debug("debugA");
a.error("errorA");
But I don't want this line :Java Code:DEBUG [15 07 2010 13:53:24.245] log4jtest.Test1.main(Test1.java:12) - debugA ERROR [15 07 2010 13:53:24.250] log4jtest.Test1.main(Test1.java:13) - errorA
to appear in stdout.Java Code:DEBUG [15 07 2010 13:53:24.245] log4jtest.Test1.main(Test1.java:12) - debugA
What I want is, I've several categories, each logging to different files.
But when an error occurs, I want the stacktrace to appear in the stdout file (SystemOut.log) as well.
Is there a way of accomplishing this WITHOUT writing code looking similar to this :
Is there a way to establish this through the configuration file ?Java Code:... } catch (... e) { Logger log = Logger.getLogger("a"); log.error(e); log = Logger.getRootLogger(); log.error(e); }
Similar Threads
-
Log4j Grouping application logs
By mhanda in forum New To JavaReplies: 0Last Post: 03-09-2010, 12:19 AM -
How to put stdout in a class instead of a properties file??
By pudsinuk in forum New To JavaReplies: 0Last Post: 01-22-2010, 12:01 PM -
log4j: Multiple entries on Tomcat stdout file using log.error
By pbs in forum Web FrameworksReplies: 1Last Post: 10-24-2009, 02:18 AM -
Log4j problem - Logs are rolling into the previous date file
By vaibhavborole in forum Advanced JavaReplies: 0Last Post: 04-16-2009, 03:33 PM -
how do i print a specific txt file on a specific printer
By nikhilbhat in forum New To JavaReplies: 2Last Post: 11-08-2008, 10:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks