如何将snmp4j/snmp4j-agent jar的日志/sysout语句转发到使用的log4j2 API?

huangapple go评论60阅读模式
英文:

How to forward snmp4j/snmp4j-agent jar logs/sysout statement to log4j2 used API?

问题

我需要记录SNMP认证成功和失败的详细信息到已使用的log4j2框架中。我的代码仅会在认证/ SNMP GET / BULK命令成功时执行,而像传递的参数无效的用户名/ OID不存在的失败SNMP命令不会触发我的代码,响应将由使用的snmp4j/snmp4j-agent jar发送到客户端。在失败情况下,我会错过将日志记录到已使用的log4j2框架中的语句。

我已经尝试了一些互联网上提供的方法,但它们没有帮助。

  1. https://www.snmp4j.org/CHANGES-2.x.txt:使用了最新的snmp4j-log4j2.8.2版本,与snmp4j2.8.4和snmp4j-agent2.7.4 jar一起使用。

  2. https://bugzilla.redhat.com/show_bug.cgi?id=591762:要将SNMP4J日志发送到log4j,您可以在RHQ Java选项中添加“-Dsnmp4j.LogFactory=org.snmp4j.log.Log4jLogFactory”,或在代码中调用LogFactory.setLogFactory(new org.snmp4j.log.Log4jLogFactory())。

请问有人可以告诉我如何将snmp4j日志重定向到已使用的log4j2框架中吗?

英文:

I have an requirement to record the snmp authentication sucess and failure details into used log4j2 framework. My code will hit only for success of authentication/snmpget/bulk command and failure snmp commands like argument passed invalid username/OID not exist will not hit my code and response will go the client by used snmp4j/snmp4j-agent jar. On failure case i would miss to log statement into used log4j2 framework.

I have followed few below approaches provided in internet and those are not helpfull

1.https://www.snmp4j.org/CHANGES-2.x.txt: used latest snmp4j-log4j2.8.2 version with snmp4j2.8.4 and snmp4j-agent2.7.4 jar

  1. https://bugzilla.redhat.com/show_bug.cgi?id=591762 : To send SNMP4J logs to log4j, you can either add "-Dsnmp4j.LogFactory=org.snmp4j.log.Log4jLogFactory" to the RHQ java opts, or call LogFactory.setLogFactory(new org.snmp4j.log.Log4jLogFactory()) in code.

Can any one please help me how to redirect snmp4j logs to used log4j2 framework?

答案1

得分: 1

Your two approaches are correct. After that you need to configure the log4j2 framework.

请参考log4j2主页以获取有关如何使用log4j2的详细信息。

在拥有运行的log4j2配置之后,您可能希望更改一些snmp4j的日志级别。使用基于XML的log4j2配置,您需要添加以下行以输出所有snmp4j消息的调试日志级别:

<Logger name="org.snmp4j" level="debug" />

英文:

Your two approaches are correct. After that you need to configure the log4j2 framework.

Please refer to the log4j2 homepage for detailed information how to use log4j2.

Having a running log4j2 configuration you might want to change some snmp4j log levels. Using an XML based log4j2 configuration you have to add the following line to output all snmp4j messages with log level debug:

&lt;Logger name=&quot;org.snmp4j&quot; level=&quot;debug&quot; /&gt;

huangapple
  • 本文由 发表于 2020年8月3日 14:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63224592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定