Bingo. Disabling the console appender made it work. 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. 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.
On Mon, Jun 27, 2016 at 4:59 PM, Chetan Mehrotra <[email protected]> wrote: > What happens if you try to disable the ConsoleAppender for outputter. > Probably logs are getting accumulated in the output stream. But the > java code is not draining it out so once it reaches the bugger limit > it gets blocked. > Chetan Mehrotra > > > On Mon, Jun 27, 2016 at 4:22 PM, Navin Ipe > <[email protected]> wrote: > > 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 > > <[email protected]> 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 > > > > _______________________________________________ > > slf4j-user mailing list > > [email protected] > > http://mailman.qos.ch/mailman/listinfo/slf4j-user > _______________________________________________ > slf4j-user mailing list > [email protected] > http://mailman.qos.ch/mailman/listinfo/slf4j-user -- Regards, Navin
_______________________________________________ slf4j-user mailing list [email protected] http://mailman.qos.ch/mailman/listinfo/slf4j-user
