File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Logging" Watch "Logging" New topic
Author

Logging

Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
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

Joined: Oct 12, 2000
Posts: 5093
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.


42
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Log4j is perfect for you.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Oct 18, 2004
Posts: 148
Does java.util.logging provide this LevelMatcherFilter ?

Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Oct 10, 2000
Posts: 1364
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.
 
 
subject: Logging