Java Code Examples for ch.qos.logback.classic.spi.ILoggingEvent

The following examples show how to use ch.qos.logback.classic.spi.ILoggingEvent. These examples are extracted from open source projects. 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 Project: GOAi   Source File: Minister.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 初始化日志
 */
private Logger initLog(Integer id) {
    // 实例化log,每个实例存放地方不一致
    ch.qos.logback.classic.Logger logger = ((ch.qos.logback.classic.Logger)
            LoggerFactory.getLogger(this.secretary.strategyName + "-" + id));

    LoggerContext context = logger.getLoggerContext();

    TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>();
    policy.setFileNamePattern(OptionHelper.substVars(
            "logs/past/" + id + "/%d{yyyy-MM-dd}.log.gz", context));
    policy.setMaxHistory(31);
    policy.setContext(context);

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %5level - [%thread] %logger : %msg%n");

    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    appender.setContext(context);
    appender.setName(this.secretary.strategyName + "-" + id);
    appender.setFile(OptionHelper.substVars("logs/" + id + "/log.log", context));
    appender.setAppend(true);
    // 同一文件多输入完整检查
    appender.setPrudent(false);
    appender.setRollingPolicy(policy);
    appender.setEncoder(encoder);
    policy.setParent(appender);

    policy.start();
    encoder.start();
    appender.start();

    logger.setLevel(Level.INFO);
    // 终端输出
    logger.setAdditive(true);
    logger.addAppender(appender);

    return logger;
}
 
Example 2
Source Project: ehcache3-samples   Source File: LoggingConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
    log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
    OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
    onMarkerMetricsEvaluator.setContext(context);
    onMarkerMetricsEvaluator.addMarker("metrics");
    onMarkerMetricsEvaluator.start();
    EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
    metricsFilter.setContext(context);
    metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
    metricsFilter.setOnMatch(FilterReply.DENY);
    metricsFilter.start();

    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
            Appender<ILoggingEvent> appender = it.next();
            if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
                log.debug("Filter metrics logs from the {} appender", appender.getName());
                appender.setContext(context);
                appender.addFilter(metricsFilter);
                appender.start();
            }
        }
    }
}
 
Example 3
Source Project: cachecloud   Source File: ErrorStatisticsAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (event == null) {
        return;
    }
    if (event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        IThrowableProxy throwableProxy = event.getThrowableProxy();
        if (throwableProxy != null) {
        	//接口名
            String errorClassName = throwableProxy.getClassName();
            if (errorClassName != null && !"".equals(errorClassName.trim())) {
            	//写入AtomicLongMap并计数
                ERROR_NAME_VALUE_MAP.getAndIncrement(errorClassName);
            }
        }
    }
}
 
Example 4
Source Project: hub-detect   Source File: DiagnosticLogger.java    License: Apache License 2.0 6 votes vote down vote up
private FileAppender<ILoggingEvent> addAppender(final String file) {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> appender;
    appender = new FileAppender<>();
    appender.setFile(file);
    appender.setEncoder(ple);
    appender.setContext(lc);
    appender.start();

    final ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LOGBACK_LOGGER_NAME);
    logbackLogger.addAppender(appender);
    logbackLogger.setLevel(Level.ALL);

    return appender;
}
 
Example 5
Source Project: synopsys-detect   Source File: DiagnosticLogger.java    License: Apache License 2.0 6 votes vote down vote up
private FileAppender<ILoggingEvent> addAppender(final String file) {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();

    final FileAppender<ILoggingEvent> appender;
    appender = new FileAppender<>();
    appender.setFile(file);
    appender.setEncoder(ple);
    appender.setContext(lc);
    final ThresholdFilter levelFilter = new ThresholdFilter();
    levelFilter.setLevel(this.level.levelStr);
    levelFilter.start();
    appender.addFilter(levelFilter);

    appender.start();

    final ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    logbackLogger.addAppender(appender);

    return appender;
}
 
Example 6
Source Project: skywalking   Source File: ContainerLogger.java    License: Apache License 2.0 6 votes vote down vote up
public ContainerLogger(final Path logDirectory, final String container) {

        final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        final PatternLayoutEncoder encoder = new PatternLayoutEncoder();

        encoder.setPattern("%d{HH:mm:ss.SSS} %-5level %logger{36}.%M - %msg%n");
        encoder.setContext(context);
        encoder.start();

        final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
        fileAppender.setFile(logDirectory.resolve(container).toAbsolutePath().toString());
        fileAppender.setEncoder(encoder);
        fileAppender.setContext(context);
        fileAppender.start();

        final ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(container);
        logger.addAppender(fileAppender);
        logger.setLevel(Level.DEBUG);
        logger.setAdditive(false);

        this.delegate = logger;
    }
 
