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


Java AbstractAppender类代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.appender.AbstractAppender的典型用法代码示例。如果您正苦于以下问题:Java AbstractAppender类的具体用法?Java AbstractAppender怎么用?Java AbstractAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AbstractAppender类属于org.apache.logging.log4j.core.appender包,在下文中一共展示了AbstractAppender类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: watch

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的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: bindLogger

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的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

示例3: start

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    for (final AppenderRef ref : appenderRefs) {
        final String name = ref.getRef();
        final Appender appender = map.get(name);
        if (appender != null) {
            final Filter filter = appender instanceof AbstractAppender ?
                ((AbstractAppender) appender).getFilter() : null;
            appenders.put(name, new AppenderControl(appender, ref.getLevel(), filter));
        } else {
            LOGGER.error("Appender " + ref + " cannot be located. Reference ignored");
        }
    }
    super.start();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:RewriteAppender.java

示例4: newInstance

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
/**
 * Gets an instance of the class.
 *
 * @param config  The current Configuration.
 * @param options pattern options, an array of two elements: pattern, max length (defaults to 100 on invalid value).
 * @return instance of class.
 */
public static MaxLengthConverter newInstance(final Configuration config, final String[] options) {
    if (options.length != 2) {
        LOGGER.error("Incorrect number of options on maxLength: expected 2 received {}: {}", options.length,
            options);
        return null;
    }
    if (options[0] == null) {
        LOGGER.error("No pattern supplied on maxLength");
        return null;
    }
    if (options[1] == null) {
        LOGGER.error("No length supplied on maxLength");
        return null;
    }
    final PatternParser parser = PatternLayout.createPatternParser(config);
    final List<PatternFormatter> formatters = parser.parse(options[0]);
    return new MaxLengthConverter(formatters, AbstractAppender.parseInt(options[1], 100));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:MaxLengthConverter.java

示例5: createAppender

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
/**
 * Factory method for creating a JDBC appender within the plugin manager.
 *
 * @see Builder
 * @deprecated use {@link #newBuilder()}
 */
@Deprecated
public static <B extends Builder<B>> JdbcAppender createAppender(final String name, final String ignore,
                                                                 final Filter filter,
                                                                 final ConnectionSource connectionSource,
                                                                 final String bufferSize, final String tableName,
                                                                 final ColumnConfig[] columnConfigs) {
    Assert.requireNonEmpty(name, "Name cannot be empty");
    Objects.requireNonNull(connectionSource, "ConnectionSource cannot be null");
    Assert.requireNonEmpty(tableName, "Table name cannot be empty");
    Assert.requireNonEmpty(columnConfigs, "ColumnConfigs cannot be empty");

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    return JdbcAppender.<B>newBuilder()
        .setBufferSize(bufferSizeInt)
        .setColumnConfigs(columnConfigs)
        .setConnectionSource(connectionSource)
        .setTableName(tableName)
        .withName(name)
        .withIgnoreExceptions(ignoreExceptions)
        .withFilter(filter)
        .build();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:31,代码来源:JdbcAppender.java

示例6: LogVerifier

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
public LogVerifier() {
    this.appender = new AbstractAppender(LogVerifier.class.getSimpleName(), LevelRangeFilter.createFilter(Level.ALL, Level.ALL, Filter.Result.ACCEPT, Filter.Result.ACCEPT), PatternLayout.createDefaultLayout()) {
        @Override
        public void append(LogEvent event) {
            LogVerifier.this.append(event);
        }
    };
}
 
开发者ID:astefanutti,项目名称:camel-cdi,代码行数:9,代码来源:LogVerifier.java

示例7: createAppender

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
/**
 * Factory method for creating a NoSQL appender within the plugin manager.
 *
 * @param name The name of the appender.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param filter The filter, if any, to use.
 * @param bufferSize If an integer greater than 0, this causes the appender to buffer log events and flush whenever
 *                   the buffer reaches this size.
 * @param provider The NoSQL provider that provides connections to the chosen NoSQL database.
 * @return a new NoSQL appender.
 */
@PluginFactory
public static NoSQLAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginElement("Filter") final Filter filter,
        @PluginAttribute("bufferSize") final String bufferSize,
        @PluginElement("NoSqlProvider") final NoSQLProvider<?> provider) {
    if (provider == null) {
        LOGGER.error("NoSQL provider not specified for appender [{}].", name);
        return null;
    }

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    final String managerName = "noSqlManager{ description=" + name + ", bufferSize=" + bufferSizeInt
            + ", provider=" + provider + " }";

    final NoSQLDatabaseManager<?> manager = NoSQLDatabaseManager.getNoSQLDatabaseManager(
            managerName, bufferSizeInt, provider
    );
    if (manager == null) {
        return null;
    }

    return new NoSQLAppender(name, filter, ignoreExceptions, manager);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:40,代码来源:NoSQLAppender.java

示例8: createAppender

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
/**
 * Factory method for creating a JDBC appender within the plugin manager.
 *
 * @param name The name of the appender.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param filter The filter, if any, to use.
 * @param connectionSource The connections source from which database connections should be retrieved.
 * @param bufferSize If an integer greater than 0, this causes the appender to buffer log events and flush whenever
 *                   the buffer reaches this size.
 * @param tableName The name of the database table to insert log events into.
 * @param columnConfigs Information about the columns that log event data should be inserted into and how to insert
 *                      that data.
 * @return a new JDBC appender.
 */
@PluginFactory
public static JDBCAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginElement("Filter") final Filter filter,
        @PluginElement("ConnectionSource") final ConnectionSource connectionSource,
        @PluginAttribute("bufferSize") final String bufferSize,
        @PluginAttribute("tableName") final String tableName,
        @PluginElement("ColumnConfigs") final ColumnConfig[] columnConfigs) {

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    final StringBuilder managerName = new StringBuilder("jdbcManager{ description=").append(name)
            .append(", bufferSize=").append(bufferSizeInt).append(", connectionSource=")
            .append(connectionSource.toString()).append(", tableName=").append(tableName).append(", columns=[ ");

    int i = 0;
    for (final ColumnConfig column : columnConfigs) {
        if (i++ > 0) {
            managerName.append(", ");
        }
        managerName.append(column.toString());
    }

    managerName.append(" ] }");

    final JDBCDatabaseManager manager = JDBCDatabaseManager.getJDBCDatabaseManager(
            managerName.toString(), bufferSizeInt, connectionSource, tableName, columnConfigs
    );
    if (manager == null) {
        return null;
    }

    return new JDBCAppender(name, filter, ignoreExceptions, manager);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:52,代码来源:JDBCAppender.java

示例9: createAppender

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
/**
 * Factory method for creating a NoSQL appender within the plugin manager.
 *
 * @param name
 *            The name of the appender.
 * @param ignore
 *            If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they
 *            are propagated to the caller.
 * @param filter
 *            The filter, if any, to use.
 * @param bufferSize
 *            If an integer greater than 0, this causes the appender to buffer log events and flush whenever the
 *            buffer reaches this size.
 * @param provider
 *            The NoSQL provider that provides connections to the chosen NoSQL database.
 * @return a new NoSQL appender.
 * @deprecated since 2.10.1; use {@link Builder}.
 */
@SuppressWarnings("resource")
@Deprecated
public static NoSqlAppender createAppender(
// @formatter:off
        final String name,
        final String ignore, 
        final Filter filter,
        final String bufferSize,
        final NoSqlProvider<?> provider) {
// @formatter:on
    if (provider == null) {
        LOGGER.error("NoSQL provider not specified for appender [{}].", name);
        return null;
    }

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    final String managerName = "noSqlManager{ description=" + name + ", bufferSize=" + bufferSizeInt + ", provider="
            + provider + " }";

    final NoSqlDatabaseManager<?> manager = NoSqlDatabaseManager.getNoSqlDatabaseManager(managerName, bufferSizeInt,
            provider);
    if (manager == null) {
        return null;
    }

    return new NoSqlAppender(name, filter, null, ignoreExceptions, manager);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:48,代码来源:NoSqlAppender.java

示例10: start

import org.apache.logging.log4j.core.appender.AbstractAppender; //导入依赖的package包/类
@Override
public void start() {
    for (final AppenderRef ref : appenderRefs) {
        final String name = ref.getRef();
        final Appender appender = config.getAppender(name);
        if (appender != null) {
            final Filter filter = appender instanceof AbstractAppender ?
                ((AbstractAppender) appender).getFilter() : null;
            appenders.put(name, new AppenderControl(appender, ref.getLevel(), filter));
        } else {
            LOGGER.error("Appender " + ref + " cannot be located. Reference ignored");
        }
    }
    super.start();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:16,代码来源:RewriteAppender.java


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