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


Java Appender.start方法代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.Appender.start方法的典型用法代碼示例。如果您正苦於以下問題:Java Appender.start方法的具體用法?Java Appender.start怎麽用?Java Appender.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.logging.log4j.core.Appender的用法示例。


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

示例1: watch

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
public void watch(Class<?> loggerClass, Level level) {
    this.loggerClass = loggerClass;
    Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) {
        @Override
        public void append(LogEvent event) {
            logEvents.add(event);
        }
    };
    appender.start();
    final LoggerContext ctx = getLoggerContext();
    LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
    oldLevel = loggerConfig.getLevel();
    loggerConfig.setLevel(level);
    loggerConfig.addAppender(appender, level, null);
    ctx.updateLoggers();
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:17,代碼來源:LogTestRule.java

示例2: StandaloneLoggerConfiguration

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
/**
 * Constructor to create the default configuration.
 */
public StandaloneLoggerConfiguration(ConfigurationSource source) {
    super(source);

    setName(CONFIG_NAME);
    final Appender appender = StandaloneLogEventAppender.createAppender("StandaloneLogAppender", 1000);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ALL;
    root.setLevel(level);
}
 
開發者ID:Steve973,項目名稱:camel-standalone,代碼行數:19,代碼來源:StandaloneLoggerConfiguration.java

示例3: configureLogging

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
protected void configureLogging() {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, config, null, null,
            true, false, null, null);
    Appender appender = FileAppender.createAppender(workDir + "/logs/camel-standalone.log", "false", "false", "File", "true",
            "false", "false", "4000", layout, null, "false", null, config);
    appender.start();
    config.addAppender(appender);
    AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
    AppenderRef[] refs = new AppenderRef[] {ref};
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "StandaloneFileLoggerConfig",
            "true", refs, null, config, null );
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("StandaloneFileLoggerConfig", loggerConfig);
    ctx.updateLoggers();
}
 
開發者ID:Steve973,項目名稱:camel-standalone,代碼行數:18,代碼來源:Standalone.java

