Discussion:
[logback-user] Custom LayoutWrappingEncoder question
Adam Gordon
2012-01-17 20:10:51 UTC
Permalink
I'm using a custom LayoutWrappingEncoder to colorize and selectively
timestamp my log file entries. This encoder is configured via the
<encoder> element in my logback XML file. My question is, with a custom
encoder, is there a way I can specify a <layout> element in my <encoder>
element and use the built in layout patterns?

I've tried:

<encoder class="com.bar.foo.CustomLayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
[level] - %logger{15}: %message%n x%Ex{full}
</layout>
</encoder>

But I'm seeing the following error in the console when testing that:

13:06:58,318 |-ERROR in ch.qos.logback.classic.PatternLayout("null") -
Empty or null pattern.

Am I doing this correctly?

Thanks,

--adam
adam
2012-01-17 20:25:46 UTC
Permalink
that should have read %xEx... - fixed but still same issue.
Tony Trinh
2012-01-17 20:39:08 UTC
Permalink
See below
Post by Adam Gordon
I'm using a custom LayoutWrappingEncoder to colorize and selectively
timestamp my log file entries. This encoder is configured via the
<encoder> element in my logback XML file. My question is, with a custom
encoder, is there a way I can specify a <layout> element in my <encoder>
element and use the built in layout patterns?
<encoder class="com.bar.foo.CustomLayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
[level] - %logger{15}: %message%n x%Ex{full}
</layout>
</encoder>
I think you're missing the <pattern> tag. Try this:

<encoder class="com.bar.foo.CustomLayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
* <pattern>*[level] - %logger{15}: %message%n %xEx{full}*</pattern>*
</layout>
</encoder>
Post by Adam Gordon
13:06:58,318 |-ERROR in ch.qos.logback.classic.PatternLayout("null") -
Empty or null pattern.
Am I doing this correctly?
Thanks,
--adam
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
Adam Gordon
2012-01-17 21:32:38 UTC
Permalink
I was missing the <pattern> element. Adding got rid of the error message,
but my output is not being formatted. It's like its ignoring the pattern
and layout.

--adam

http://gordonizer.com
Post by Tony Trinh
See below
Post by Adam Gordon
I'm using a custom LayoutWrappingEncoder to colorize and selectively
timestamp my log file entries. This encoder is configured via the
<encoder> element in my logback XML file. My question is, with a custom
encoder, is there a way I can specify a <layout> element in my <encoder>
element and use the built in layout patterns?
<encoder class="com.bar.foo.CustomLayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
[level] - %logger{15}: %message%n x%Ex{full}
</layout>
</encoder>
<encoder class="com.bar.foo.CustomLayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
* <pattern>*[level] - %logger{15}: %message%n %xEx{full}*</pattern>
*
</layout>
</encoder>
Post by Adam Gordon
13:06:58,318 |-ERROR in ch.qos.logback.classic.PatternLayout("null") -
Empty or null pattern.
Am I doing this correctly?
Thanks,
--adam
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
Tony Trinh
2012-01-17 23:21:15 UTC
Permalink
Post by Adam Gordon
I was missing the <pattern> element. Adding got rid of the error message,
but my output is not being formatted. It's like its ignoring the pattern
and layout.
Including your code and complete logback.xml would be most helpful...
What exactly is the outcome? Describe the output (or paste it here).

--adam
Adam Gordon
2012-01-17 23:41:55 UTC
Permalink
Of course. Code is available here:
https://github.com/icfantv/color-logback

The outcome is that it appears that my encoder completely ignores any of
the pattern stuff. This leads me to believe I'm supposed to call something
in my encoder to do this - I'd assumed that it would happen automatically.

--adam

http://gordonizer.com
Post by Tony Trinh
Post by Adam Gordon
I was missing the <pattern> element. Adding got rid of the error
message, but my output is not being formatted. It's like its ignoring the
pattern and layout.
Including your code and complete logback.xml would be most helpful...
What exactly is the outcome? Describe the output (or paste it here).
--adam
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
Tony Trinh
2012-01-18 01:46:53 UTC
Permalink
There's a bug at line
98<https://github.com/icfantv/color-logback/blob/master/FooLayoutWrappingEncoder.java#L98>.
You need to use Layout.doLayout(event) instead of
event.getFormattedMessage(). I've commented
here<https://github.com/icfantv/color-logback/commit/17374f0b017f37ffd36cb12788948b5c0d76126d>
.
Post by Adam Gordon
https://github.com/icfantv/color-logback
The outcome is that it appears that my encoder completely ignores any of
the pattern stuff. This leads me to believe I'm supposed to call something
in my encoder to do this - I'd assumed that it would happen automatically.
--adam
http://gordonizer.com
Post by Tony Trinh
Post by Adam Gordon
I was missing the <pattern> element. Adding got rid of the error
message, but my output is not being formatted. It's like its ignoring the
pattern and layout.
Including your code and complete logback.xml would be most helpful...
What exactly is the outcome? Describe the output (or paste it here).
--adam
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
Adam Gordon
2012-01-18 20:30:52 UTC
Permalink
Worked like a charm. Thanks!
There's a bug at line 98. You need to use Layout.doLayout(event) instead of event.getFormattedMessage(). I've commented here.
Of course. Code is available here: https://github.com/icfantv/color-logback
The outcome is that it appears that my encoder completely ignores any of the pattern stuff. This leads me to believe I'm supposed to call something in my encoder to do this - I'd assumed that it would happen automatically.
--adam
http://gordonizer.com
I was missing the <pattern> element. Adding got rid of the error message, but my output is not being formatted. It's like its ignoring the pattern and layout.
Including your code and complete logback.xml would be most helpful...
What exactly is the outcome? Describe the output (or paste it here).
--adam
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
http://mailman.qos.ch/mailman/listinfo/logback-user
Loading...