Java 类org.apache.logging.log4j.spi.ExtendedLogger 实例源码

项目:elasticsearch_my    文件:PrefixLogger.java   
PrefixLogger(final ExtendedLogger logger, final String name, final String prefix) {
    super(logger, name, null);

    final String actualPrefix = (prefix == null ? "" : prefix).intern();
    final Marker actualMarker;
    // markers is not thread-safe, so we synchronize access
    synchronized (markers) {
        final WeakReference<Marker> marker = markers.get(actualPrefix);
        final Marker maybeMarker = marker == null ? null : marker.get();
        if (maybeMarker == null) {
            actualMarker = new MarkerManager.Log4jMarker(actualPrefix);
            markers.put(actualPrefix, new WeakReference<>(actualMarker));
        } else {
            actualMarker = maybeMarker;
        }
    }
    this.marker = actualMarker;
}
项目:logging-log4j2    文件:Log4jTaglibLoggerContext.java   
@Override
public Log4jTaglibLogger getLogger(final String name, final MessageFactory messageFactory) {
    // Note: This is the only method where we add entries to the 'loggerRegistry' ivar.
    Log4jTaglibLogger logger = this.loggerRegistry.getLogger(name, messageFactory);
    if (logger != null) {
        AbstractLogger.checkMessageFactory(logger, messageFactory);
        return logger;
    }

    synchronized (this.loggerRegistry) {
        logger = this.loggerRegistry.getLogger(name, messageFactory);
        if (logger == null) {
            final LoggerContext context = LogManager.getContext(false);
            final ExtendedLogger original = messageFactory == null ?
                    context.getLogger(name) : context.getLogger(name, messageFactory);
            // wrap a logger from an underlying implementation
            logger = new Log4jTaglibLogger(original, name, original.getMessageFactory());
            this.loggerRegistry.putIfAbsent(name, messageFactory, logger);
        }
    }

    return logger;
}
项目:logging-log4j2    文件:Log4j2Jira1688AsyncTest.java   
@Test
public void testLog4j2Only() throws InterruptedException {
    final org.apache.logging.log4j.Logger log4JLogger = LogManager.getLogger(this.getClass());
    final int limit = 11; // more than unrolled varargs
    final Object[] args = createArray(limit);
    final Object[] originalArgs = Arrays.copyOf(args, args.length);

    listAppender.countDownLatch = new CountDownLatch(1);
    ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);

    listAppender.countDownLatch.await(1, TimeUnit.SECONDS);
    Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);

    ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
    Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
}
项目:logging-log4j2    文件:Log4j2Jira1688Test.java   
@Test
public void testLog4j2Only() throws InterruptedException {
    final org.apache.logging.log4j.Logger log4JLogger = LogManager.getLogger(this.getClass());
    final int limit = 11; // more than unrolled varargs
    final Object[] args = createArray(limit);
    final Object[] originalArgs = Arrays.copyOf(args, args.length);

    listAppender.countDownLatch = new CountDownLatch(1);
    ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);

    listAppender.countDownLatch.await(1, TimeUnit.SECONDS);
    Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);

    ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
    Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
}
项目:monarch    文件:FastLoggerJUnitTest.java   
@Before
public void setUp() {
  this.messageFactory = new ParameterizedMessageFactory();
  this.mockedLogger = mock(ExtendedLogger.class);
  this.mockedMarker = mock(Marker.class);

  when(this.mockedLogger.getMessageFactory()).thenReturn(this.messageFactory);
  when(this.mockedMarker.getName()).thenReturn("MARKER");
}
项目:logging-log4j2    文件:SimpleLoggerContext.java   
@Override
public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) {
    // Note: This is the only method where we add entries to the 'loggerRegistry' ivar.
    final ExtendedLogger extendedLogger = loggerRegistry.getLogger(name, messageFactory);
    if (extendedLogger != null) {
        AbstractLogger.checkMessageFactory(extendedLogger, messageFactory);
        return extendedLogger;
    }
    final SimpleLogger simpleLogger = new SimpleLogger(name, defaultLevel, showLogName, showShortName, showDateTime,
            showContextMap, dateTimeFormat, messageFactory, props, stream);
    loggerRegistry.putIfAbsent(name, messageFactory, simpleLogger);
    return loggerRegistry.getLogger(name, messageFactory);
}
项目:logging-log4j2    文件:TestLoggerContext.java   
@Override
 public ExtendedLogger getLogger(final String name) {
     final ExtendedLogger extendedLogger = map.get(name);
     if (extendedLogger != null) {
return extendedLogger;
     }
     final ExtendedLogger logger = new TestLogger(name);
     map.put(name, logger);
     return logger;
 }
