use of ch.qos.logback.classic.spi.ILoggingEvent in project uavstack by uavorg.
the class LogBackHookProxy method figureoutLogConfiguration.
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
while (appenders != null && appenders.hasNext()) {
LogProfileInfo logProfileInfo = new LogProfileInfo();
if (appid != null) {
logProfileInfo.setAppId(appid);
}
logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(LogProfileInfo.ENGINE, "logback");
Appender<ILoggingEvent> appender = appenders.next();
if (!(appender instanceof FileAppender<?>)) {
continue;
}
FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
@SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
Layout<?> layout = encoder.getLayout();
if (null != layout) {
if (layout instanceof PatternLayout) {
PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
} else if (layout instanceof HTMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
} else if (layout instanceof XMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
} else if (layout instanceof TTLLLayout) {
attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
}
}
logProfileInfo.setFilePath(fileAppender.getFile());
logProfileInfo.setAttributes(attributes);
list.add(logProfileInfo);
}
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project BIMserver by opensourceBIM.
the class LocalDevBimServerStarter method fixLogging.
/**
* Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
*
* @throws IOException
*/
private void fixLogging(BimServerConfig config) throws IOException {
Path logFolder = config.getHomeDir().resolve("logs");
if (!Files.isDirectory(logFolder)) {
Files.createDirectories(logFolder);
}
Path file = logFolder.resolve("bimserver.log");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
String filename = file.toAbsolutePath().toString();
if (lc instanceof LoggerContext) {
if (!lc.isStarted()) {
lc.start();
}
}
System.out.println("Logging to " + filename);
fileAppender.setFile(filename);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if (log.getLevel() != null) {
log.addAppender(fileAppender);
}
}
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarlint-core by SonarSource.
the class SonarLintLogging method init.
private static void init() {
ConsoleAppender<ILoggingEvent> defaultAppender = new ConsoleAppender<>();
defaultAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
defaultAppender.setName(DEFAULT_APPENDER_NAME);
LevelFilter levelFilter = new LevelFilter();
levelFilter.setLevel(Level.ERROR);
defaultAppender.addFilter(levelFilter);
// if output is not set for thread, keep default behavior (configured to stdout)
setCustomRootAppender(defaultAppender);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project qpid-broker-j by apache.
the class VirtualHostNameAndLevelLogInclusionRuleImplTest method testAsFilter.
public void testAsFilter() {
VirtualHostNameAndLevelLogInclusionRule<?> rule = createRule("org.apache.qpid", LogLevel.INFO);
Filter<ILoggingEvent> filter = rule.asFilter();
assertTrue("Unexpected filter instance", filter instanceof LoggerNameAndLevelFilter);
LoggerNameAndLevelFilter f = (LoggerNameAndLevelFilter) filter;
assertEquals("Unexpected log level", Level.INFO, f.getLevel());
assertEquals("Unexpected logger name", "org.apache.qpid", f.getLoggerName());
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project qpid-broker-j by apache.
the class QpidBrokerTestCase method getFileFromSiftingAppender.
private File getFileFromSiftingAppender(final ch.qos.logback.classic.Logger logger) {
String key = logger.getLoggerContext().getProperty(LogbackPropertyValueDiscriminator.CLASS_QUALIFIED_TEST_NAME);
for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) /* do nothing */
{
Appender<ILoggingEvent> appender = index.next();
if (appender instanceof SiftingAppender) {
SiftingAppender siftingAppender = (SiftingAppender) appender;
Appender subAppender = siftingAppender.getAppenderTracker().find(key);
if (subAppender instanceof FileAppender) {
return new File(((FileAppender) subAppender).getFile());
}
}
}
return null;
}
Aggregations