Log4j to Logback migration, logback.xml question

Hi there, I'm migrating my stuff from log4j to logback and I've gotten to the log4j.xml -> logback.xml porting. Besides not having a .dtd makes the work quite hard, I am trying to understand one thing: In log4j I had <category> supporting the class= attribute (while <logger>, which would be its replacement from my understanding, doesn't). Is there anything similar in logback.xml? I wrote a custom Logger (implementing Logger interface) and I would like to tell the logger to use it instead of org.slf4j.Logger. Thanks a lot. -- Fabio Erculiani

In SLF4J org.slf4j.Logger is the interface applications code to. SLF4J is the API. If you want to change the interface you aren't going to be able to use SLF4J. The only good way to extend Logback's Logger is to use the LoggerWrapper found in slf4j-ext, much as XLogger does. If you want to fully implement SLF4J's Logger interface than you essentially won't be using Logback. Ralph On Feb 7, 2011, at 11:15 AM, Fabio Erculiani wrote:
Hi there, I'm migrating my stuff from log4j to logback and I've gotten to the log4j.xml -> logback.xml porting. Besides not having a .dtd makes the work quite hard, I am trying to understand one thing: In log4j I had <category> supporting the class= attribute (while <logger>, which would be its replacement from my understanding, doesn't). Is there anything similar in logback.xml? I wrote a custom Logger (implementing Logger interface) and I would like to tell the logger to use it instead of org.slf4j.Logger.
Thanks a lot. -- Fabio Erculiani _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Hello Fabio, As Ralph Noted, XLogger in the slf4j-ext package shows how you could extend the SLF4J Logger interface. One could do quite a bit of extending via that approach. However, contrary to log4j, logback does *not* provide support for such extensions in configuration files. HTH, -- Ceki On 08.02.2011 02:12, Ralph Goers wrote:
In SLF4J org.slf4j.Logger is the interface applications code to. SLF4J is the API. If you want to change the interface you aren't going to be able to use SLF4J.
The only good way to extend Logback's Logger is to use the LoggerWrapper found in slf4j-ext, much as XLogger does. If you want to fully implement SLF4J's Logger interface than you essentially won't be using Logback.
Ralph
On Feb 7, 2011, at 11:15 AM, Fabio Erculiani wrote:
Hi there, I'm migrating my stuff from log4j to logback and I've gotten to the log4j.xml -> logback.xml porting. Besides not having a .dtd makes the work quite hard, I am trying to understand one thing: In log4j I had<category> supporting the class= attribute (while <logger>, which would be its replacement from my understanding, doesn't). Is there anything similar in logback.xml? I wrote a custom Logger (implementing Logger interface) and I would like to tell the logger to use it instead of org.slf4j.Logger.
Thanks a lot. -- Fabio Erculiani _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Thanks both, I'm in the process of checking out XLogger, slf4j-ext and LoggerWrapper. While doing this, some more (maybe stupid) questions, just to clarify: - Given what you said, I think I can't even create my own LoggerFactory and tell logback to use it (from logback.xml). Is this scenario possible? Because that would fix my issue. In short, I'd need to tell logback, through logback.xml to use my implementation of Logger. - Is there a way (I guess no, considering what Ceki said), to set Logger paramemters from inside <logger>, like I did in the log4j days using <param name="foo" value="1"> ? The answer is probably obvious, but better safe than sorry ;-). - Given the absence of a .dtd, is there a way to figure out all the supported parameters of logback.xml ? Thanks a lot -- Fabio Erculiani

Moreover, can I assume that the output pattern I used in log4j will work in logback too? For example, in <appender> I now have: <encoder> <pattern>%d{dd-MM-yy HH:mm:ss,SSS}|%5.5p|%m%n</pattern> </encoder> Which comes from log4j.xml I previously had. This question might be good for the Logback FAQ, also. Regards, -- Fabio Erculiani

On 08.02.2011 14:32, Fabio Erculiani wrote:
Moreover, can I assume that the output pattern I used in log4j will work in logback too? For example, in<appender> I now have: <encoder> <pattern>%d{dd-MM-yy HH:mm:ss,SSS}|%5.5p|%m%n</pattern> </encoder>
Which comes from log4j.xml I previously had. This question might be good for the Logback FAQ, also.
Regards,
Yes, in principle, log4j conversion patterns work in logback as is. Of course, logback are much more powerful. See http://logback.qos.ch/manual/layouts.html#conversionWord for more details. HTH, -- Ceki

On 08.02.2011 12:48, Fabio Erculiani wrote:
Thanks both, I'm in the process of checking out XLogger, slf4j-ext and LoggerWrapper.
While doing this, some more (maybe stupid) questions, just to clarify:
- Given what you said, I think I can't even create my own LoggerFactory and tell logback to use it (from logback.xml). Is this scenario possible? Because that would fix my issue. In short, I'd need to tell logback, through logback.xml to use my implementation of Logger. - Is there a way (I guess no, considering what Ceki said), to set Logger paramemters from inside<logger>, like I did in the log4j days using<param name="foo" value="1"> ? The answer is probably obvious, but better safe than sorry ;-). - Given the absence of a .dtd, is there a way to figure out all the supported parameters of logback.xml ?
Thanks a lot
If you are familiar with log4j.xml it is fairly easy to convert a log4j.xml to logback.xml. The hard part is mapping log4j classes to their logback equivalents. (We have a tool which automates such conversions for log4j.properties files). As for your Logger extensions, Markers may give you the flexibility you are looking for. What does your logger extension do? -- Ceki

On Tue, Feb 8, 2011 at 4:50 PM, Ceki Gulcu <ceki@qos.ch> wrote:
On 08.02.2011 12:48, Fabio Erculiani wrote:
If you are familiar with log4j.xml it is fairly easy to convert a log4j.xml to logback.xml. The hard part is mapping log4j classes to their logback equivalents. (We have a tool which automates such conversions for log4j.properties files).
That is also written in the manual. Still you haven't answered my questions ;-)))
As for your Logger extensions, Markers may give you the flexibility you are looking for. What does your logger extension do?
I need to set a property value on my custom Logger class, and I need to do it through logback.xml like I was able to do with log4j. If that's not possible, fine, I'll find another way to do the same. Just wanted to know if there would be a way from inside logback.xml.
-- Ceki
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
-- Fabio Erculiani

On 08/02/2011 10:46 PM, Fabio Erculiani wrote:
I need to set a property value on my custom Logger class, and I need to do it through logback.xml like I was able to do with log4j. If that's not possible, fine, I'll find another way to do the same. Just wanted to know if there would be a way from inside logback.xml.
Logback offers 3 different options you might not have considered: 1) put key/values into the logging context 2) put key/values into MDC 3) attach a marker to your logging statement Could one of the above work for you? -- Ceki

I'd like more information. Adding a property to a logger by itself does nothing. What happens to the property? Does it get added to the log event? Ralph On Feb 8, 2011, at 1:46 PM, Fabio Erculiani wrote:
On Tue, Feb 8, 2011 at 4:50 PM, Ceki Gulcu <ceki@qos.ch> wrote:
On 08.02.2011 12:48, Fabio Erculiani wrote:
If you are familiar with log4j.xml it is fairly easy to convert a log4j.xml to logback.xml. The hard part is mapping log4j classes to their logback equivalents. (We have a tool which automates such conversions for log4j.properties files).
That is also written in the manual. Still you haven't answered my questions ;-)))
As for your Logger extensions, Markers may give you the flexibility you are looking for. What does your logger extension do?
I need to set a property value on my custom Logger class, and I need to do it through logback.xml like I was able to do with log4j. If that's not possible, fine, I'll find another way to do the same. Just wanted to know if there would be a way from inside logback.xml.
-- Ceki
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
-- Fabio Erculiani _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (4)
-
Ceki Gulcu
-
Ceki Gülcü
-
Fabio Erculiani
-
Ralph Goers