项目:logging-log4j2    文件:IoBuilder.java   
/**
 * Constructs a new IoBuilder for the given Logger. This method is provided for extensibility of this builder
 * class. The static factory methods should be used normally.
 *
 * @param logger the {@link ExtendedLogger} to wrap
 */
protected IoBuilder(final Logger logger) {
    if (!(logger instanceof ExtendedLogger)) {
        throw new UnsupportedOperationException("The provided Logger [" + String.valueOf(logger) +
            "] does not implement " + ExtendedLogger.class.getName());
    }
    this.logger = (ExtendedLogger) logger;
}
项目:logging-log4j2    文件:ByteStreamLogger.java   
public ByteStreamLogger(final ExtendedLogger logger, final Level level, final Marker marker, final Charset charset) {
    this.logger = logger;
    this.level = level == null ? logger.getLevel() : level;
    this.marker = marker;
    this.reader = new InputStreamReader(new ByteBufferInputStream(),
        charset == null ? Charset.defaultCharset() : charset);
}
项目:logging-log4j2    文件:ApiLogger.java   
ApiLogger(final ExtendedLogger logger) {
    super(logger.getName(), null);
    final Level javaLevel = LevelTranslator.toJavaLevel(logger.getLevel());
    // "java.util.logging.LoggingPermission" "control"
    AccessController.doPrivileged(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            ApiLogger.super.setLevel(javaLevel);
            return null;
        }
    });
    this.logger = new WrappedLogger(logger);
}
项目:logging-log4j2    文件:SLF4JLoggerContext.java   
@Override
public ExtendedLogger getLogger(final String name) {
    if (!loggerRegistry.hasLogger(name)) {
        loggerRegistry.putIfAbsent(name, null, new SLF4JLogger(name, LoggerFactory.getLogger(name)));
    }
    return loggerRegistry.getLogger(name);
}
项目:logging-log4j2    文件:SLF4JLoggerContext.java   
@Override
public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) {
    // FIXME according to LOG4J2-1180, the below line should be:
    // FIXME if (!loggerRegistry.hasLogger(name, messageFactory)) {
    if (!loggerRegistry.hasLogger(name)) {
        // FIXME: should be loggerRegistry.putIfAbsent(name, messageFactory,
        loggerRegistry.putIfAbsent(name, null,
                new SLF4JLogger(name, messageFactory, LoggerFactory.getLogger(name)));
    }
    // FIXME should be return loggerRegistry.getLogger(name, messageFactory);
    return loggerRegistry.getLogger(name);

    // TODO applying the above fixes causes (log4j-to-slf4j) LoggerTest to fail
}
项目:elasticsearch_my    文件:ESLoggerFactory.java   
public static Logger getLogger(String prefix, Logger logger) {
    return new PrefixLogger((ExtendedLogger)logger, logger.getName(), prefix);
}
项目:monarch    文件:FastLogger.java   
public FastLogger(final Logger logger) {
  this((ExtendedLogger) logger, logger.getName(), logger.getMessageFactory());
}
项目:monarch    文件:FastLogger.java   
public FastLogger(final ExtendedLogger logger, final String name,
    final MessageFactory messageFactory) {
  super(logger, name, messageFactory);
}
项目:monarch    文件:FastLogger.java   
public ExtendedLogger getExtendedLogger() {
  return super.logger;
}
项目:mynlp    文件:Log4J2Logger.java   
Log4J2Logger(Logger logger) {
    super((ExtendedLogger) logger, logger.getName(), logger.getMessageFactory());
}
项目:core-ng-project    文件:ESLoggerContext.java   
@Override
public ExtendedLogger getLogger(String name) {
    return getLogger(name, null);
}
项目:core-ng-project    文件:ESLoggerContext.java   
@Override
public ExtendedLogger getLogger(String name, MessageFactory messageFactory) {
    return loggers.computeIfAbsent(name, key -> new ESLogger(key, messageFactory, (LoggerImpl) LoggerFactory.getLogger(key)));
}
项目:nano-framework    文件:Log4j2Impl.java   
public Log4j2Impl(final Logger logger) {
    Assert.notNull(logger);
    this.logger = (ExtendedLogger) logger;
    setLoggerName(logger.getName());
}
项目:nano-framework    文件:Log4j2Impl.java   
public Log4j2Impl(final String loggerName) {
    Assert.hasText(loggerName);
    logger = (ExtendedLogger) LogManager.getLogger(loggerName);
    setLoggerName(loggerName);
}
项目:Izou    文件:IzouLogger.java   
/**
 * Creates a new file-logger for an addOn. The logger will log to a file with the addOnId as name in the logs folder
 * of Izou
 *
 * @param addOnId the Id of the addOn the logger is created for
 * @param level level of logger (at what level of log the logger should be activated
 * @return the new logger
 */
