當前位置: 首頁>>代碼示例>>Java>>正文


Java Appender類代碼示例

本文整理匯總了Java中ch.qos.logback.core.Appender的典型用法代碼示例。如果您正苦於以下問題:Java Appender類的具體用法?Java Appender怎麽用?Java Appender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Appender類屬於ch.qos.logback.core包,在下文中一共展示了Appender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAppenderThreshold

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@Override
public Level getAppenderThreshold(String appenderName) throws AppenderThresholdNotSupported {
    for (Map.Entry<String, Appender> entry : getAllAppenders().entrySet()) {
        if (entry.getKey().equals(appenderName)) {
            Appender appender = entry.getValue();
            for (Object filter : appender.getCopyOfAttachedFiltersList()) {
                if (filter instanceof ThresholdFilter) {
                    try {
                        Field field = filter.getClass().getDeclaredField("level");
                        field.setAccessible(true);
                        return (Level) field.get(filter);
                    } catch (NoSuchFieldException | IllegalAccessException e) {
                        log.error("Error getting appender " + appenderName + " level", e);
                        throw new AppenderThresholdNotSupported(appenderName);
                    }
                }
            }
        }
    }
    throw new AppenderThresholdNotSupported(appenderName);
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:22,代碼來源:LogControlImpl.java

示例2: fileAppender

import ch.qos.logback.core.Appender; //導入依賴的package包/類
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
		String logFile) {
	RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
	encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
	appender.setEncoder(encoder);
	config.start(encoder);

	appender.setFile(logFile);

	FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
	rollingPolicy.setFileNamePattern(logFile + ".%i");
	appender.setRollingPolicy(rollingPolicy);
	rollingPolicy.setParent(appender);
	config.start(rollingPolicy);

	SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
	triggeringPolicy.setMaxFileSize("10MB");
	appender.setTriggeringPolicy(triggeringPolicy);
	config.start(triggeringPolicy);

	config.appender("FILE", appender);
	return appender;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:26,代碼來源:DefaultLogbackConfiguration.java

示例3: setMetricsMarkerLogbackFilter

import ch.qos.logback.core.Appender; //導入依賴的package包/類
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();
            }
        }
    }
}
 
開發者ID:torgcrm,項目名稱:TorgCRM-Server,代碼行數:25,代碼來源:LoggingConfiguration.java

示例4: logToConsole

import ch.qos.logback.core.Appender; //導入依賴的package包/類
/**
 * Starts or stops logging to the console.
 *
 * @param start starts or stops logging to the console.
 */
@SuppressWarnings("rawtypes")
public static void logToConsole(boolean start) {
    Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    if (rootLogger != null && rootLogger instanceof ch.qos.logback.classic.Logger) {
        Appender appender = ((ch.qos.logback.classic.Logger) rootLogger).getAppender(CONSOLE_APPENDER_NAME);

        if (appender != null) {
            if (start) {
                appender.start();
            } else {
                appender.stop();
            }

            return;
        }
    }

    logger.warn("Unable to reconfigure Logback console logger (appender name '" + CONSOLE_APPENDER_NAME + "').");
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:25,代碼來源:StandaloneUtils.java

示例5: setMetricsMarkerLogbackFilter

import ch.qos.logback.core.Appender; //導入依賴的package包/類
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();
            }
        }
    }
}
 
開發者ID:asanzdiego,項目名稱:codemotion-2017-taller-de-jhipster,代碼行數:25,代碼來源:LoggingConfiguration.java

示例6: build

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@Override
public Appender<E> build(final LoggerContext context,
                         final String applicationName,
                         final LayoutFactory<E> layoutFactory,
                         final LevelFilterFactory<E> levelFilterFactory,
                         final AsyncAppenderFactory<E> asyncAppenderFactory) {
    final Appender<E> appender = new FifoLogbackAppender<>();

    appender.setContext(context);

    appender.addFilter(levelFilterFactory.build(threshold));
    getFilterFactories().forEach(f -> appender.addFilter(f.build()));
    appender.start();
    appender.setName(APPENDER_NAME);

    return appender;
}
 
