Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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
  • Quote
  • Report post to moderator

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.layout.ConversionPattern=%-5p [%d{dd MM yyyy HH:mm:ss.SSS}] %l - %m%n

##### a
log4j.appender.a.layout.ConversionPattern=%-5p [%d{dd MM yyyy HH:mm:ss.SSS}] %l - %m%n

The test code looks like this :


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 ?
    Bookmark Topic Watch Topic
  • New Topic