[slf4j-user] Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while
Navin Ipe
navin.ipe at searchlighthealth.com
Mon Jun 27 10:52:18 UTC 2016
Confirmed. There is a problem. Even without Spring Boot. Just using logback
and slf4j. A very very simple program. It outputs upto i=1146 and then the
program hangs.
Why does this happen?
You could try it yourself. The program is given below. You'll be able to
build and run the project without gradle too. Just use your favourite build
tool like Ant or Maven.
*First project: *
package com.slh;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class outputter {
private static final Logger logger =
LoggerFactory.getLogger(outputter.class);
public static void main(String[] args) throws InterruptedException,
SQLException {
logger.info("Outputter started");
Integer i = 0;
while(true) {
logger.info("i = {}", i++);
TimeUnit.MILLISECONDS.sleep(100);
}
}
}
*Gradle build of first project:*
apply plugin: 'java'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
jar {
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'com.slh.outputter'
}
}
if (!hasProperty('mainClass')) {
ext.mainClass = 'com.slh.outputter'
}
repositories {
mavenCentral()
}
dependencies {
compile "ch.qos.logback:logback-classic:1.1.3"
compile "ch.qos.logback:logback-core:1.1.3"
compile "org.slf4j:slf4j-api:1.7.12"
testCompile group: 'junit', name: 'junit', version: '4.10'
}
*Second project: *
package com.slh;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class outputtercaller {
private static final Logger logger =
LoggerFactory.getLogger(outputtercaller.class);
public static void main(String[] args) throws IOException,
InterruptedException {
Process ps;
logger.info("Running outputter.jar. See the log file");
ps = Runtime.getRuntime().exec("java -jar outputter.jar ");
ps.waitFor();
logger.info("finished running outputter.jar");
}
}
*Second project's gradle build file:*
apply plugin: 'java'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
jar {
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'com.slh.outputtercaller'
}
}
if (!hasProperty('mainClass')) {
ext.mainClass = 'com.slh.outputtercaller'
}
repositories {
mavenCentral()
}
dependencies {
compile "ch.qos.logback:logback-classic:1.1.3"
compile "ch.qos.logback:logback-core:1.1.3"
compile "org.slf4j:slf4j-api:1.7.12"
testCompile group: 'junit', name: 'junit', version: '4.10'
}
*Both programs have their own logback.xml files which look like this:*
<configuration>
<!-- always a good activate OnConsoleStatusListener -->
<statusListener
class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>outputter.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>crystal.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
<maxHistory>10000</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n</pattern>
</encoder>
</appender>
<logger name="com.slh" level="INFO"/>
<root level="debug">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
On Mon, Jun 27, 2016 at 10:32 AM, Navin Ipe <navin.ipe at searchlighthealth.com
> wrote:
> Hi,
>
> I'm using...
>
>
>
>
>
>
> *import org.slf4j.Logger;import org.slf4j.LoggerFactory;static Logger
> logger = LoggerFactory.getLogger(MyClass.class);Process ps;ps =
> Runtime.getRuntime().exec("java -jar myclass.jar");ps.waitFor();*
>
> MyClass is part of a Spring Boot project which uses these dependencies:
>
>
>
> *dependencies { compile "ch.qos.logback:logback-classic:1.1.3" compile
> "ch.qos.logback:logback-core:1.1.3" compile "org.slf4j:slf4j-api:1.7.12"*
>
> *Problem is...*
> myclass.jar runs fine for a while and I can see the outputs of the logger
> in myclass.log, but after a few hundred lines, there are no more log
> outputs visible. Moreover, the program itself doesn't seem to function
> anymore (the program is supposed to be writing to MySQL) but the program
> does not quit either. It just appears to hang. I left it for 14 hours like
> that, and nothing proceeded. There's no while loop after ps.waitFor(), and
> the code is itself not in an infinite loop. As long as the logs are written
> to the file, the program also writes to MySQL.
>
> On the other hand, if I switch off logging, the program works fine from
> start to end, writes to MySQL and completes running in 6 hours and exits
> fine.
>
> I'm considering writing a small sample program to test it out separately,
> but considered asking here in case this is a known issue.
>
>
> --
> Regards,
> Navin
>
--
Regards,
Navin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20160627/bbe01896/attachment.html>
More information about the slf4j-user
mailing list