Example 7
Source Project: jframework   Source File: DingTalkAppender.java    License: Apache License 2.0 6 votes vote down vote up
private String transformStackTrace(ILoggingEvent event) {
    String exception = "";
    IThrowableProxy throwableProxy =  event.getThrowableProxy();
    if (throwableProxy != null) {
        exception = ThrowableProxyUtil.asString(throwableProxy);
    }

    StackTraceElement[] callerData = event.getCallerData();
    StackTraceElement stackTraceElement = callerData[0];

    String time = DEFAULT_DATE_FORMAT.format(new Date(event.getTimeStamp()));
    String threadName = event.getThreadName();
    String level = event.getLevel().toString();
    String logger = event.getLoggerName();
    String msg = event.getFormattedMessage();
    String className = stackTraceElement.getClassName();
    String method = stackTraceElement.getMethodName();
    int lineNumber = stackTraceElement.getLineNumber();

    return String.format(FORMAT_MESSAGE, time, threadName, level, logger, className, method, lineNumber, exception, msg);
}
 
Example 8
@Test
public void testDecideForWildcardLoggerName() throws Exception
{
    LoggerNameAndLevelFilter filter = new LoggerNameAndLevelFilter("org.apache.qpid.server.*", Level.INFO);

    ILoggingEvent event = mock(ILoggingEvent.class);
    when(event.getLevel()).thenReturn(Level.INFO);
    when(event.getLoggerName()).thenReturn("org.apache.qpid.server.foo");
    assertEquals("Unexpected reply for matching logger name and log level",
                        FilterReply.ACCEPT,
                        filter.decide(event));

    when(event.getLoggerName()).thenReturn("org.apache.qpid.foo");
    assertEquals("Unexpected reply for non matching logger name but matching log level",
                        FilterReply.NEUTRAL,
                        filter.decide(event));

    when(event.getLoggerName()).thenReturn("org.apache.qpid.server.foo");
    when(event.getLevel()).thenReturn(Level.DEBUG);
    assertEquals("Unexpected reply for matching logger name but non matching log level",
                        FilterReply.NEUTRAL,
                        filter.decide(event));
}
 
Example 9
Source Project: armeria   Source File: RequestContextExportingAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {
    if (exporter == null) {
        exporter = builder.build();
    }
    final Map<String, String> contextMap = exporter.export();
    if (!contextMap.isEmpty()) {
        final Map<String, String> originalMdcMap = eventObject.getMDCPropertyMap();
        final Map<String, String> mdcMap;

        if (!originalMdcMap.isEmpty()) {
            mdcMap = new UnionMap<>(contextMap, originalMdcMap);
        } else {
            mdcMap = contextMap;
        }
        eventObject = new LoggingEventWrapper(eventObject, mdcMap);
    }
    aai.appendLoopOnAppenders(eventObject);
}
 
Example 10
Source Project: NationStatesPlusPlus   Source File: LoggingFilter.java    License: MIT License 6 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
	final IThrowableProxy throwableProxy = event.getThrowableProxy();
	if (throwableProxy == null) {
		return FilterReply.NEUTRAL;
	}

	if (!(throwableProxy instanceof ThrowableProxy)) {
		return FilterReply.NEUTRAL;
	}

	final ThrowableProxy throwableProxyImpl = (ThrowableProxy) throwableProxy;
	final Throwable throwable = throwableProxyImpl.getThrowable();
	if (java.nio.channels.ClosedChannelException.class.isInstance(throwable)) {
		return FilterReply.DENY;
	}

	return FilterReply.NEUTRAL;
}
 
Example 11
Source Project: qpid-broker-j   Source File: JDBCLoggerHelper.java    License: Apache License 2.0 6 votes vote down vote up
Appender<ILoggingEvent> createAppenderInstance(final Context context,
                                               final ConfiguredObject<?> logger,
                                               final JDBCSettings settings)
{
    try
    {
        final JDBCSettingsDBNameResolver dbNameResolver = new JDBCSettingsDBNameResolver(settings);
        final ConnectionSource connectionSource = createConnectionSource(context, logger, settings);
        final DBAppender appender = new DBAppender();
        appender.setDbNameResolver(dbNameResolver);
        appender.setConnectionSource(connectionSource);
        appender.setContext(context);
        appender.start();
        return appender;
    }
    catch (Exception e)
    {
        LOGGER.error("Failed to create appender", e);
        throw new IllegalConfigurationException("Cannot create appender");
    }
}
 
