当前位置: 首页>>代码示例>>Java>>正文


Java Appender.setContext方法代码示例

本文整理汇总了Java中ch.qos.logback.core.Appender.setContext方法的典型用法代码示例。如果您正苦于以下问题:Java Appender.setContext方法的具体用法?Java Appender.setContext怎么用?Java Appender.setContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.core.Appender的用法示例。


在下文中一共展示了Appender.setContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: setVerboseMode

import ch.qos.logback.core.Appender; //导入方法依赖的package包/类
@Override
public void setVerboseMode(boolean on) {
    PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
    patternLayoutEncoder.setPattern("[%d{HH:mm:ss.SSS}] [%highlight(%level)] %msg%n");
    patternLayoutEncoder.setContext(loggerContext);
    patternLayoutEncoder.start();

    Appender<ILoggingEvent> consoleAppender = new ConsoleAppender();
    ((OutputStreamAppender) consoleAppender).setEncoder(patternLayoutEncoder);
    consoleAppender.setContext(loggerContext);
    consoleAppender.start();

    loggerContext.getLogger("com.paypal.butterfly.cli").detachAppender("CONSOLE");
    loggerContext.getLogger("ROOT").addAppender(consoleAppender);
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:16,代码来源:LogbackLogConfigurator.java

示例5: 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 Properties producerConfigProperties = producerConfig.stream()
            .map(s -> s.split("="))
            .filter(values -> values.length == 2)
            .reduce(new Properties(), (props, values) -> {
                props.setProperty(values[0], values[1]);
                return props;
            }, (p1, p2) -> {
                Properties merged = new Properties();
                merged.putAll(p1);
                merged.putAll(p2);
                return merged;
            });

    final Appender<E> appender = new KafkaLogbackAppender<>(producerConfigProperties, topic);

    appender.setContext(context);

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

    return appender;
    //return wrapAsync(appender, asyncAppenderFactory);
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:33,代码来源:KafkaLogbackAppenderFactory.java

示例6: addGuiAppender

import ch.qos.logback.core.Appender; //导入方法依赖的package包/类
/**
 * Add a specific appender meant for GUI log pane.
 * To be called only when running with a GUI.
 */
public static void addGuiAppender ()
{
    // GUI (filtered in LogGuiAppender)
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    Appender guiAppender = new LogGuiAppender();
    guiAppender.setName("GUI");
    guiAppender.setContext(loggerContext);
    guiAppender.start();
    root.addAppender(guiAppender);
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:17,代码来源:LogUtil.java

示例7: testNoStart

import ch.qos.logback.core.Appender; //导入方法依赖的package包/类
@Test
public void testNoStart() {
  Appender<E> appender = getAppender();
  appender.setContext(context);
  appender.setName("doh");
  // is null OK?
  appender.doAppend(null);
  StatusChecker checker = new StatusChecker(context.getStatusManager());
  StatusPrinter.print(context);
  checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\].");
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:12,代码来源:AbstractAppenderTest.java

示例8: build

import ch.qos.logback.core.Appender; //导入方法依赖的package包/类
/**
 * 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(f -> appender.addFilter(f));
	}

	return appender;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:20,代码来源:AbstractBaleenLoggerBuilder.java

示例9: LogConfigurator

import ch.qos.logback.core.Appender; //导入方法依赖的package包/类
public LogConfigurator(File f) {

            Appender appender = null;

            if (f != null) {
                try {
                    String line = Files.readFirstLine(f, Charset.defaultCharset()).trim();
                    switch (line) {
                        case "rolling":
                            String logFile = workingDirectory();
                            message = ("rolling to file://{}" + logFile);

                            RollingFileAppender r = new RollingFileAppender();
                            r.setFile(logFile);
                            r.setAppend(true);

                            SizeBasedTriggeringPolicy triggeringPolicy = new ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy();
                            triggeringPolicy.setMaxFileSize(FileSize.valueOf("5MB"));
                            triggeringPolicy.start();

                            FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
                            policy.setFileNamePattern("log.%i.gz");
                            policy.setParent(r);
                            policy.setContext(LOG.getLoggerContext());
                            policy.start();

                            r.setEncoder(logEncoder());
                            r.setRollingPolicy(policy);
                            r.setTriggeringPolicy(triggeringPolicy);


                            appender = r;
                            break;
                        //TODO TCP/UDP etc
                    }
                } catch (IOException e) {
                    logger.error("{}", e);
                    appender = null;
                }
            }

            if (appender == null) {
                //default
                ConsoleAppender a = new ConsoleAppender();
                a.setEncoder(logEncoder());
                appender = a;
                message = "ConsoleAppender";
            }


            LOG.detachAndStopAllAppenders();

            appender.setContext(LOG.getLoggerContext());
            appender.start();

            LOG.addAppender(appender);


            this.appender = appender;
        }
 
开发者ID:automenta,项目名称:spimedb,代码行数:61,代码来源:Main.java


注:本文中的ch.qos.logback.core.Appender.setContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。