public synchronized ExtendedLogger createFileLogger(String addOnId, String level) {
    try {
        LoggerContext ctx = LogManager.getContext(false);
        Configuration config = ((org.apache.logging.log4j.core.LoggerContext) ctx).getConfiguration();

        //creates a new pattern layout (what determines how the log is formated, i.e. date, thread etc.)
        Layout layout = PatternLayout.createLayout("%d %-5p [%t] %C{10} (%F:%L) - %m%n", config, null, null, true,
                false, null, null);

        //creates a file appender for the logger (so that it knows what file to log to)
        Appender fileAppender = FileAppender.createAppender("logs" + File.separator + addOnId + ".log", "true",
                "false", "file", "true", "false", "false", "4000", layout, null, "false", null, config);
        fileAppender.start();
        config.addAppender(fileAppender);

        //creates also a console appender for the logger (so that the logger also outputs the log in the console)
        Appender consoleAppender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "console", null, null);
        consoleAppender.start();
        config.addAppender(consoleAppender);

        //adds appenders to an array called refs. It will later serve as references to the logger as to what
        // appenders it has
        AppenderRef fileRef = AppenderRef.createAppenderRef("file", Level.DEBUG, null);
        AppenderRef consoleRef = AppenderRef.createAppenderRef("console", Level.DEBUG, null);
        AppenderRef[] refs = new AppenderRef[]{fileRef, consoleRef};

        //creates the logger configurations for the logger, where the appender-references are also added
        LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.DEBUG, addOnId,
                "true", refs, null, config, null);
        loggerConfig.addAppender(fileAppender, Level.DEBUG, null);
        loggerConfig.addAppender(consoleAppender, Level.DEBUG, null);

        //finally creates the logger and returns it
        config.addLogger(addOnId, loggerConfig);
        ((org.apache.logging.log4j.core.LoggerContext) ctx).updateLoggers();
        ctx.getLogger(addOnId);
        ExtendedLogger logger = ctx.getLogger(addOnId);
        return logger;
    } catch(Exception e) {
        fileLogger.error("Unable to create FileLogger",e);
        return null;
    }
}
项目:apiman    文件:ApimanLog4j2LogDelegate.java   
ApimanLog4j2LogDelegate(final String name) {
  logger = (ExtendedLogger) org.apache.logging.log4j.LogManager.getLogger(name, new FormattedMessageFactory());
}
项目:logging-log4j2    文件:SimpleLoggerContext.java   
@Override
public ExtendedLogger getLogger(final String name) {
    return getLogger(name, null);
}
项目:logging-log4j2    文件:TestLoggerContext.java   
@Override
public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) {
    return new TestLogger(name, messageFactory);
}
项目:logging-log4j2    文件:TomcatLogger.java   
public static ExtendedLogger getLogger(final String name) {
    return getContext().getLogger(name);
}
项目:logging-log4j2    文件:Log4j2Logger.java   
public static ExtendedLogger getLogger(final String name) {
    return getContext().getLogger(name);
}
项目:logging-log4j2    文件:Log4jTaglibLogger.java   
public Log4jTaglibLogger(final ExtendedLogger logger, final String name, final MessageFactory messageFactory) {
    super(logger, name, messageFactory);
}
项目:logging-log4j2    文件:LoggerOutputStream.java   
protected LoggerOutputStream(final ExtendedLogger logger, final Level level, final Marker marker,
                             final Charset charset, final String fqcn) {
    this.logger = new ByteStreamLogger(logger, level, marker, charset);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerWriter.java   
protected LoggerWriter(final ExtendedLogger logger, final String fqcn, final Level level, final Marker marker) {
    this.logger = new CharStreamLogger(logger, level, marker);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerFilterOutputStream.java   
protected LoggerFilterOutputStream(final OutputStream out, final Charset charset, final ExtendedLogger logger,
                                   final String fqcn, final Level level, final Marker marker) {
    super(out);
    this.logger = new ByteStreamLogger(logger, level, marker, charset);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerBufferedInputStream.java   
protected LoggerBufferedInputStream(final InputStream in, final Charset charset, final ExtendedLogger logger,
                                    final String fqcn, final Level level, final Marker marker) {
    super(new LoggerInputStream(in, charset, logger, fqcn == null ? FQCN : fqcn, level, marker));
}
项目:logging-log4j2    文件:LoggerBufferedInputStream.java   
protected LoggerBufferedInputStream(final InputStream in, final Charset charset, final int size,
                                    final ExtendedLogger logger, final String fqcn, final Level level,
                                    final Marker marker) {
    super(new LoggerInputStream(in, charset, logger, fqcn == null ? FQCN : fqcn, level, marker), size);
}
项目:logging-log4j2    文件:LoggerBufferedReader.java   
protected LoggerBufferedReader(final Reader reader, final ExtendedLogger logger, final String fqcn,
                               final Level level, final Marker marker) {
    super(new LoggerReader(reader, logger, fqcn == null ? FQCN : fqcn, level, marker));
}
项目:logging-log4j2    文件:LoggerBufferedReader.java   
protected LoggerBufferedReader(final Reader reader, final int size, final ExtendedLogger logger, final String fqcn,
                               final Level level, final Marker marker) {
    super(new LoggerReader(reader, logger, fqcn == null ? FQCN : fqcn, level, marker), size);
}
项目:logging-log4j2    文件:LoggerInputStream.java   
protected LoggerInputStream(final InputStream in, final Charset charset, final ExtendedLogger logger,
                            final String fqcn, final Level level, final Marker marker) {
    super(in);
    this.logger = new ByteStreamLogger(logger, level, marker, charset);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerFilterWriter.java   
protected LoggerFilterWriter(final Writer out, final ExtendedLogger logger, final String fqcn, final Level level,
                             final Marker marker) {
    super(out);
    this.logger = new CharStreamLogger(logger, level, marker);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerReader.java   
protected LoggerReader(final Reader reader, final ExtendedLogger logger, final String fqcn, final Level level,
                       final Marker marker) {
    super(reader);
    this.logger = new CharStreamLogger(logger, level, marker);
    this.fqcn = fqcn == null ? FQCN : fqcn;
}
项目:logging-log4j2    文件:LoggerPrintWriter.java   
protected LoggerPrintWriter(final ExtendedLogger logger, final boolean autoFlush, final String fqcn,
                            final Level level, final Marker marker) {
    super(new LoggerWriter(logger, fqcn == null ? FQCN : fqcn, level, marker), autoFlush);
}
项目:logging-log4j2    文件:LoggerPrintWriter.java   
protected LoggerPrintWriter(final Writer writer, final boolean autoFlush, final ExtendedLogger logger,
                            final String fqcn, final Level level, final Marker marker) {
    super(new LoggerFilterWriter(writer, logger, fqcn == null ? FQCN : fqcn, level, marker), autoFlush);
}