Example 12
@Test(timeout = 5000)
public void test_get_only_logged_once() throws Exception {
    final String msg = "Can't open directory channel. Log directory fsync won't be performed.";

    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final Iterator<Appender<ILoggingEvent>> appenderIterator = rootLogger.iteratorForAppenders();

    final Appender<ILoggingEvent> next = appenderIterator.next();
    next.addFilter(createFilter(countDownLatch, msg));

    XodusFileDataWriterLogLevelModificator.fileDataWriterLogger.warn(msg);
    XodusFileDataWriterLogLevelModificator.fileDataWriterLogger.warn(msg);
    XodusFileDataWriterLogLevelModificator.fileDataWriterLogger.warn(msg);
    XodusFileDataWriterLogLevelModificator.fileDataWriterLogger.warn(msg);
    XodusFileDataWriterLogLevelModificator.fileDataWriterLogger.warn(msg);

    assertEquals(false, countDownLatch.await(3, TimeUnit.SECONDS));
}
 
Example 13
@Override
protected void append (ILoggingEvent event)
{
    if (!isReady()) {
        backlog.add(event);
    } else {
        if (!backlog.isEmpty()) {
            for (ILoggingEvent evt : backlog) {
                publish(evt);
            }

            backlog.clear();
        }

        publish(event);
    }
}
 
Example 14
Source Project: logging-java   Source File: LoggerThresholdFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    if(!isStarted())
        return FilterReply.NEUTRAL;

    if(logger != null && !event.getLoggerName().startsWith(logger))
        return FilterReply.NEUTRAL;

    if(exceptLogger != null && event.getLoggerName().startsWith(exceptLogger))
        return FilterReply.NEUTRAL;

    if(level != null && !event.getLevel().isGreaterOrEqual(level))
        return FilterReply.DENY;

    return FilterReply.NEUTRAL;
}
 
Example 15
Source Project: orion.server   Source File: LogService.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<FileAppender<ILoggingEvent>> getFileAppenders() {
	List<FileAppender<ILoggingEvent>> fileAppenders = new LinkedList<FileAppender<ILoggingEvent>>();

	for (Logger logger : getLoggers()) {
		for (Iterator<Appender<ILoggingEvent>> index = logger
				.iteratorForAppenders(); index.hasNext();) {

			Appender<ILoggingEvent> appender = index.next();
			if (appender instanceof FileAppender)
				fileAppenders.add((FileAppender<ILoggingEvent>) appender);
		}
	}

	return fileAppenders;
}
 
Example 16
Source Project: logback-flume-appender   Source File: FlumeLogstashV1Appender.java    License: MIT License 6 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {

  if (flumeManager != null) {
    try {
      String body = layout != null ? layout.doLayout(eventObject) : eventObject.getFormattedMessage();
      Map<String, String> headers = new HashMap<String, String>();
      if(additionalAvroHeaders != null) {
        headers.putAll(additionalAvroHeaders);
      }
      headers.putAll(extractHeaders(eventObject));

      Event event = EventBuilder.withBody(StringUtils.strip(body), UTF_8, headers);

      flumeManager.send(event);
    } catch (Exception e) {
      addError(e.getLocalizedMessage(), e);
    }
  }

}
 
Example 17
Source Project: cubeai   Source File: LoggingConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
    log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
    OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
    onMarkerMetricsEvaluator.setContext(context);
    onMarkerMetricsEvaluator.addMarker("metrics");
    onMarkerMetricsEvaluator.start();
    EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
    metricsFilter.setContext(context);
    metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
    metricsFilter.setOnMatch(FilterReply.DENY);
    metricsFilter.start();

    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
            Appender<ILoggingEvent> appender = it.next();
            if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
                log.debug("Filter metrics logs from the {} appender", appender.getName());
                appender.setContext(context);
                appender.addFilter(metricsFilter);
                appender.start();
            }
        }
    }
}
 
Example 18
private void doFailSafeConfiguration() {
    // Not really fail-safe, just less likely to fail
    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    rootLogger.addAppender(appender);
    appender.setContext(context);
    appender.setTarget("System.err");

    PatternLayout layout = new PatternLayout();
    appender.setLayout(layout);
    layout.setPattern("%msg%n%ex");
    layout.setContext(context);

    layout.start();
    appender.start();
}
 
