use of ch.qos.logback.classic.spi.ILoggingEvent in project platformlayer by platformlayer.
the class LogbackHook method append.
@Override
protected void append(E e) {
OpsContext opsContext = OpsContext.get();
if (opsContext != null) {
ILoggingEvent event = (ILoggingEvent) e;
// Note that we can get the unformatted message in getMessage(), presumably along with the parameters...
String message = event.getFormattedMessage();
Level level = event.getLevel();
int levelInt = level.toInt();
List<String[]> exceptionStacks = null;
IThrowableProxy throwableInformation = event.getThrowableProxy();
while (throwableInformation != null) {
String[] exceptionStackTrace = null;
StackTraceElementProxy[] trace = throwableInformation.getStackTraceElementProxyArray();
String exceptionMessage = throwableInformation.getMessage();
String exceptionClass = throwableInformation.getClassName();
if (trace != null) {
exceptionStackTrace = new String[1 + trace.length];
exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;
for (int i = 0; i < trace.length; i++) {
exceptionStackTrace[1 + i] = trace[i].getSTEAsString();
}
} else {
exceptionStackTrace = new String[1];
exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;
}
if (exceptionStacks == null) {
exceptionStacks = Lists.newArrayList();
}
exceptionStacks.add(exceptionStackTrace);
throwableInformation = throwableInformation.getCause();
}
if (message != null || exceptionStacks != null) {
opsContext.getJobLogger().logMessage(message, exceptionStacks, levelInt);
if (levelInt >= Level.ERROR_INT) {
// String key = "warn-" + OpsSystem.buildSimpleTimeString() + "-" + (System.nanoTime() % 1000);
if (opsContext != null) {
// && opsContext.getOperation() != null) {
if (exceptionStacks != null && !exceptionStacks.isEmpty()) {
String[] exceptionStack = exceptionStacks.get(0);
if (exceptionStack != null && exceptionStack.length > 0) {
message += "; " + exceptionStack[0];
}
}
opsContext.addWarning(null, message);
}
}
}
}
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project spring-boot by spring-projects.
the class LogbackConfigurationTests method filePatternCanBeOverridden.
@Test
public void filePatternCanBeOverridden() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
LoggerContext context = new LoggerContext();
configurator.setContext(context);
configurator.doConfigure(new File("src/test/resources/custom-file-log-pattern.xml"));
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(FileAppender.class);
Encoder<?> encoder = ((FileAppender<?>) appender).getEncoder();
assertThat(encoder).isInstanceOf(PatternLayoutEncoder.class);
assertThat(((PatternLayoutEncoder) encoder).getPattern()).isEqualTo("bar");
}
use of ch.qos.logback.classic.spi.ILoggingEvent 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.spi.ILoggingEvent 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.spi.ILoggingEvent in project sonarqube by SonarSource.
the class AppLogging method configureConsole.
/**
* Creates a non additive logger dedicated to printing message as is (ie. assuming they are already formatted).
*
* It creates a dedicated appender to the System.out which applies no formatting the logs it receives.
*/
private void configureConsole(LoggerContext loggerContext) {
ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(loggerContext, CONSOLE_PLAIN_APPENDER, "%msg%n");
Logger consoleLogger = loggerContext.getLogger(CONSOLE_LOGGER);
consoleLogger.setAdditive(false);
consoleLogger.addAppender(consoleAppender);
}
Aggregations