• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4J : log everything of a specific category to a file, but only errors to the file AND stdout ..

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Need help on configuring log4j.

Let's say, we have following logger :



and this log4j configuration file :

log4j.rootLogger=ERROR, stdout
log4j.category.a=TRACE, a

##### STDOUT
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%d{dd MM yyyy HH:mm:ss.SSS}] %l - %m%n

##### a
log4j.appender.a=org.apache.log4j.DailyRollingFileAppender
log4j.appender.a.File=c:\\logs\\a.log
log4j.appender.a.layout=org.apache.log4j.PatternLayout
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



The test code looks like this :

a.debug("debugA");
a.error("errorA");



I see both of these lines in the file created AND in stdout :


But I don't want this line :



to appear in stdout.

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 ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic