use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project helios by spotify.
the class LoggingTestWatcher method setupFileLogging.
/**
* Sets up a FileAppender under the path {@code $logDir/<timestamp>-<name>-<pid>.log}. If not set
* as a system property then {@code $logDir} falls back to {@code /tmp/helios-test/log}.
*/
private void setupFileLogging(final String name) {
final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
final LoggerContext context = rootLogger.getLoggerContext();
context.reset();
final String ts = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS").format(new Date());
final String pid = ManagementFactory.getRuntimeMXBean().getName().split("@", 2)[0];
final PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setContext(context);
ple.setPattern("%d{HH:mm:ss.SSS} %-5level %logger{1} %F:%L - %msg%n");
ple.start();
final Path directory = Paths.get(System.getProperty("logDir", "/tmp/helios-test/log/"));
final String filename = String.format("%s-%s-%s.log", ts, name, pid);
final Path file = directory.resolve(filename);
final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setEncoder(ple);
fileAppender.setFile(file.toString());
fileAppender.setContext(context);
fileAppender.start();
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
try {
Files.createDirectories(directory);
} catch (IOException e) {
throw Throwables.propagate(e);
}
configureLogger("org.eclipse.jetty", Level.ERROR);
configureLogger("org.apache.curator", Level.ERROR);
configureLogger("org.apache.zookeeper", Level.ERROR);
configureLogger("com.spotify.helios", Level.DEBUG);
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project drill by apache.
the class LogFixture method setupConsole.
private void setupConsole(LogFixtureBuilder builder) {
drillLogger = (Logger) LoggerFactory.getLogger(DRILL_PACKAGE_NAME);
if (drillLogger.getAppender("STDOUT") != null) {
return;
}
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
ple = new PatternLayoutEncoder();
ple.setPattern(builder.consoleFormat);
ple.setContext(lc);
ple.start();
appender = new ConsoleAppender<>();
appender.setContext(lc);
appender.setName("Console");
appender.setEncoder(ple);
appender.start();
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.addAppender(appender);
drillLogger.addAppender(appender);
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project SmartApplianceEnabler by camueller.
the class Application method configureLogging.
public static void configureLogging(ch.qos.logback.classic.Level level, String file, boolean additive) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.getFrameworkPackages().add(ApplianceLogger.class.getPackage().getName());
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = null;
if (file != null) {
fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setFile(file);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
}
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("de.avanux");
if (fileAppender != null) {
logger.addAppender(fileAppender);
}
logger.setLevel(level);
logger.setAdditive(additive);
if (fileAppender != null) {
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(fileAppender);
}
logger.info("Logging configured with log level " + level);
// external classes
ch.qos.logback.classic.Logger loggerRetrieveRemoteDescriptors = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.fourthline.cling.protocol.RetrieveRemoteDescriptors");
loggerRetrieveRemoteDescriptors.setLevel(Level.ERROR);
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project cdap-ingest by caskdata.
the class FileTailerIT method getTimeLogger.
private Logger getTimeLogger(String file) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName("File Tailer IT");
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(file + "%d{yyyy-MM-dd_HH-mm}");
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("%msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures the logger
Logger logger = loggerContext.getLogger(FileTailerIT.class.getName() + "time");
logger.setLevel(Level.DEBUG);
logger.addAppender(fileAppender);
return logger;
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project cdap-ingest by caskdata.
the class TailerLogUtils method getSizeLogger.
public static Logger getSizeLogger(String file, String fileSize) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setFileNamePattern(file + "%i");
rollingPolicy.setParent(fileAppender);
rollingPolicy.start();
rollingPolicy.setMaxIndex(100);
fileAppender.setRollingPolicy(rollingPolicy);
SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setContext(loggerContext);
triggeringPolicy.setMaxFileSize(fileSize);
triggeringPolicy.start();
fileAppender.setTriggeringPolicy(triggeringPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("[%d %-5p %c{1}] %msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures logger
Logger rootLogger = loggerContext.getLogger(BaseTailerTest.class.getName() + "size");
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
return rootLogger;
}
Aggregations