開發者ID:gchq,項目名稱:stroom-query,代碼行數:18,代碼來源:FifoLogbackAppenderFactory.java

示例7: init

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@BeforeClass
@SuppressWarnings("unchecked")
public static void init() {
    loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    appender = new CdpAppender();
    appender.setContext(loggerContext);
    appender.start();
    appender.setName(CdpAppender.class.getName());

    Logger logger = loggerContext.getLogger("cdp4j.flow");
    logger.addAppender((Appender<ILoggingEvent>) appender);

    factory = new Launcher().launch();

    session = factory.create();

    session.enableConsoleLog();

    URL url = TestAll.class.getResource("/session-test.html");
    session.navigate(url.toString());
}
 
開發者ID:webfolderio,項目名稱:cdp4j,代碼行數:23,代碼來源:TestAll.java

示例8: shouldSetConsoleAppenderForServiceAndRequestLogs

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@Test
public void shouldSetConsoleAppenderForServiceAndRequestLogs() {
    final String requestLoggerName = "requestlogger";
    SecondBaseLogger.setupLoggingStdoutOnly(KEYS, VALUES, requestLoggerName);
    final ch.qos.logback.classic.Logger rootLogger
            = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
                    org.slf4j.Logger.ROOT_LOGGER_NAME);
    final Appender<ILoggingEvent> serviceConsoleAppender = rootLogger.getAppender(
            "SERVICECONSOLEAPPENDER");

    assertThat(serviceConsoleAppender, notNullValue());

    final ch.qos.logback.classic.Logger requestLogger
            = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(requestLoggerName);
    final Appender<ILoggingEvent> requestLogConsoleAppender = requestLogger.getAppender(
            "REQUESTLOGCONSOLEAPPENDER");

    assertThat(requestLogConsoleAppender, notNullValue());
}
 
開發者ID:secondbase,項目名稱:secondbase,代碼行數:20,代碼來源:SecondBaseLoggerTest.java

示例9: build

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@Override
public Appender<ILoggingEvent> build(LoggerContext context, String s, Layout<ILoggingEvent> layout) {
    Preconditions.checkNotNull(context);
    WiretapAppender appender = new WiretapAppender();

    final PatternLayoutEncoder patternEncoder = new PatternLayoutEncoder();
    patternEncoder.setContext(context);
    patternEncoder.setPattern("%-5p [%thread] [%d] %c: %m%n%rEx");
    patternEncoder.start();

    appender.setContext(context);
    appender.setName("wiretap-appender");
    appender.setEncoder(patternEncoder);

    addThresholdFilter(appender, threshold);
    appender.start();

    return wrapAsync(appender);
}
 
開發者ID:Quiq,項目名稱:dropwizard-wiretap,代碼行數:20,代碼來源:WiretapAppenderFactory.java

示例10: build

import ch.qos.logback.core.Appender; //導入依賴的package包/類
public Appender<ILoggingEvent> build(
    LoggerContext context,
    String applicationName,
    LayoutFactory<ILoggingEvent> layoutFactory,
    LevelFilterFactory<ILoggingEvent> levelFilterFactory,
    AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory
  ) {

  final LoggingEventCompositeJsonEncoder encoder = new LoggingEventCompositeJsonEncoder();
  encoder.setContext(context);

  encoder.getProviders().addProvider(withPattern("{ \"type\": \"system\" }", new LoggingEventPatternJsonProvider(), context));
  encoder.getProviders().addProvider(withName("timestamp", new LoggingEventFormattedTimestampJsonProvider(), context));
  encoder.getProviders().addProvider(new LogLevelJsonProvider() );
  encoder.getProviders().addProvider(new MessageJsonProvider() );
  encoder.getProviders().addProvider(new StackTraceJsonProvider() );

  encoder.start();

  final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
  appender.setContext(context);
  appender.setEncoder(encoder);
  appender.start();

  return wrapAsync(appender, asyncAppenderFactory);
}
 
開發者ID:atgse,項目名稱:sam,代碼行數:27,代碼來源:JsonLogAppender.java

示例11: startLogback

