[SNMP4J] use SNMP4J + LOG4J

Frank Fock fock at agentpp.com
Tue Nov 21 22:48:24 CET 2006


Hi Bernard,

bernard collardey wrote:
> Hi Franck,
> 
> Nice having responded so quickly !
> 
> But, I thought ,as there is a Log4JFactory in your package, that I could use
> it !
> 

Yes, of course you can use it.

> I would like SNMP4J to log its messages in my logger instance, to have a
> single thread of messages, keeping things simple!
>
What do you mean with "single thread of messages"? May be
I do understand your logging approach, but Log4J and Java logging
IMHO only makes sense when used with different logger
(=LogAdapter in SNMP4J) instances?

> In fact after revisiting some code , I use as is your snmprequest class
> which does the major parts of sending SNMP messages.
> 

This class is only an example.

> But this class uses a JavaLogFactory ...
> 
> How can I still use this class without modifying it and have LO4J logging
> instead of Java logging ?

You cannot for the SnmpRequest class, but since this is only
an example, this should not make any trouble.
For any other implementation, you can use your own logging
factory.

Best regards,
Frank

> 
> Bests regards, 
> 
> Bernard,
> 
> -----Message d'origine-----
> De : Frank Fock [mailto:fock at agentpp.com] 
> Envoyé : vendredi 17 novembre 2006 21:24
> À : bernard collardey
> Cc : snmp4j at agentpp.org
> Objet : Re: [SNMP4J] use SNMP4J + LOG4J
> 
> 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