示例4: addLoggingWriterAppender

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Override
public StringWriter addLoggingWriterAppender(String appenderName)
{
    // Get the configuration
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration configuration = loggerContext.getConfiguration();

    // Create a string writer as part of the appender so logging will be written to it.
    StringWriter stringWriter = new StringWriter();

    // Create and start the appender with the string writer.
    Appender appender = WriterAppender.createAppender(null, null, stringWriter, appenderName, false, true);
    appender.start();

    // Add the appender to the root logger.
    configuration.getRootLogger().addAppender(appender, null, null);

    // Return the string writer.
    return stringWriter;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:21,代碼來源:Log4j2LoggingHelper.java

示例5: configureLog4j

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private static Logger configureLog4j() {
    LoggerContext context = (LoggerContext) LogManager.getContext();
    Configuration config = context.getConfiguration();

    PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
    Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
    appender.start();
    AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
    AppenderRef[] refs = new AppenderRef[]{ref};
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
    loggerConfig.addAppender(appender, null, null);

    config.addAppender(appender);
    config.addLogger("Main.class", loggerConfig);
    context.updateLoggers(config);
    return LogManager.getContext().getLogger("Main.class");
}
 
開發者ID:vitaly-chibrikov,項目名稱:homework_tester,代碼行數:18,代碼來源:Main.java

示例6: bindLogger

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
public static void bindLogger() {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();

    Map<String, ESLogger> loggers = Maps.newConcurrentHashMap();
    Appender appender = new AbstractAppender("", null, null) {
        @Override
        public void append(LogEvent event) {
            String name = event.getLoggerName();
            ESLogger logger = loggers.computeIfAbsent(name, key -> new ESLogger(key, null, (LoggerImpl) LoggerFactory.getLogger(key)));
            logger.log(event.getLevel(), event.getMarker(), event.getMessage(), event.getThrown());
        }
    };
    appender.start();
    config.addAppender(appender);

    LoggerConfig loggerConfig = new LoggerConfig("", Level.ALL, false);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("", loggerConfig);
    context.updateLoggers();
}
 
開發者ID:neowu,項目名稱:core-ng-project,代碼行數:22,代碼來源:ESLoggerConfigFactory.java

示例7: addAppenderToContext

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
public void addAppenderToContext(
        final LoggerContext ctx,
        final AuditAppender auditAppender,
        final LoggerConfig eventLogConf) {

    Appender targetAppender = ctx.getConfiguration().getAppender(auditAppender.getTargetAppenderName());
    if (targetAppender == null) {
        targetAppender = auditAppender.getTargetAppender();
    }
    targetAppender.start();
    ctx.getConfiguration().addAppender(targetAppender);
    if (auditAppender.isRewriteEnabled()) {
        RewriteAppender rewriteAppender = ctx.getConfiguration().getAppender(auditAppender.
                getTargetAppenderName() + "_rewrite");
        if (rewriteAppender == null) {
            rewriteAppender = auditAppender.getRewriteAppender();
        }
        rewriteAppender.start();
        ctx.getConfiguration().addAppender(rewriteAppender);
        eventLogConf.addAppender(rewriteAppender, Level.DEBUG, null);
    } else {
        eventLogConf.addAppender(targetAppender, Level.DEBUG, null);
    }
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:25,代碼來源:LoggerLoader.java

示例8: createFileAppender

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private void createFileAppender(DiagnosticContext ctx) {

      String logDir = ctx.getTempDir() + SystemProperties.fileSeparator + "diagnostics.log";

      final LoggerContext context = (LoggerContext) LogManager.getContext(false);
      final Configuration config = context.getConfiguration();
      Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", null, config, null,
         null,true, true, null, null );
      Appender appender = FileAppender.createAppender(logDir, "false", "false", "File", "true",
         "false", "false", "0", layout, null, "false", null, config);
      appender.start();
      config.addAppender(appender);
      AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
      AppenderRef[] refs = new AppenderRef[] {ref};

      config.getRootLogger().addAppender(appender, null, null);
      context.updateLoggers();
      Logger testLog = LogManager.getLogger();
      testLog.error("Testing");
   }
 
開發者ID:elastic,項目名稱:elasticsearch-support-diagnostics,代碼行數:21,代碼來源:Diagnostic.java

示例9: start

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
/**
 * Initialize the configuration.
 */
@Override
public void start() {
    pluginManager.collectPlugins();
    setup();
    setupAdvertisement();
    doConfigure();
    for (final LoggerConfig logger : loggers.values()) {
        logger.startFilter();
    }
    for (final Appender appender : appenders.values()) {
        appender.start();
    }
    root.startFilter(); // LOG4J2-336
    startFilter();
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:19,代碼來源:BaseConfiguration.java

示例10: setToDefault

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private void setToDefault() {
    setName(DefaultConfiguration.DEFAULT_NAME);
    final Layout<? extends Serializable> layout =
            PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n",
                    null, null, null, null);
    final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
        "true");
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
        Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:18,代碼來源:BaseConfiguration.java

示例11: DefaultConfiguration

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
/**
 * Constructor to create the default configuration.
 */
public DefaultConfiguration() {

    setName(DEFAULT_NAME);
    final Layout<? extends Serializable> layout =
            PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null);
    final Appender appender =
            ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
        Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:21,代碼來源:DefaultConfiguration.java

示例12: createAppender

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private Appender createAppender(final Route route, final LogEvent event) {
    final Node routeNode = route.getNode();
    for (final Node node : routeNode.getChildren()) {
        if (node.getType().getElementName().equals("appender")) {
            final Node appNode = new Node(node);
            config.createConfiguration(appNode, event);
            if (appNode.getObject() instanceof Appender) {
                final Appender app = (Appender) appNode.getObject();
                app.start();
                return app;
            }
            LOGGER.error("Unable to create Appender of type " + node.getName());
            return null;
        }
    }
    LOGGER.error("No Appender was configured for route " + route.getKey());
    return null;
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:19,代碼來源:RoutingAppender.java

示例13: CustomConfiguration

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
/**
 * Constructor to create the default configuration.
 */
public CustomConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
    super(loggerContext, source);

    setName(CONFIG_NAME);
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
            .withPattern(DEFAULT_PATTERN)
            .withConfiguration(this)
            .build();
    final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:23,代碼來源:CustomConfiguration.java

示例14: setToDefault

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
protected void setToDefault() {
    // LOG4J2-1176 facilitate memory leak investigation
    setName(DefaultConfiguration.DEFAULT_NAME + "@" + Integer.toHexString(hashCode()));
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
            .withPattern(DefaultConfiguration.DEFAULT_PATTERN)
            .withConfiguration(this)
            .build();
    final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
    appender.start();
    addAppender(appender);
    final LoggerConfig rootLoggerConfig = getRootLogger();
    rootLoggerConfig.addAppender(appender, null, null);

    final Level defaultLevel = Level.ERROR;
    final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL,
            defaultLevel.name());
    final Level level = Level.valueOf(levelName);
    rootLoggerConfig.setLevel(level != null ? level : defaultLevel);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:20,代碼來源:AbstractConfiguration.java

示例15: createAppender

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private Appender createAppender(final Route route, final LogEvent event) {
    final Node routeNode = route.getNode();
    for (final Node node : routeNode.getChildren()) {
        if (node.getType().getElementName().equals(Appender.ELEMENT_TYPE)) {
            final Node appNode = new Node(node);
            configuration.createConfiguration(appNode, event);
            if (appNode.getObject() instanceof Appender) {
                final Appender app = appNode.getObject();
                app.start();
                return app;
            }
            error("Unable to create Appender of type " + node.getName());
            return null;
        }
    }
    error("No Appender was configured for route " + route.getKey());
    return null;
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:19,代碼來源:RoutingAppender.java


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