Example 19
Source Project: cubeai   Source File: LoggingConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
    log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
    OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
    onMarkerMetricsEvaluator.setContext(context);
    onMarkerMetricsEvaluator.addMarker("metrics");
    onMarkerMetricsEvaluator.start();
    EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
    metricsFilter.setContext(context);
    metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
    metricsFilter.setOnMatch(FilterReply.DENY);
    metricsFilter.start();

    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
            Appender<ILoggingEvent> appender = it.next();
            if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
                log.debug("Filter metrics logs from the {} appender", appender.getName());
                appender.setContext(context);
                appender.addFilter(metricsFilter);
                appender.start();
            }
        }
    }
}
 
Example 20
Source Project: bither-desktop-java   Source File: LogbackFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static ConsoleAppender<ILoggingEvent> buildConsoleAppender(LoggingConfiguration.ConsoleConfiguration console,
                                                                  LoggerContext context,
                                                                  String logFormat) {
    final LogFormatter formatter = new LogFormatter(context, console.getTimeZone());
    if (logFormat != null) {
        formatter.setPattern(logFormat);
    }
    formatter.start();

    final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setLayout(formatter);
    addThresholdFilter(appender, console.getThreshold());
    appender.start();

    return appender;
}
 
Example 21
Source Project: james-project   Source File: PeriodicalHealthChecksTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void startShouldLogPeriodicallyWhenDegraded() {
    ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);

    TestingHealthCheck degraded = () -> Mono.just(Result.degraded(TestingHealthCheck.COMPONENT_NAME, "cause"));
    testee = new PeriodicalHealthChecks(ImmutableSet.of(degraded),
        scheduler,
        new PeriodicalHealthChecksConfiguration(PERIOD));
    testee.start();

    scheduler.advanceTimeBy(PERIOD);
    assertThat(loggingEvents.list).hasSize(1)
        .allSatisfy(loggingEvent -> {
            assertThat(loggingEvent.getLevel()).isEqualTo(Level.WARN);
            assertThat(loggingEvent.getFormattedMessage()).contains("DEGRADED", "testing", "cause");
        });
}
 
Example 22
Source Project: qpid-broker-j   Source File: AbstractLogger.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void postResolveChildren()
{
    super.postResolveChildren();

    LoggerContext loggerContext = ROOT_LOGGER.getLoggerContext();
    Appender<ILoggingEvent> appender = createAppenderInstance(loggerContext);
    appender.setName(getName());
    appender.setContext(loggerContext);

    for(LogInclusionRule logInclusionRule : getLogInclusionRules())
    {
        _compositeFilter.addLogInclusionRule((LogBackLogInclusionRule)logInclusionRule);
    }
    appender.addFilter(_compositeFilter);

    ROOT_LOGGER.addAppender(appender);
    appender.start();

    // TODO generalise for virtualhost too
    StartupAppender startupAppender = (StartupAppender) ROOT_LOGGER.getAppender(StartupAppender.class.getName());
    if (startupAppender != null)
    {
        startupAppender.replayAccumulatedEvents(appender);
    }
}
 
Example 23
Source Project: gocd   Source File: DefaultPluginLoggingService.java    License: Apache License 2.0 5 votes vote down vote up
private void initializeLoggerForPluginId(String pluginId) {
    if (alreadyInitialized(pluginId)) {
        return;
    }

    synchronized (pluginId.intern()) {
        if (alreadyInitialized(pluginId)) {
            return;
        }

        synchronized (appenderCreationLock) {
            FileAppender<ILoggingEvent> pluginAppender = getAppender(pluginId);

            ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(PLUGIN_LOGGER_PREFIX + "." + pluginId);
            logger.setAdditive(false);
            logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId));
            logger.addAppender(pluginAppender);

            if (systemEnvironment.consoleOutToStdout()) {
                ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
                consoleAppender.setEncoder(LogHelper.encoder("%d{ISO8601} %5p [%t] %c{1}:%L [plugin-" + pluginId + "] - %m%n"));
                logger.setAdditive(false);
                logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId));
                consoleAppender.start();
                logger.addAppender(consoleAppender);
            }

            loggingServiceLogger.debug("Plugin with ID: " + pluginId + " will log to: " + pluginAppender.rawFileProperty());
        }
    }
}
 
