File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging

 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • 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?

 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
K Riaz
Ranch Hand
Posts: 375
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log4j is perfect for you.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does java.util.logging provide this LevelMatcherFilter ?

 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1364
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic