Last active
July 28, 2017 05:40
-
-
Save bcalmac/9056bb3a08cede6dab7a16d589d8b92c to your computer and use it in GitHub Desktop.
What happens if stdout is redirected to the same file as a FileAppender?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class DuplicateLogging { | |
private static final Logger logger = LoggerFactory.getLogger(DuplicateLogging.class); | |
public static void main(String[] args) throws IOException, InterruptedException { | |
logger.info("message 1"); | |
logger.debug("message 2"); | |
logger.info("message 3"); | |
logger.debug("message 4"); | |
logger.info("message 5"); | |
logger.debug("message 6"); | |
logger.info("message 7"); | |
logger.debug("message 8"); | |
System.out.println("This goes to the console!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | |
<file>log.txt</file> | |
<encoder> | |
<pattern>[FileAppender] %date %level %msg%n</pattern> | |
</encoder> | |
</appender> | |
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
<encoder> | |
<pattern>[ConsoleAppender] %date %level %msg%n</pattern> | |
</encoder> | |
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | |
<level>INFO</level> | |
</filter> | |
</appender> | |
<root level="DEBUG"> | |
<appender-ref ref="FILE"/> | |
<appender-ref ref="STDOUT"/> | |
</root> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example invocation: