Java Code Examples for com.codahale.metrics.logback.InstrumentedAppender#start()
The following examples show how to use
com.codahale.metrics.logback.InstrumentedAppender#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaleenLogging.java From baleen with Apache License 2.0 | 5 votes |
/** * Configure logging based on a list of builders provided to it. Injects the configured logging to * replace the default UIMA loggers, and also sets up metrics on the logging. * * @param builders The builders to use to configure the logging */ public void configure(List<BaleenLoggerBuilder> builders) { // Install JUL to SLF4J handling (JUL is default for UIMA) SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); // Configure Logback LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); // Install the level change propagator to reduce the impact of JUL logging context.addListener(new LevelChangePropagator()); // Remove all the existing appenders rootLogger.detachAndStopAllAppenders(); for (BaleenLoggerBuilder builder : builders) { PatternLayoutEncoder ple = new PatternLayoutEncoder(); ple.setCharset(StandardCharsets.UTF_8); ple.setContext(context); ple.setPattern(builder.getPattern()); ple.start(); Appender<ILoggingEvent> appender = builder.build(context, ple); if (!appender.isStarted()) { appender.start(); } rootLogger.addAppender(appender); } LOGGER.debug("Adding instrumented metrics for logging"); // Add an instrumented appender so we get the information about logging // through metrics InstrumentedAppender instrumentedAppender = new InstrumentedAppender(MetricsFactory.getInstance().getRegistry()); instrumentedAppender.setContext(context); instrumentedAppender.start(); rootLogger.addAppender(instrumentedAppender); }
Example 2
Source File: ChassisConfiguration.java From chassis with Apache License 2.0 | 5 votes |
/** * 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; }