import ch.qos.logback.core.Appender; //導入依賴的package包/類
public static void startLogback() {
    long startTime = System.nanoTime();
    Config config = Configs.DEFAULT.logging();
    LogbackConfig logbackConfig = getLogbackConfig(config);
    LogbackManager logbackMgr = LogbackManager.INSTANCE;
    RollingFileAppender<ILoggingEvent> fileAppender = logbackMgr.createRollingFileAppender(logbackConfig);
    ConsoleAppender<ILoggingEvent> consoleAppender = logbackMgr
            .createConsoleAppender(APPENDER_CONSOLE, config.getString(KEY_LOG_PATTERN_CONSOLE));
    List<Appender<ILoggingEvent>> appenderList = new ArrayList<>();
    appenderList.add(consoleAppender);
    appenderList.add(fileAppender);
    logbackMgr.getAppenders().addAll(appenderList);
    LoggerContext context = logbackMgr.getLoggerContext();
    initRootLogger(context, consoleAppender, config);
    addLoggers(config, appenderList);
    addAsyncAppender(config, fileAppender);
    context.start();
    context.getLogger(LogbackInitializer.class).info(INIT_MSG, elapsedMillis(startTime));
}
 
開發者ID:AdeptJ,項目名稱:adeptj-runtime,代碼行數:20,代碼來源:LogbackInitializer.java

示例12: configure

import ch.qos.logback.core.Appender; //導入依賴的package包/類
/**
 * Initializes the logger and the requested log level.
 *
 * @param level Logging level threshold
 */
@SuppressWarnings("unchecked")
public static void configure(final Level level) {
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(level);

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(root.getLoggerContext());
    encoder.setPattern("%msg%n");
    encoder.start();

    Iterator<Appender<ILoggingEvent>> iterator = root.iteratorForAppenders();

    while (iterator.hasNext()) {
        Appender<ILoggingEvent> appender = iterator.next();
        if (appender instanceof OutputStreamAppender) {
            ((OutputStreamAppender) appender).setEncoder(encoder);
        }
        appender.stop();
        appender.start();
    }
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:27,代碼來源:LoggingConfigurer.java

示例13: configureAppender

import ch.qos.logback.core.Appender; //導入依賴的package包/類
private Appender<ILoggingEvent> configureAppender(LoggerContext loggerContext, String name, Config config)
		throws ReflectiveOperationException {
	List<Object> children = new ArrayList<>();

	@SuppressWarnings("unchecked")
	Class<Appender<ILoggingEvent>> clazz = (Class<Appender<ILoggingEvent>>) Class
			.forName(config.getString("class"));

	Appender<ILoggingEvent> appender = this.configureObject(loggerContext, clazz, config, children);
	appender.setName(name);

	for (Object child : children) {
		if (child instanceof RollingPolicy) {
			((RollingPolicy) child).setParent((FileAppender<?>) appender);
		}
		if (child instanceof LifeCycle) {
			((LifeCycle) child).start();
		}
	}

	appender.start();
	return appender;

}
 
開發者ID:gnieh,項目名稱:logback-config,代碼行數:25,代碼來源:ConfigConfigurator.java

示例14: buildDailyMaxRollingAppender

import ch.qos.logback.core.Appender; //導入依賴的package包/類
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:26,代碼來源:DynamicLogbackLogger.java

示例15: testAppender

import ch.qos.logback.core.Appender; //導入依賴的package包/類
@org.junit.Test
public void testAppender() {
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    Appender mockAppender = mock(Appender.class);
    root.addAppender(mockAppender);
    Appender<ILoggingEvent> appender = root.getAppender("SNMP");
    LOG.info("server error", new RuntimeException("info message"));
    LOG.error("server error", new RuntimeException("error message"));

    verify(mockAppender,times(2)).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {
        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains("server error");
        }
    }));
    Assert.assertThat(appender.getClass().getName(), is(equalTo("com.sathwik.logback.appender.SNMPTrapAppender")));


}
 
開發者ID:anilkd,項目名稱:logback-snmp,代碼行數:20,代碼來源:SNMPTrapAppenderTest.java


注:本文中的ch.qos.logback.core.Appender類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。