[SNMP4J] use SNMP4J + LOG4J

Frank Fock fock at agentpp.com
Fri Nov 17 21:23:51 CET 2006


Hi Bernard,

Why do you think that SNMP4J should use your
Logger instance to log its messages?
What did you expect?

If you want to use your own logging mechanism
(for example a single Log4J logger instance),
then you will have to write your own factory.

Best regards,
Frank

bernard collardey wrote:
>  
> 
> 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 !
> 
>  
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list