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

Usage of prefix with LogstashEncoder and LayoutWrappingEncoder throws errors #232

Closed
nhakimjee opened this issue Jun 27, 2017 · 8 comments
Closed
Labels
type/bug-logback Bugs in logback that impact logstash-logback-encoder

Comments

@nhakimjee
Copy link

I am trying to send my application logs to syslog using LogstashTcpSocketAppender. My configuration is as follows:

127.0.0.1:514 30 second 5 minutes 16384
  <!-- encoder is required -->
  <encoder class="net.logstash.logback.encoder.LogstashEncoder">
  	 <prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
        <layout class="ch.qos.logback.classic.PatternLayout">
           <pattern>%syslogStart{LOCAL0}</pattern>
        </layout>
     </prefix>

    <fieldNames>
	  <thread>[ignore]</thread>
	  <levelValue>[ignore]</levelValue>
</fieldNames>

    <includeCallerData>true</includeCallerData>      
  </encoder>
  
  <includeCallerData>true</includeCallerData>

However, I get the following errors when I startup my web application.
09:21:48,936 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/home/nhakimjee/work/Workspaces/syslog/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bap/WEB-INF/classes/logback-test.xml]
09:21:49,001 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
09:21:49,002 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word syslogStart with class [ch.qos.logback.classic.pattern.SyslogStartConverter]
09:21:49,002 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [net.logstash.logback.appender.LogstashTcpSocketAppender]
09:21:49,028 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stash-tcp]
09:21:49,358 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@5475d1b2 - A "net.logstash.logback.encoder.LogstashEncoder" object is not assignable to a "ch.qos.logback.core.Appender" variable.
09:21:49,358 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@5475d1b2 - The class "ch.qos.logback.core.Appender" was loaded by
09:21:49,359 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@5475d1b2 - [WebappClassLoader
context: ROOT
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2f92e0f4
] whereas object of type
09:21:49,359 |-ERROR in ch.qos.logback.core.joran.util.PropertySetter@5475d1b2 - "net.logstash.logback.encoder.LogstashEncoder" was loaded by [WebappClassLoader
context: ROOT
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2f92e0f4
].
09:21:49,359 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.fieldnames.LogstashFieldNames] for [fieldNames] property

I used the examples to for the above configuration, am I missing some something?

Thanks,

Nuruddin

@philsttr
Copy link
Collaborator

Hi Nuruddin,

Can you please provide your complete logback.xml file (while masking any sensitive data)? Specifically, I need to see the appender element.

@nhakimjee
Copy link
Author

Sorry for the delay. Here is my appender:

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

<appender name="stash-tcp" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
  <!-- Multiple destinations can be set and a reconnection strategy can be introduced -->
  <destination>127.0.0.1:514</destination>
  <reconnectionDelay>30 second</reconnectionDelay>
  <keepAliveDuration>5 minutes</keepAliveDuration>
  <writeBufferSize>16384</writeBufferSize>

  <!-- encoder is required -->
  <encoder class="net.logstash.logback.encoder.LogstashEncoder">
  	<prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%syslogStart{LOCAL6}</pattern>
      </layout>
    </prefix>

    <fieldNames>
	  <thread>[ignore]</thread>
	  <levelValue>[ignore]</levelValue>
    </fieldNames>

    <includeCallerData>true</includeCallerData>      
  </encoder>
  
  <includeCallerData>true</includeCallerData>
</appender>

@philsttr
Copy link
Collaborator

Looks like this is caused by a backwards incompatible change introduced in logback 1.2.1. Specifically, this change

For now, you can workaround this by using logback prior to 1.2.1.

I tested your config using logback 1.2.0 and 1.1.7, and it worked in both cases.

@philsttr philsttr changed the title Usage of prefix with LogstashEncoder and LogstashTcpSocketAppender throws errors Usage of prefix with LogstashEncoder and LayoutWrappingEncoder throws errors Jul 11, 2017
philsttr added a commit to philsttr/logback that referenced this issue Jul 11, 2017
…Appender`.

This allow `LayoutWrappingEncoder` to be used within another `Encoder`.

The introduction of `setParent(Appender)` in logback 1.2.1 caused an issue in downstream projects
that allow a `LayoutWrappingEncoder` to be used within another `Encoder`.

Specifically: logfellow/logstash-logback-encoder#232
@philsttr philsttr added type/bug-logback Bugs in logback that impact logstash-logback-encoder and removed type/bug labels Jul 11, 2017
@philsttr
Copy link
Collaborator

Submitted LOGBACK-1326 with qos-ch/logback#383 to hopefully fix this in logback.

@nhakimjee
Copy link
Author

Thank you!

@imod
Copy link

imod commented Jul 30, 2019

this does not look to be resolved in any foreseeable time - is there any other way this could be fixed?

@philsttr
Copy link
Collaborator

philsttr commented Sep 7, 2019

According to this comment, @ceki has marked LOGBACK-1326 to be fixed in logback 1.3.0-alpha5. And it looks like he has been active recently in the logback repo, so hopefully, this will be addressed soon. I know 2 years is a long time to wait for a PR to be merged, but I'm still hopeful due to the recent activity.

Without the requested change in logback, the only workaround would be to copy the LayoutWrappingEncoder class from logback, and make the change from the PR Specifically, change the type of the parent field and setParent method parameter to ContextAware. Then use the modified class instead of LayoutWrappingEncoder from logback.

andrewedstrom added a commit to codeforamerica/shiba that referenced this issue May 3, 2021
Logback introduced a backwards incompatible change in 1.2.1 which will be fixed in 1.3.0

See this issue for context: logfellow/logstash-logback-encoder#232

In the meantime, we should not upgrade to any of the 1.2.x versions. #182 should be closed.
@philsttr
Copy link
Collaborator

LOGBACK-1326 has been fixed in logback 1.2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug-logback Bugs in logback that impact logstash-logback-encoder
Projects
None yet
Development

No branches or pull requests

3 participants