use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project qpid-broker-j by apache.
the class StartupAppender method logToConsole.
public void logToConsole() {
Context context = getContext();
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(context);
PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder.setContext(context);
// added MDC variable 'qpid.log.prefix' for test purposes
patternLayoutEncoder.setPattern("%X{qpid.log.prefix}%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
patternLayoutEncoder.start();
consoleAppender.addFilter(new Filter<ILoggingEvent>() {
@Override
public FilterReply decide(final ILoggingEvent event) {
return event.getLevel().isGreaterOrEqual(_consoleAppenderAcceptLogLevel) ? FilterReply.ACCEPT : FilterReply.DENY;
}
});
consoleAppender.setEncoder(patternLayoutEncoder);
consoleAppender.start();
replayAccumulatedEvents(consoleAppender);
consoleAppender.stop();
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project apps-android-commons by commons-app.
the class FileLoggingTree method configureLogger.
/**
* Configures the logger with a file size rolling policy (SizeBasedTriggeringPolicy)
* https://github.com/tony19/logback-android/wiki
* @param logDir
*/
private void configureLogger(String logDir) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
rollingFileAppender.setContext(loggerContext);
rollingFileAppender.setFile(logDir + "/" + logFileName + ".0.log");
rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(4);
rollingPolicy.setParent(rollingFileAppender);
rollingPolicy.setFileNamePattern(logDir + "/" + logFileName + ".%i.log");
rollingPolicy.start();
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
triggeringPolicy.setContext(loggerContext);
triggeringPolicy.setMaxFileSize(String.format(Locale.ENGLISH, "%dKB", fileSize));
triggeringPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%-27(%date{ISO8601}) [%-5level] [%thread] %msg%n");
encoder.start();
rollingFileAppender.setEncoder(encoder);
rollingFileAppender.setRollingPolicy(rollingPolicy);
rollingFileAppender.setTriggeringPolicy(triggeringPolicy);
rollingFileAppender.start();
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.addAppender(rollingFileAppender);
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class CeProcessLoggingTest method startup_logger_prints_to_only_to_system_out.
@Test
public void startup_logger_prints_to_only_to_system_out() {
LoggerContext ctx = underTest.configure(props);
Logger startup = ctx.getLogger("startup");
assertThat(startup.isAdditive()).isFalse();
Appender appender = startup.getAppender("CONSOLE");
assertThat(appender).isInstanceOf(ConsoleAppender.class);
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class CeProcessLoggingTest method log_to_ce_file.
@Test
public void log_to_ce_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_ce");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.log").getAbsolutePath());
assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level ce[%X{ceTaskUuid}][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class LogbackHelper method newConsoleAppender.
/**
* Creates a new {@link ConsoleAppender} to {@code System.out} with the specified name and log pattern.
*
* @see #buildLogPattern(RootLoggerConfig)
*/
public ConsoleAppender<ILoggingEvent> newConsoleAppender(Context loggerContext, String name, String logPattern) {
PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
consoleEncoder.setContext(loggerContext);
consoleEncoder.setPattern(logPattern);
consoleEncoder.start();
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(loggerContext);
consoleAppender.setEncoder(consoleEncoder);
consoleAppender.setName(name);
consoleAppender.setTarget("System.out");
consoleAppender.start();
return consoleAppender;
}
Aggregations