Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InstrumentedLoggerSingleton implements ConfigurationListener
- {
- private static final Logger LOG = LoggerFactory.getLogger(InstrumentedLoggerSingleton.class);
- private static InstrumentedLoggerSingleton instance = null;
- private final InstrumentedAppender appender;
- private final Filter filter = null;
- private final PatternLayout layout = null;
- public static synchronized InstrumentedLoggerSingleton getInstance()
- {
- if (instance == null)
- {
- instance = new InstrumentedLoggerSingleton();
- }
- return instance;
- }
- private InstrumentedLoggerSingleton()
- {
- appender = new InstrumentedAppender(MetricRegistrySingleton.getInstance().getMetricsRegistry(), filter, layout, false);
- appender.start();
- instrument();
- }
- private void instrument()
- {
- LoggerContext context = (LoggerContext) LogManager.getContext(false);
- Configuration config = context.getConfiguration();
- config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, Level.ALL, filter);
- config.addListener(this);
- context.updateLoggers(config);
- LOG.info("Logging configuration has been modified and a new InstrumentedAppender has been configured on the root logger");
- }
- public void onChange(Reconfigurable reconfigurable)
- {
- instrument();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement