Custom LayoutWrappingEncoder question

View: New views
8 Messages — Rating Filter:   Alert me  

Custom LayoutWrappingEncoder question

by Adam Gordon :: Rate this Message:

| View Threaded | Show Only this Message

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

_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by Adam Gordon :: Rate this Message:

| View Threaded | Show Only this Message

that should have read %xEx... - fixed but still same issue.

_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by tony19 :: Rate this Message:

| View Threaded | Show Only this Message

See below

On Tue, Jan 17, 2012 at 3:10 PM, Adam Gordon <adam.n.gordon@...> 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@...
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by Adam Gordon :: Rate this Message:

| View Threaded | Show Only this Message

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@...> wrote:
See below

On Tue, Jan 17, 2012 at 3:10 PM, Adam Gordon <adam.n.gordon@...> 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@...
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by tony19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Jan 17, 2012 at 4:32 PM, Adam Gordon <adam.n.gordon@...> 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@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by Adam Gordon :: Rate this Message:

| View Threaded | Show Only this Message

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


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by tony19 :: Rate this Message:

| View Threaded | Show Only this Message

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@...> 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

http://gordonizer.com



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


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: Custom LayoutWrappingEncoder question

by Adam Gordon :: Rate this Message:

| View Threaded | Show Only this Message

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@...> 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

http://gordonizer.com



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


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user