• 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

Logging

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my application I want to use logging. But the thing is that I want seperate error log, debug log, information log.

Using java.util.logging I found that all the higher level logs will come in a lower level log.

E.g. Severity WARNING will be there in INFO also.

Any solution to this problem. Can I use Log4j for this purpose?

 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you create several Loggers, each with its own FileHandler pointing to different files?
You might then create an umbrella logging class that calls the correct one based on the level of the log message received.
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Log4j is perfect for you.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With log4j, you will see the same behavior. A debug log would include info, warn, error. A warn log would include error. etc.

But it sounds like you can use a LevelMatchFilter to get the desired behavior. I haven't tried it.

Here's a quote from Ceki G�lc�'s (log4j developer) The complete log4j manual,


If you must absolutely filter events by exact match, then you can attach a LevelMatchFilter to a given appender in order to filter out logging events by exact level match. The LevelMatchFilter is an instance of a custom filter.
...
Note that the PropertyConfigurator does not support custom filters which can only be specified in configuration scripts expressed in XML format.

 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does java.util.logging provide this LevelMatcherFilter ?

 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any filter implementations in the java.util.logging package.

Looking at the
java.util.logging API, there is an interface java.util.logging.Filter you can implement.

It's got one method,

boolean isLoggable(LogRecord record)
Check if a given log record should be published.
[ March 21, 2005: Message edited by: Carol Enderlin ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I'd mention that I've been quite satisfied with the way you describe the levels working. If each level is in a different log file it seems to me it would be harder to follow the context of an error. Your mileage or needs may vary.
 
My cellmate was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic