logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Masterson <mark_master...@compuserve.com>
Subject Re: Generating SNMP traps from Java Application
Date Mon, 13 Feb 2006 19:51:11 GMT
Hi Swarna,

Ah, fantastic.  Swarna, I've been meaning to get to your mail (to me 
directly) for about a week now, but I wanted to "cc" my reply to the 
log4j list, since most of your questions are generic log4j questions, 
and not specific to the SNMPTrapAppender. 

1. Bender has already explained what you need to do in your Java code, 
to achieve what you want.  But just to be sure it's clear, and using 
Bender's example further, here's what your code would then look like:

logger.warn("Logging a trap out to somewhere...") // this is *your* 
logger, the one you already had...
mySnmpLogger.warn("This goes out to a trap") // this is the new, extra 
logger, that you use to send traps.

2.  You don't install JoeSnmp, or Wengsoft, or Snmp4j, for that matter.  
You add the relevant Jar to your CLASSPATH, and that's it.  Where that 
is/what that means is application specific, and you're going to have to 
tell us a whole lot more about your application, if you need us to help 
you with that.

3. The changes that you need to make in the log4j.xml file are rather 
extensively documented on my Web site, and in the Javadocs for the 
appender, which come with the download.  See here -- 
-- for example.

4.  How can you test it?  Now, that's a good question.  There is no easy 
way to "catch" traps in a unit test, so it's difficult to do a pure unit 
test.  If anybody has an idea on how to do this, I'd be all ears.  In 
the meantime, if you've access to a Windows PC, I suggest Ncomtech's 
free Trap Receiver program (http://www.ncomtech.com/download.htm).  Set 
it up to be the "listening end" (i.e. localhost and some free port in 
your log4j.xml, and set up the Trap Receiver to listen on this port), 
and you can use it to receive traps that you generate with your unit tests.



Swarna Mani wrote:
> My Name is Swarna. I am trying to implement generation of SNMP traps from Java
> application using log4j. We already have log4j implemented for generating log
> messages.
> When I searched in the web, I came across posts in http://blog.gmane.org Wherein
> it is explained that code like
> logger.warn("Send a trap");
> will generate a trap.
> My question is we use similar one to generate logs, how can we distinguish
> between entries for logs and entries for traps?
> Also I find that it is mentioned that all we need to do is change the
> configuration script. I am thinking of using JOESNMP.
> Will it be possible for you to provide me the steps  on
> What needs to be coded in java application to differentiate logs and traps? 
> Where do I install joesnmp? 
> What changes I need to make to log4j.xml? 
> How can I test the same? 
> Thanks in Advance,
> Swarna
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message