本文介绍了SocketAppender和PatternLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个记录器,可将日志发送到日志服务器存储.这项工作正常,但未使用 patternlayout .有或没有,都不会改变任何东西.我相信记得读过 socketappender 使用的是自己的模式,而不是其他模式.

I have a logger that send log to a log server storage. This work fine but the patternlayout isn't used. With or without that doesn't change anything. I believe remember to read somewhere that socketappender use is own pattern and not others.

<appender name="LOGSTASH" class="org.apache.log4j.net.SocketAppender"> 
        <param name="Port" value="5000"/>
        <param name="RemoteHost" value="192.168.81.131"/> 
        <param name="ReconnectionDelay" value="5000"/>
        <param name="LocationInfo" value="true" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
      </layout>
</appender> 

但是在此文档(以及其他一些文档)上小伙子们用这个.此文档的示例:

But on this documentation (and a few other) thay use this. Example from this doc :

<appender name="A1" class="org.apache.log4j.net.SocketAppender">
    <param name="RemoteHost" value="localhost"/>
    <param name="Port" value="5000"/>
    <param name="LocationInfo" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
    </layout>
    </appender>

因此不可能将个人模式与 socketappender 一起使用,还是我的错?

So is it impossible to use personnal pattern with socketappender or is it my fault?

如果不可能,是否可以使用自定义模式的tcp日志记录的替代附加程序?

If it's impossible is there an alternative appender for tcp logging with custom pattern?

推荐答案

SocketAppender 似乎没有使用布局.

在此处查看文档

因此,我使用 SyslogAppender 进行替换.由于未使用的可能性(例如设施和优先级),它并不完美,但效果很好.

So I use a SyslogAppender to replace. It's not perfect because of unused possibilies (like facility and priority) but works fine.

这篇关于SocketAppender和PatternLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:36