Not able to enable snmp4j2.5..jar logs into java application

Hi All ,

i would like to debug snmp4j logs for each snmp request it is coming from an java application .

followed below approaches :

Approach 1) Enable Simple Logging

In the main class execute the following code before any SNMP4J code is executed statically or at runtime:

static {
LogFactory.setLogFactory(new ConsoleLogFactory());
ConsoleLogAdapter.setDebugEnabled(true);
}

Approach 2) Enable Log4J Logging

In the main class put:

static {
LogFactory.setLogFactory(new Log4jLogFactory());
org.apache.log4j.BasicConfigurator.configure();
LogFactory.getLogFactory().getRootLogger().setLogLevel(LogLevel.ALL);
}

Approach 3) Enable Java Logging
To enable Java logging two steps are necessary:

Code
static {
LogFactory.setLogFactory(new JavaLogFactory());
// Optionally set log level on root logger:
LogFactory.getLogFactory().getRootLogger().setLogLevel(LogLevel.ALL);
}

none of the above approach did not worked to push logs from snmp4j.jar to java application jar .

Any body suggest ?

Probably the problem is related to your requirement „to log into Java application“?
How does the Java application log? Where is stdout written to? …

For the Java and Log4j logging you need to define a logging format and appended in the logging framework specific manner, but when the console logging does not work the problem is more related to your expectations where the log output should appear…

Thanks for the reply .

java application logs are redirected to log file /var/log/test.log due to configuration in log4j.properties file something like below.
log4j.logger.com.example.snmp=DEBUG, file

Redirect log messages to a log file

og4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.file.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.file.rollingPolicy.FileNamePattern=/var/log//test-%i.log.gz
log4j.appender.file.rollingPolicy.ActiveFileName=/var/log/test.log

Console appender is not enabled.
I tried enabling snmp4j jar logs into /var/log/test.log file by adding below line in log4j.properties file as well.
log4j.logger.org.snmp4j=DEBUG, file
But it didn’t worked.
Please suggest how it can be enabled.

Thanks

Thank you , issue resolved

Hi @rattaiah
Can you please post how issue was resolved. This will help others facing similar issues.
Thanks