Advertisement
Guest User

Untitled

a guest
May 5th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class InstrumentedLoggerSingleton implements ConfigurationListener
  2. {
  3. private static final Logger LOG = LoggerFactory.getLogger(InstrumentedLoggerSingleton.class);
  4. private static InstrumentedLoggerSingleton instance = null;
  5.  
  6. private final InstrumentedAppender appender;
  7. private final Filter filter = null;
  8. private final PatternLayout layout = null;
  9.  
  10. public static synchronized InstrumentedLoggerSingleton getInstance()
  11. {
  12. if (instance == null)
  13. {
  14. instance = new InstrumentedLoggerSingleton();
  15. }
  16.  
  17. return instance;
  18. }
  19.  
  20. private InstrumentedLoggerSingleton()
  21. {
  22. appender = new InstrumentedAppender(MetricRegistrySingleton.getInstance().getMetricsRegistry(), filter, layout, false);
  23. appender.start();
  24. instrument();
  25. }
  26.  
  27. private void instrument()
  28. {
  29. LoggerContext context = (LoggerContext) LogManager.getContext(false);
  30. Configuration config = context.getConfiguration();
  31.  
  32. config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, Level.ALL, filter);
  33. config.addListener(this);
  34. context.updateLoggers(config);
  35.  
  36. LOG.info("Logging configuration has been modified and a new InstrumentedAppender has been configured on the root logger");
  37. }
  38.  
  39. public void onChange(Reconfigurable reconfigurable)
  40. {
  41. instrument();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement