ch.qos.logback.core.ContextBase Java Examples

The following examples show how to use ch.qos.logback.core.ContextBase. 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: AuditableLogbackThriftLoggerTest.java    From singer with Apache License 2.0 6 votes vote down vote up
public String initialize(String logFileDir, String topic, Class<?> thriftClazz) {
  File file = new File(logFileDir);
  if (file.exists()) {
    file.delete();
  }

  Appender<LogMessage> appender = null;
  try {
    appender = AppenderUtils.createFileRollingThriftAppender(
        new File(logFileDir), topic, 10000, new ContextBase(), 1);
    ThriftLogger logger = new AuditableLogbackThriftLogger(appender, topic, thriftClazz, true, 1.0);

    for (int i = 0; i < messages.length; i++) {
      ThriftMessage msg = new ThriftMessage();
      msg.setSequenceNum(i);
      msg.setPayload(("message" + i).getBytes());
      messages[i] = msg;
      logger.append(null, msg, System.nanoTime());
    }
    logger.close();
  } catch (Exception e) {
    e.printStackTrace();
    assert (false);
  }
  return logFileDir + "/" + topic;
}
 
Example #2
Source File: LogbackThriftLoggerTest.java    From singer with Apache License 2.0 6 votes vote down vote up
public String initialize(String logFileDir, String logFile) {
  File file = new File(logFileDir);
  if (file.exists()) {
    file.delete();
  }

  Appender<LogMessage> appender = null;
  try {
    appender = AppenderUtils.createFileRollingThriftAppender(
        new File(logFileDir), logFile, 10, new ContextBase(), 1);
    ThriftLogger logger = new LogbackThriftLogger("test_topic", appender);

    for (int i = 0; i < messages.length; i++) {
      LogMessage msg = new LogMessage();
      msg.setMessage(("message" + i).getBytes()).setTimestampInNanos(System.nanoTime());
      messages[i] = msg;
      logger.append(null, msg.getMessage(), msg.getTimestampInNanos());
    }
    logger.close();
  } catch (Exception e) {
    e.printStackTrace();
    assert (false);
  }

  return logFileDir + "/" + logFile;
}
 
Example #3
Source File: LogbackConfigurationListener.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
    final String settings = environment.getProperty("logging.config.src");
    if (StringUtils.hasText(settings)) {
        try {
            final ContextBase context = (ContextBase) StaticLoggerBinder.getSingleton().getLoggerFactory();
            final JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            LOG.info("try to update logback configuration to {}", settings);
            context.reset();
            configurator.doConfigure(new ByteArrayInputStream(settings.getBytes()));
        } catch (JoranException e) {
            LOG.error("can't load settings", e);
        }
    }
}
 
Example #4
Source File: LogbackModule.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
private Appender<ILoggingEvent> createConsoleAppender(LoggerContext lc, LogbackOptions options) {
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern(options.pattern);
    ple.setContext(lc);
    ple.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
    appender.setContext(new ContextBase());
    appender.setEncoder(ple);
    appender.start();
    return appender;
}
 
Example #5
Source File: ExceptionConverterTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void errorsIfTargetClassPropertyIsEmpty() throws Exception {
    ContextBase contextBase = new ContextBase();
    StatusManager statusManager = mock(StatusManager.class);
    contextBase.setStatusManager(statusManager);
    ExceptionConverter converter = newExceptionConverter(contextBase);
    converter.getContext()
            .putProperty(TARGET_CLASSES_PROPERTY_NAME, "");

    ILoggingEvent loggingEvent = newErrorLoggingEvent(new TargetClass().blow());
    converter.convert(loggingEvent);

    verify(statusManager).add(any(ErrorStatus.class));
}
 
Example #6
Source File: ExceptionConverterTest.java    From styx with Apache License 2.0 4 votes vote down vote up
private ExceptionConverter newExceptionConverter() {
    return newExceptionConverter(new ContextBase());
}
 
Example #7
Source File: ExceptionConverterTest.java    From styx with Apache License 2.0 4 votes vote down vote up
private ExceptionConverter newExceptionConverter(ContextBase context) {
    ExceptionConverter converter = new ExceptionConverter();
    converter.setContext(context);
    converter.start();
    return converter;
}