1

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?

Raghu
  • 23
  • 4

1 Answers1

1

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:

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

Uli
  • 1,390
  • 1
  • 14
  • 28
  • 1
    Thanks for reply, I have added above Logger into log4j2.xml as following below. The below appenderRef "alarm" is used and pointed existing log of application. Still i would not see any log refernces for snmp event when used snmpget/snmpbulkwalk. – Raghu Aug 07 '20 at 10:14