
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

See below On Tue, Jan 17, 2012 at 3:10 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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>
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>
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
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

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 On Tue, Jan 17, 2012 at 13:39, Tony Trinh <tony19@gmail.com> wrote:
See below
On Tue, Jan 17, 2012 at 3:10 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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>
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>
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
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

On Tue, Jan 17, 2012 at 4:32 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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

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 On Tue, Jan 17, 2012 at 16:21, Tony Trinh <tony19@gmail.com> wrote:
On Tue, Jan 17, 2012 at 4:32 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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 Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

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> . On Tue, Jan 17, 2012 at 6:41 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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
On Tue, Jan 17, 2012 at 16:21, Tony Trinh <tony19@gmail.com> wrote:
On Tue, Jan 17, 2012 at 4:32 PM, Adam Gordon <adam.n.gordon@gmail.com>wrote:
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 Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Worked like a charm. Thanks! On Jan 17, 2012, at 6:46 PM, Tony Trinh wrote:
There's a bug at line 98. You need to use Layout.doLayout(event) instead of event.getFormattedMessage(). I've commented here.
On Tue, Jan 17, 2012 at 6:41 PM, Adam Gordon <adam.n.gordon@gmail.com> wrote: 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
On Tue, Jan 17, 2012 at 16:21, Tony Trinh <tony19@gmail.com> wrote: On Tue, Jan 17, 2012 at 4:32 PM, Adam Gordon <adam.n.gordon@gmail.com> wrote: 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 Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (3)
-
adam
-
Adam Gordon
-
Tony Trinh