use of ch.qos.logback.classic.LoggerContext in project cdap-ingest by caskdata.
the class TailerLogUtils method getSizeLogger.
public static Logger getSizeLogger(String file, String fileSize) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setFileNamePattern(file + "%i");
rollingPolicy.setParent(fileAppender);
rollingPolicy.start();
rollingPolicy.setMaxIndex(100);
fileAppender.setRollingPolicy(rollingPolicy);
SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setContext(loggerContext);
triggeringPolicy.setMaxFileSize(fileSize);
triggeringPolicy.start();
fileAppender.setTriggeringPolicy(triggeringPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("[%d %-5p %c{1}] %msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures logger
Logger rootLogger = loggerContext.getLogger(BaseTailerTest.class.getName() + "size");
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
return rootLogger;
}
use of ch.qos.logback.classic.LoggerContext in project camel by apache.
the class ITestApplication method overrideLoggingConfig.
private static void overrideLoggingConfig() {
URL logbackFile = ITestApplication.class.getResource("/spring-logback.xml");
if (logbackFile != null) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
// Call context.reset() to clear any previous configuration, e.g. default
// configuration. For multi-step configuration, omit calling context.reset().
context.reset();
configurator.doConfigure(logbackFile);
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
}
use of ch.qos.logback.classic.LoggerContext in project weave by continuuity.
the class ServiceMain method doMain.
protected final void doMain(final ZKClientService zkClientService, final Service service) throws ExecutionException, InterruptedException {
configureLogger();
final String serviceName = service.toString();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Services.chainStop(service, zkClientService);
}
});
// Listener for state changes of the service
ListenableFuture<Service.State> completion = Services.getCompletionFuture(service);
// Starts the service
LOG.info("Starting service {}.", serviceName);
Futures.getUnchecked(Services.chainStart(zkClientService, service));
LOG.info("Service {} started.", serviceName);
try {
completion.get();
LOG.info("Service {} completed.", serviceName);
} catch (Throwable t) {
LOG.warn("Exception thrown from service {}.", serviceName, t);
throw Throwables.propagate(t);
} finally {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (loggerFactory instanceof LoggerContext) {
((LoggerContext) loggerFactory).stop();
}
}
}
use of ch.qos.logback.classic.LoggerContext in project dropwizard by dropwizard.
the class LogbackClassicRequestLogFactory method build.
public RequestLog build(String name) {
final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
logger.setAdditive(false);
final LoggerContext context = logger.getLoggerContext();
final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new NullLevelFilterFactory<>();
final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
final LayoutFactory<ILoggingEvent> layoutFactory = (c, tz) -> new RequestLogLayout();
final AppenderAttachableImpl<ILoggingEvent> attachable = new AppenderAttachableImpl<>();
for (AppenderFactory<ILoggingEvent> appender : appenders) {
attachable.addAppender(appender.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
}
return new DropwizardSlf4jRequestLog(attachable, timeZone);
}
use of ch.qos.logback.classic.LoggerContext in project dropwizard by dropwizard.
the class ConsoleAppenderFactoryTest method defaultIsNotNeverBlock.
@Test
public void defaultIsNotNeverBlock() throws Exception {
ConsoleAppenderFactory<ILoggingEvent> consoleAppenderFactory = new ConsoleAppenderFactory<>();
// default neverBlock
AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
assertThat(asyncAppender.isNeverBlock()).isFalse();
}
Aggregations