为什么log4j2 syslog在一个数据包中发送2条消息

时间:2015-12-21 18:37:39

标签: java log4j2

当我们将一些消息记录到syslog中时,我们有应用程序。有时,当我们有大量流量(同时2个日志)时,syslog会在同一个数据包中记录2条消息:

这是来自tcpdump的消息:

413 62.346560   127.0.0.1   127.0.0.1   Syslog  698 LOCAL3.INFO: 1 2015-12-21T17:49:14.239+01:00 myserver.i.cz zip:/TestServertmp/_WL_user/my-app/zh0o33/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j2.xml - - - MyService|SD|21.12.2015 17:49:14.239|21.12.2015 13:22:16|8e8c46f5-5112-4fe2-ae27-4d9a1bc6f601|46cf84c9-0135-4e71-9a96-89f3fd6b562c\n<158>1 2015-12-21T17:49:14.239+01:00 myserver.i.cz zip:/TestServertmp/_WL_user/my-app/zh0o33/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j2.xml - - - MyService|SD|21.12.2015 17:49:14.239|21.02.2014 07:56:07|074006c1-8105-4b21-8e2c-cca30cea98b4|36eea480-cc23-4f46-ace1-12839c97f7e6\n

如您所见<158>表示启动另一条日志消息(优先级),这意味着local3.info但syslog将其发送到一个包中。为什么?这种情况每小时只发生1-2次。我正在使用upd,这意味着我已经立即使用了真正的

更新

有人可以解释为什么log4j2在abstractOutputStream中追加数据时会使用readLock而不是writeLock吗?

private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
private final Lock readLock = rwLock.readLock();


@Override
public void append(final LogEvent event) {
    readLock.lock();
    try {
        final byte[] bytes = getLayout().toByteArray(event);
        if (bytes.length > 0) {
            manager.write(bytes);
            if (this.immediateFlush || event.isEndOfBatch()) {
                manager.flush();
            }
        }
    } catch (final AppenderLoggingException ex) {
        error("Unable to write to stream " + manager.getName() + " for appender " + getName());
        throw ex;
    } finally {
        readLock.unlock();
    }
}

1 个答案:

答案 0 :(得分:0)

好的,这个bug应该在最新版本中修复:https://issues.apache.org/jira/browse/LOG4J2-1230

相关问题