Created
July 6, 2016 18:22
-
-
Save aakashbapna/23b40959857b012b714a5a007d0f7987 to your computer and use it in GitHub Desktop.
Scalyr dropwizard integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ScalyrBundle<T extends Configuration> implements ConfiguredBundle<T> { | |
@Override | |
public void initialize(final Bootstrap<?> bootstrap) { | |
} | |
public abstract ScalyrConfiguration getConfiguration(T configuration); | |
@Override | |
public void run(T t, Environment environment) throws Exception { | |
final ScalyrConfiguration configuration = getConfiguration(t); | |
if(configuration.getEnabled()) { | |
final ScalyrAppender appender = new ScalyrAppender(); | |
LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory(); | |
appender.setContext(context); | |
appender.setApiKey(configuration.getApiKey()); | |
appender.setServerHost(configuration.getHostName()); | |
appender.start(); | |
final Logger root = (Logger) LoggerFactory.getLogger( | |
org.slf4j.Logger.ROOT_LOGGER_NAME); | |
root.addAppender(appender); | |
root.debug("Started scalyr appender for host:"+configuration.getHostName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment