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

Syslog writer thread should be daemon thread #7

Open
robertvazan opened this issue Oct 3, 2015 · 3 comments
Open

Syslog writer thread should be daemon thread #7

robertvazan opened this issue Oct 3, 2015 · 3 comments

Comments

@robertvazan
Copy link

My app is not exiting properly, because non-daemon syslog4j thread hangs in the background. Apparently there's some way to configure syslog4j to use daemon thread. What's more, daemon mode appears to be the default in recent versions, so maybe just upgrading would be enough.

Meantime I am calling System.exit(0) at the end of main() as a temporary workaround.

@robertvazan
Copy link
Author

I've improved termination code in my app in order to ensure that all messages are flushed to papertrail before exiting:

ch.qos.logback.classic.LoggerContext loggerContext = (ch.qos.logback.classic.LoggerContext)LoggerFactory.getILoggerFactory();
loggerContext.stop();
System.exit(0);

Nevertheless, this is still a workaround. The library should work out of the box.

@alexkuang
Copy link

alexkuang commented Oct 18, 2016

Not sure if this is still relevant, but... A slightly less hacky way I got around this is importing syslog4j 0.9.46 from clojars: https://mvnrepository.com/artifact/org.syslog4j/syslog4j/0.9.46

That version should use daemon threads by default. Or for more explicit configuration:

  <!-- from readme example -->
  <appender name="SYSLOG-TLS" class="com.papertrailapp.logback.Syslog4jAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <pattern>%-5level %logger{35}: %m%n%xEx</pattern>
    </layout>

    <syslogConfig class="org.productivity.java.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfig">
      <host>localhost</host>
      <port>514</port>
      <ident>java-app</ident>
      <maxMessageLength>128000</maxMessageLength>
      <useDaemonThread>true</useDaemonThread>  <!-- explicitly use daemon threads -->
    </syslogConfig>
  </appender>

+1 that we shouldn't need these workarounds though.

@lcersly
Copy link

lcersly commented Jun 6, 2018

For anyone stumbling on this using gradle. I used the following build file:

repositories {
    maven { url "https://clojars.org/repo" }
}

dependencies {
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    compile (group: 'com.papertrailapp', name: 'logback-syslog4j', version: '1.0.0'){
        exclude group:'org.syslog4j', module: 'syslog4j'
    }
    compile group: 'org.syslog4j', name: 'syslog4j', version: '0.9.46'
}

And then (as @alexkuang showed) adding the following to the syslogConfig node:

<useDaemonThread>true</useDaemonThread>  <!-- explicitly use daemon threads -->

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

3 participants