use of org.apache.logging.log4j.core.config.Configuration in project spring-boot by spring-projects.
the class Log4J2LoggingSystem method getLoggerConfigurations.
@Override
public List<LoggerConfiguration> getLoggerConfigurations() {
List<LoggerConfiguration> result = new ArrayList<>();
Configuration configuration = getLoggerContext().getConfiguration();
for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
result.add(convertLoggerConfiguration(loggerConfig));
}
Collections.sort(result, CONFIGURATION_COMPARATOR);
return result;
}
use of org.apache.logging.log4j.core.config.Configuration in project torodb by torodb.
the class Log4jUtils method appendToLogFile.
public static void appendToLogFile(String logFile) {
LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = coreContext.getConfiguration();
final Layout<? extends Serializable> layout = PatternLayout.newBuilder().withConfiguration(configuration).withPattern("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n").build();
final Appender appender = FileAppender.createAppender(logFile, "false", "false", "File", "true", "false", null, null, layout, null, "false", null, configuration);
appender.start();
for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
configuration.addLoggerAppender(coreContext.getLogger(loggerConfig.getName()), appender);
}
}
use of org.apache.logging.log4j.core.config.Configuration in project spring-boot by spring-projects.
the class Log4J2LoggingSystemTests method noFile.
@Test
public void noFile() throws Exception {
this.loggingSystem.beforeInitialize();
this.logger.info("Hidden");
this.loggingSystem.initialize(null, null, null);
this.logger.info("Hello world");
String output = this.output.toString().trim();
Configuration configuration = this.loggingSystem.getConfiguration();
assertThat(output).contains("Hello world").doesNotContain("Hidden");
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
assertThat(configuration.getConfigurationSource().getFile()).isNotNull();
}
use of org.apache.logging.log4j.core.config.Configuration in project camel by apache.
the class LogBodyWithNewLineTest method setUp.
public void setUp() throws Exception {
super.setUp();
writer = new StringWriter();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Appender appender = WriterAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).build()).setTarget(writer).setName("Writer").build();
appender.start();
config.addAppender(appender);
config.getRootLogger().removeAppender("Writer");
config.getRootLogger().addAppender(appender, Level.INFO, null);
ctx.updateLoggers();
}
use of org.apache.logging.log4j.core.config.Configuration in project camel by apache.
the class LogVerifier method newAppender.
private Appender newAppender() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LogAppender appender = new LogAppender("cdi-rule");
appender.start();
config.addAppender(appender);
config.getRootLogger().removeAppender("cdi-rule");
config.getRootLogger().addAppender(appender, Level.TRACE, null);
ctx.updateLoggers();
return appender;
}
Aggregations