Search in sources :

Example 1 with LoggerImpl

use of core.framework.impl.log.LoggerImpl in project core-ng-project by neowu.

the class ESLoggerConfigFactory method bindLogger.

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();
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) LoggerImpl(core.framework.impl.log.LoggerImpl) LoggerContext(org.apache.logging.log4j.core.LoggerContext) ESLogger(core.framework.impl.search.log.ESLogger) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

LoggerImpl (core.framework.impl.log.LoggerImpl)1 ESLogger (core.framework.impl.search.log.ESLogger)1 Appender (org.apache.logging.log4j.core.Appender)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1