<div dir="ltr"><div><div>Bingo. Disabling the console appender made it work.<br></div>I want to understand this properly though. Even if the logs get accumulated in the output stream, why would the program hang? I'd have assumed the OutputStream is on a separate thread.<br></div>Is there any way to flush it either during runtime or to place a configuration parameter that forces auto-flushes? Already googled, but didn't find anything that worked.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 27, 2016 at 4:59 PM, Chetan Mehrotra <span dir="ltr"><<a href="mailto:chetan.mehrotra@gmail.com" target="_blank">chetan.mehrotra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">What happens if you try to disable the ConsoleAppender for outputter.<br>
Probably logs are getting accumulated in the output stream. But the<br>
java code is not draining it out so once it reaches the bugger limit<br>
it gets blocked.<br>
Chetan Mehrotra<br>
<div><div class="h5"><br>
<br>
On Mon, Jun 27, 2016 at 4:22 PM, Navin Ipe<br>
<<a href="mailto:navin.ipe@searchlighthealth.com">navin.ipe@searchlighthealth.com</a>> wrote:<br>
> Confirmed. There is a problem. Even without Spring Boot. Just using logback<br>
> and slf4j. A very very simple program. It outputs upto i=1146 and then the<br>
> program hangs.<br>
> Why does this happen?<br>
><br>
> You could try it yourself. The program is given below. You'll be able to<br>
> build and run the project without gradle too. Just use your favourite build<br>
> tool like Ant or Maven.<br>
><br>
> First project:<br>
> package com.slh;<br>
> import java.util.concurrent.TimeUnit;<br>
> import org.slf4j.Logger;<br>
> import org.slf4j.LoggerFactory;<br>
><br>
> public class outputter {<br>
><br>
> private static final Logger logger =<br>
> LoggerFactory.getLogger(outputter.class);<br>
><br>
> public static void main(String[] args) throws InterruptedException,<br>
> SQLException {<br>
> <a href="http://logger.info" rel="noreferrer" target="_blank">logger.info</a>("Outputter started");<br>
> Integer i = 0;<br>
><br>
> while(true) {<br>
> <a href="http://logger.info" rel="noreferrer" target="_blank">logger.info</a>("i = {}", i++);<br>
> TimeUnit.MILLISECONDS.sleep(100);<br>
> }<br>
><br>
> }<br>
> }<br>
><br>
> Gradle build of first project:<br>
> apply plugin: 'java'<br>
><br>
> sourceCompatibility = '1.8'<br>
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'<br>
><br>
> jar {<br>
> from {<br>
> (configurations.runtime).collect {<br>
> it.isDirectory() ? it : zipTree(it)<br>
> }<br>
> }<br>
> manifest {<br>
> attributes 'Main-Class': 'com.slh.outputter'<br>
> }<br>
> }<br>
><br>
> if (!hasProperty('mainClass')) {<br>
> ext.mainClass = 'com.slh.outputter'<br>
> }<br>
><br>
> repositories {<br>
> mavenCentral()<br>
> }<br>
><br>
> dependencies {<br>
> compile "ch.qos.logback:logback-classic:1.1.3"<br>
> compile "ch.qos.logback:logback-core:1.1.3"<br>
> compile "org.slf4j:slf4j-api:1.7.12"<br>
> testCompile group: 'junit', name: 'junit', version: '4.10'<br>
> }<br>
><br>
><br>
> Second project:<br>
> package com.slh;<br>
> import java.io.IOException;<br>
> import org.slf4j.Logger;<br>
> import org.slf4j.LoggerFactory;<br>
><br>
> public class outputtercaller {<br>
><br>
> private static final Logger logger =<br>
> LoggerFactory.getLogger(outputtercaller.class);<br>
><br>
> public static void main(String[] args) throws IOException,<br>
> InterruptedException {<br>
> Process ps;<br>
> <a href="http://logger.info" rel="noreferrer" target="_blank">logger.info</a>("Running outputter.jar. See the log file");<br>
> ps = Runtime.getRuntime().exec("java -jar outputter.jar ");<br>
> ps.waitFor();<br>
> <a href="http://logger.info" rel="noreferrer" target="_blank">logger.info</a>("finished running outputter.jar");<br>
> }<br>
> }<br>
><br>
> Second project's gradle build file:<br>
> apply plugin: 'java'<br>
><br>
> sourceCompatibility = '1.8'<br>
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'<br>
><br>
> jar {<br>
> from {<br>
> (configurations.runtime).collect {<br>
> it.isDirectory() ? it : zipTree(it)<br>
> }<br>
> }<br>
> manifest {<br>
> attributes 'Main-Class': 'com.slh.outputtercaller'<br>
> }<br>
> }<br>
><br>
> if (!hasProperty('mainClass')) {<br>
> ext.mainClass = 'com.slh.outputtercaller'<br>
> }<br>
><br>
> repositories {<br>
> mavenCentral()<br>
> }<br>
><br>
> dependencies {<br>
> compile "ch.qos.logback:logback-classic:1.1.3"<br>
> compile "ch.qos.logback:logback-core:1.1.3"<br>
> compile "org.slf4j:slf4j-api:1.7.12"<br>
><br>
> testCompile group: 'junit', name: 'junit', version: '4.10'<br>
> }<br>
><br>
><br>
> Both programs have their own logback.xml files which look like this:<br>
><br>
> <configuration><br>
> <!-- always a good activate OnConsoleStatusListener --><br>
> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"<br>
> /><br>
><br>
> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><br>
> <!-- encoders are assigned the type<br>
> ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --><br>
> <encoder><br>
> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -<br>
> %msg%n</pattern><br>
> </encoder><br>
> </appender><br>
><br>
> <appender name="FILE"<br>
> class="ch.qos.logback.core.rolling.RollingFileAppender"><br>
> <file>outputter.log</file><br>
> <rollingPolicy<br>
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><br>
> <fileNamePattern>crystal.%d{yyyy-MM-dd}.log.zip</fileNamePattern><br>
> <maxHistory>10000</maxHistory><br>
> </rollingPolicy><br>
><br>
> <encoder><br>
> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -<br>
> %msg%n</pattern><br>
> </encoder><br>
> </appender><br>
><br>
> <logger name="com.slh" level="INFO"/><br>
><br>
><br>
> <root level="debug"><br>
> <appender-ref ref="FILE" /><br>
> <appender-ref ref="STDOUT" /><br>
> </root><br>
><br>
> </configuration><br>
><br>
><br>
><br>
><br>
> On Mon, Jun 27, 2016 at 10:32 AM, Navin Ipe<br>
> <<a href="mailto:navin.ipe@searchlighthealth.com">navin.ipe@searchlighthealth.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm using...<br>
>><br>
>> import org.slf4j.Logger;<br>
>> import org.slf4j.LoggerFactory;<br>
>> static Logger logger = LoggerFactory.getLogger(MyClass.class);<br>
>> Process ps;<br>
>> ps = Runtime.getRuntime().exec("java -jar myclass.jar");<br>
>> ps.waitFor();<br>
>><br>
>> MyClass is part of a Spring Boot project which uses these dependencies:<br>
>> dependencies {<br>
>> compile "ch.qos.logback:logback-classic:1.1.3"<br>
>> compile "ch.qos.logback:logback-core:1.1.3"<br>
>> compile "org.slf4j:slf4j-api:1.7.12"<br>
>><br>
>> Problem is...<br>
>> myclass.jar runs fine for a while and I can see the outputs of the logger<br>
>> in myclass.log, but after a few hundred lines, there are no more log outputs<br>
>> visible. Moreover, the program itself doesn't seem to function anymore (the<br>
>> program is supposed to be writing to MySQL) but the program does not quit<br>
>> either. It just appears to hang. I left it for 14 hours like that, and<br>
>> nothing proceeded. There's no while loop after ps.waitFor(), and the code is<br>
>> itself not in an infinite loop. As long as the logs are written to the file,<br>
>> the program also writes to MySQL.<br>
>><br>
>> On the other hand, if I switch off logging, the program works fine from<br>
>> start to end, writes to MySQL and completes running in 6 hours and exits<br>
>> fine.<br>
>><br>
>> I'm considering writing a small sample program to test it out separately,<br>
>> but considered asking here in case this is a known issue.<br>
>><br>
>><br>
>> --<br>
>> Regards,<br>
>> Navin<br>
><br>
><br>
><br>
><br>
> --<br>
> Regards,<br>
> Navin<br>
><br>
</div></div>> _______________________________________________<br>
> slf4j-user mailing list<br>
> <a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
> <a href="http://mailman.qos.ch/mailman/listinfo/slf4j-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/slf4j-user</a><br>
_______________________________________________<br>
slf4j-user mailing list<br>
<a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/slf4j-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/slf4j-user</a></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Navin</div></div></div>
</div>