[SNMP4J] use SNMP4J + LOG4J

bernard collardey bernard.collardey at cnafmail.fr
Fri Nov 17 19:21:42 CET 2006


 

Hi all,

 

I am quite disappointed !

 

I try to use log4j with SNMP4J.

 

But it doesn't work.

 

Here is a short sample I am trying  !!

 

public class SnmpTest {

 

            static {

                        PropertyConfigurator.configure("log4j.properties");

                        LogFactory.setLogFactory(new Log4jLogFactory());

            }

            

            public static void main(String[] args) throws SNMPCnafException
{

 

                        

                        InetAddress inetAddress;

                        String ipAddress = null;

                        try {

                                   inetAddress = InetAddress.getLocalHost();

                                   ipAddress =
inetAddress.getCanonicalHostName();

                        } catch (UnknownHostException e) {

                                   e.printStackTrace();

                                   System.exit(-1);

                        }

 

                        Logger logger =
Logger.getLogger(SNMPCnafHelper.class

                .getName());

                        

                        logger.info("Hello ... ");

                        

                        for (int i = 0; i < 10; i++) {

                                   SNMPCnafHelper.init("localhost/172",
ipAddress, "MSIPC","MSIP", "6",

                                                           "100");

                                   SNMPCnafHelper.send(1, "msg_partie_" + i,
"msg_partie_2" + i);

                                   

                        }

            }

}

 

 

Where SNMPCnafhelper is a wrapper for SNMP4J.

 

 

 

 

Here is the result :

AS you can see,  logging profucd by SNMP4J doesn't use my logger ! and
prints directly the message.

 

 

 

2006-11-17 19:18:31,020 INFO  [main    ] snmp.SNMPCnafHelper
- Hello ... 

17 nov. 2006 19:18:37 org.snmp4j.log.JavaLogAdapter log

INFO: UDP receive buffer size for socket 63.176.2.0/0 is set to: 8192

 

 

Any idea,

Thanks to all !

 




More information about the SNMP4J mailing list