use of ch.qos.logback.classic.LoggerContext in project openhab1-addons by openhab.
the class LoggingPersistenceService method createNewAppender.
protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(pattern);
encoder.start();
FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
appender.setAppend(true);
appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
appender.setEncoder(encoder);
appender.setContext(context);
appender.start();
return appender;
}
use of ch.qos.logback.classic.LoggerContext in project chassis by Kixeye.
the class AppMain method initializeLogging.
private static void initializeLogging(Arguments arguments) {
//need to exclude logback from their project dependencies and initialize their own logging
try {
AppMain.class.getClassLoader().loadClass("ch.qos.logback.classic.LoggerContext");
} catch (ClassNotFoundException e) {
System.err.println("No Logback found in classpath. Skipping logging initialization. This is expected if you are configuring the logging system yourself. If you are not configuring logging yourself and would like to use logging provided by java-bootstrap, ensure that the Logback dependency jar exists in your classpath.");
return;
}
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
BasicConfigurator.configure(context);
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
Level level = Level.valueOf(arguments.logLevel.name().toUpperCase());
logger.setLevel(level);
logger.info("Initialized logging at {} level", level);
}
use of ch.qos.logback.classic.LoggerContext in project chassis by Kixeye.
the class ChassisConfiguration method metricRegistry.
/**
* Initializes the metrics registry
*
* @return metric registry bean
*/
@Bean
public MetricRegistry metricRegistry() {
final MetricRegistry bean = new MetricRegistry();
// add JVM metrics
bean.register("jvm.gc", new GarbageCollectorMetricSet());
bean.register("jvm.memory", new MemoryUsageGaugeSet());
bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
bean.register("jvm.fd", new FileDescriptorRatioGauge());
bean.register("jvm.load-average", new Gauge<Double>() {
private OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
public Double getValue() {
try {
return mxBean.getSystemLoadAverage();
} catch (Exception e) {
// not supported
return -1d;
}
}
});
// add Logback metrics
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender appender = new InstrumentedAppender(bean);
appender.setContext(root.getLoggerContext());
appender.start();
root.addAppender(appender);
return bean;
}
use of ch.qos.logback.classic.LoggerContext in project chassis by Kixeye.
the class FlumeLoggerLoader method installFlumeAppender.
public synchronized void installFlumeAppender() {
LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
appender.setContext(logContext);
appender.start();
Logger logger = logContext.getLogger(Logger.ROOT_LOGGER_NAME);
if (logger.getAppender(appender.getName()) == null) {
logger.addAppender(appender);
}
}
use of ch.qos.logback.classic.LoggerContext in project chassis by Kixeye.
the class FlumeLoggerLoader method uninstallFlumeAppender.
public synchronized void uninstallFlumeAppender() {
LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
appender.setContext(logContext);
appender.stop();
Logger logger = logContext.getLogger(Logger.ROOT_LOGGER_NAME);
if (logger.getAppender(appender.getName()) != null) {
logger.detachAppender(appender);
}
}
Aggregations