[logback-user] Configuring FileAppender - only empty logfile created

stepwalk walkowia at arri.de
Thu Nov 28 14:30:23 CET 2013


Hi Everyone :-)

i've many troubles getting my FileAppender creating Logfiles.
The Logfile itself is created, but it's always empty. I don't know what else
i can do??!
May someone can have a look at my code and help me out.

Cheers Stephan



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.util.StatusPrinter;


part of my main code:

		// get instance of RootLogger for modification
		ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)
LoggerFactory
				.getLogger(Logger.ROOT_LOGGER_NAME);

		// reset the default context (which may already have been initialized)
		// since we want to reconfigure it
		LoggerContext logContext = logger.getLoggerContext();
		logContext.reset();

		// setup FileAppender
		PatternLayoutEncoder encoder1 = new PatternLayoutEncoder();
		encoder1.setPattern("%date %level [%thread] [%file:%line] %msg%n");
		encoder1.setContext(logContext);
		encoder1.start();

		
		// create FileAppender
		FileAppender<ILoggingEvent> logfileOut = new
FileAppender<ILoggingEvent>();
		logfileOut.setAppend(true);
		logfileOut.setFile("/home/stepwalk/AlmiraTestLocal/EclipseTestLogs/"
				+ name + "_" + System.currentTimeMillis() + ".log");
		logfileOut.setContext(logContext);
		logfileOut.setEncoder(encoder1);
		logfileOut.start();
		
		// create ConsoleAppender
		ConsoleAppender<ILoggingEvent> consoleOut = new
ConsoleAppender<ILoggingEvent>();
		consoleOut.setEncoder(encoder1);
		consoleOut.start();

		// attach the rolling file appender to the root logger
		logger.addAppender(logfileOut);
		logger.addAppender(consoleOut);
		logger.setLevel(Level.DEBUG);

		// print logback internal status messages
		StatusPrinter.print(logContext);

......more code......




--
View this message in context: http://logback.10977.n7.nabble.com/Configuring-FileAppender-only-empty-logfile-created-tp13127.html
Sent from the Users mailing list archive at Nabble.com.


More information about the Logback-user mailing list