
Hi everyone! I have a very general question about logging in Java -- I appreciate this being a logback-related list, but I assumed people with lots of experience in this domain would be able to give me the good advice I need :-) I want to include logging in the framework I'm creating -- this include several different modules that share centralized services like authentication, configuration, and, soon, logging. I've tried using log4j, but it didn't really fit my purpose, or rather I couldn't make it fit my purpose -- unresolved bugs and stuff. Be it as it may, I think I have to move on to a new library, only I'm wondering which one I should use. Perhaps someone can help me decide? My goal is to have logs written in an abstract, language-independent way (level, timestamp, message ID and name/value parameter pairs), so they can be displayed e.g. in different languages (e.g. in a web interface). For this, I want to use XML as the basis format for the logs. Ideally, logs should be rotated, with each finished file being a valid XML document by itself (i.e. with wrapping tag, would've worked in log4j if the writeFooter() method had been called in FileAppender.closeFile() ). It is quite clear to me that the current log file will probably *not* be a proper XML document (no end tag), but I'll take care of that later. I might also consider being happy with having invalid XML log files (no wrapping tag) and including them in a wrapper file using a SYSTEM entity. I'll see. Also ideally, if possible, I'd like to have a system that allows setting the log level on a medium basis -- i.e. have the very same message, from the very same logger, be logged only on channels for which the log level is enabled. For instance, I'd like to be able to use a single logger (in the log4j sense) with one console channel and one file channel, and have the file channel record all levels (debug - error) while the console displays only e.g. info to error. AFAIK this wasn't possible with log4j, as the logging level was defined for each logger, and the logger itself decided for all appenders whether a message should be logged or not. I don't mind expanding a bit on an existing library, but I'd like most of the functionality I've just described to be readily available or at least foreseen. Does anyone have a good idea? Thanks a lot in advance! Pagod

David Vergnaud wrote: [snip]
My goal is to have logs written in an abstract, language-independent way (level, timestamp, message ID and name/value parameter pairs), so they can be displayed e.g. in different languages (e.g. in a web interface). For this, I want to use XML as the basis format for the logs. Ideally, logs should be rotated, with each finished file being a valid XML document by itself (i.e. with wrapping tag, would've worked in log4j if the writeFooter() method had been called in FileAppender.closeFile() ). It is quite clear to me that the current log file will probably *not* be a proper XML document (no end tag), but I'll take care of that later. I might also consider being happy with having invalid XML log files (no wrapping tag) and including them in a wrapper file using a SYSTEM entity. I'll see.
You could create your own layout (see section "Writing your own layout in [1]) which could output logging events in XML format. The getContentType(), getFileHeader(), getFileFooter() methods in your Layout will be invoked when the log file is opened or closed, so as to produce valid XML . [1] http://logback.qos.ch/manual/layouts.html
Also ideally, if possible, I'd like to have a system that allows setting the log level on a medium basis -- i.e. have the very same message, from the very same logger, be logged only on channels for which the log level is enabled. For instance, I'd like to be able to use a single logger (in the log4j sense) with one console channel and one file channel, and have the file channel record all levels (debug - error) while the console displays only e.g. info to error. AFAIK this wasn't possible with log4j, as the logging level was defined for each logger, and the logger itself decided for all appenders whether a message should be logged or not.
Both log4j and logback have the capability you are asking for. See the chapter on filters http://logback.qos.ch/manual/filters.html
I don't mind expanding a bit on an existing library, but I'd like most of the functionality I've just described to be readily available or at least foreseen. Does anyone have a good idea?
Before extending logback, I suggest that you spend some time reading the manual. -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Hi Ceki, thanks of a lot for your answer.
You could create your own layout (see section "Writing your own layout in [1]) which could output logging events in XML format. The getContentType(), getFileHeader(), getFileFooter() methods in your Layout will be invoked when the log file is opened or closed, so as to produce valid XML .
I had tried to do just that with log4j, and only half of it had worked -- as i said, I think there was a problem with the writeFooter method. I take it this problem doesn't occur in logback.
Both log4j and logback have the capability you are asking for. See the chapter on filters http://logback.qos.ch/manual/filters.html
I hadn't had time to look into filters yet, I'll be sure to check them out! :-)
Before extending logback, I suggest that you spend some time reading the manual. Yup, that's definitely what I want to do. My question was more about which of the newer alternatives might be better for me, but it looks like logback will definitely be appropriate, so I'll start with that.
again thx a lot! David __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

David Vergnaud skrev:
I had tried to do just that with log4j, and only half of it had worked -- as i said, I think there was a problem with the writeFooter method. I take it this problem doesn't occur in logback.
Another approach might be deliberately writing out XML fragments without headers or footers, and then use <?xml version="1.0" ?> <!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd" [<!ENTITY data SYSTEM "abc">]> <log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/"> &data; </log4j:eventSet> to read it in (replace abc with the actual filename). (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/XMLLayout.h...) -- Thorbjørn Ravn Andersen "...plus... Tubular Bells!"
participants (3)
-
Ceki Gulcu
-
David Vergnaud
-
Thorbjoern Ravn Andersen