Example 24
@Test
public void testWriteXxxxxResult() throws TechnicalException {
    final OutputConsoleDataProvider outputConsoleDataProvider = new OutputConsoleDataProvider();
    outputConsoleDataProvider.prepare("hello");
    Assert.assertTrue(true);

    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    final TestAppender<ILoggingEvent> appender = new TestAppender<>();
    appender.start();
    logger.addAppender(appender);
    outputConsoleDataProvider.writeFailedResult(1, "UT Failed Message");
    List<ILoggingEvent> log = appender.getLog();
    Assert.assertEquals(Level.ERROR, log.get(0).getLevel());
    Assert.assertTrue(log.get(0).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_FAILED_AT_LINE"), 1, "UT Failed Message")));

    outputConsoleDataProvider.writeSuccessResult(2);
    log = appender.getLog();
    Assert.assertEquals(Level.INFO, log.get(1).getLevel());
    Assert.assertTrue(log.get(1).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_SUCCESS_AT_LINE"), 2)));

    outputConsoleDataProvider.writeWarningResult(3, "UT Warning Message");
    log = appender.getLog();
    Assert.assertEquals(Level.WARN, log.get(2).getLevel());
    Assert.assertTrue(log.get(2).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_WARNING_AT_LINE"), 3, "UT Warning Message")));

    outputConsoleDataProvider.writeDataResult("title", 4, "UT title");
    log = appender.getLog();
    Assert.assertEquals(Level.INFO, log.get(3).getLevel());
    Assert.assertTrue(log.get(3).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_RESULT_AT_LINE"), 4, "title", "UT title")));
}
 
Example 25
Source Project: qpid-broker-j   Source File: VirtualHostLoggerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAddLoggerWithDefaultSettings()
{
    VirtualHostLogger logger = createVirtualHostLogger();

    assertTrue("Unexpected logger created " + logger, logger instanceof VirtualHostFileLogger);
    assertEquals("Unexpected log file", _logFile.getPath(), ((VirtualHostFileLogger<?>) logger).getFileName());
    assertEquals("Unexpected state on creation", State.ACTIVE, logger.getState());
    assertTrue("Log file does not exists", _logFile.exists());

    Appender<ILoggingEvent> appender = ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))
            .getAppender(logger.getName());
    assertTrue("Appender was not started", appender.isStarted());
}
 
Example 26
Source Project: otroslogviewer   Source File: GuiAppender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {
  if (bufferingLogDataCollectorProxy != null && !isIgnoringLogRecord(eventObject)) {
    final LogDataBuilder builder = LogbackUtil.translate(eventObject);
    builder.withFile("Olv-internal");
    bufferingLogDataCollectorProxy.add(builder.build());
  }
}
 
Example 27
@Before
public void setUp() throws Exception
{
    _brokerLogger = mock(BrokerLogger.class);
    _loggingEvent = mock(ILoggingEvent.class);
    _filter = new VirtualHostLogEventExcludingFilter(_brokerLogger);
}
 
Example 28
Source Project: eclair   Source File: ExampleTableBuilder.java    License: Apache License 2.0 5 votes vote down vote up
String buildSampleCell(List<ILoggingEvent> events) {
    if (events.isEmpty()) {
        return "-";
    }
    return events.stream()
            .map(patternLayout::doLayout)
            .map(this::processMultiLineEventString)
            .collect(joining(LINE_SEPARATOR));
}
 
Example 29
Source Project: baleen   Source File: AbstractBaleenLoggerBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build a new appender for the specified context and encoder (where required).
 *
 * @param context The logger context
 * @param encoder The encoder to use (if that is possible for the specific appender)
 * @return The new appender
 */
@Override
public final Appender<ILoggingEvent> build(
    LoggerContext context, Encoder<ILoggingEvent> encoder) {
  Appender<ILoggingEvent> appender = createAppender(context, encoder);
  appender.setName(name);
  appender.setContext(context);

  if (filters != null) {
    filters.forEach(appender::addFilter);
  }

  return appender;
}
 
Example 30
Source Project: pravega   Source File: MetricsLogAppender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doAppend(ILoggingEvent event) throws LogbackException {
    if (event.getLevel() == Level.ERROR) {
        recordEvent(MetricsNames.LOG_ERRORS, event);
    } else if (event.getLevel() == Level.WARN) {
        recordEvent(MetricsNames.LOG_WARNINGS, event);
    }
}