Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogstashSocketAppender prefix example incorrect #158

Closed
superfly72 opened this issue Mar 22, 2016 · 5 comments
Closed

LogstashSocketAppender prefix example incorrect #158

superfly72 opened this issue Mar 22, 2016 · 5 comments

Comments

@superfly72
Copy link

I have tried using the example given in the README with my SpringBoot (1.3.2) app

<configuration>
  <conversionRule conversionWord="syslogStart" converterClass="ch.qos.logback.classic.pattern.SyslogStartConverter"/>

  <appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender">
    <host>127.0.0.1</host>
    <port>514</port>
    <prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%syslogStart{LOCAL5}</pattern>
      </layout>
    </prefix>
  </appender>

  ...
</configuration>

but this results in an error

Application startup failed
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.util.PropertySetter@10d307f1 - A "ch.qos.logback.core.encoder.LayoutWrappingEncoder" object is not assignable to a "ch.qos.logback.core.Layout" variable.
ERROR in ch.qos.logback.core.joran.util.PropertySetter@10d307f1 - The class "ch.qos.logback.core.Layout" was loaded by 
ERROR in ch.qos.logback.core.joran.util.PropertySetter@10d307f1 - [sun.misc.Launcher$AppClassLoader@73d16e93] whereas object of type 
ERROR in ch.qos.logback.core.joran.util.PropertySetter@10d307f1 - "ch.qos.logback.core.encoder.LayoutWrappingEncoder" was loaded by [sun.misc.Launcher$AppClassLoader@73d16e93].

but if I remove the wrapping LayoutWrappingEncoder the code works.

  <appender name="JSON_SYSLOG" class="net.logstash.logback.appender.LogstashSocketAppender">
    <host>127.0.0.1</host>
    <port>514</port>
    <prefix class="ch.qos.logback.classic.PatternLayout">
       <pattern>%syslogStart{LOCAL5}</pattern>
    </prefix>
  </appender>

so I assume this example is incorrect.

@philsttr
Copy link
Collaborator

Thanks for reporting!

Fixed the documentation in commit 88b0c36

The LayoutWrappingEncoder is required when using a prefix within an encoder. But it's not required when using it within a layout or within the LogstashSocketAppender

@onema
Copy link

onema commented Nov 10, 2018

@philsttr, this works, but in your example of the documentation I get the following messages:

19:15:04,813 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@1f9d6c7b - A "net.logstash.logback.encoder.LogstashEncoder" object is not assignable to a "ch.qos.logback.core.Appender" variable.
19:15:04,813 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@1f9d6c7b - The class "ch.qos.logback.core.Appender" was loaded by 
19:15:04,813 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@1f9d6c7b - [sun.misc.Launcher$AppClassLoader@3d4eac69] whereas object of type 
19:15:04,813 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@1f9d6c7b - "net.logstash.logback.encoder.LogstashEncoder" was loaded by [sun.misc.Launcher$AppClassLoader@3d4eac69].

for the following config:

<configuration>
    <appender name="FOO" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <customFields>{"stage":"${STAGE_NAME}","function":"${FUNCTION_NAME}"}</customFields>
            <prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
                <layout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>*** FOO:</pattern>
                </layout>
            </prefix>
        </encoder>
    </appender>
...
</configuration>

What can I do to fix this?

@philsttr
Copy link
Collaborator

philsttr commented Nov 10, 2018

Hi @onema,

Unfortunately, you're running into a backwards incompatibility introduced in logback (LOGBACK-1326), as mentioned in logstash-logback-encoder #232.

I have submitted logback PR#383 to address this problem, but it has not gotten any attention in over a year (ping @ceki).

Please help out by voting for LOGBACK-1326 and adding a thumbs up to PR#383 to try to get this addressed in logback.

In the meantime, the only solution to get this working would be to downgrade logback-classic and logback-core to 1.2.0 (before the backwards incompatibility was introduced)

@onema
Copy link

onema commented Nov 10, 2018

Thanks for your response @philsttr, I up-voted and added a comment. Hopefully, it helps!

@linzhou-zhong
Copy link

As @philsttr said, going to downgrade the version of logback-classic and logback-core to 1.2.0 is an excellent but unique solution at this moment. Trying to verify if these two dependencies have been added in the pom.xml is also important.
Anyway, thanks for @philsttr . 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants