Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Log4j Monitoring tool

Options
  • 20-03-2014 12:56pm
    #1
    Registered Users Posts: 16,759 ✭✭✭✭


    Hi folks

    Looking for advice on what tool would be best for monitoring log4j log files? Not necessarily free but preferably!

    Basically we'd like email alerts off a particular server for all applications for Fatal or critical issues that may pop up in the various log files. Would have to be real-time.

    Any advice\tips greatly appreciated.

    Regards
    Trilla


Comments

  • Registered Users Posts: 1,263 ✭✭✭00sully


    doesn't log4j provide this natively? obviously you need an SMTP server but I use log4net and can add an SMTP appender to my log configuration. Same is surely true of log4j!? can also do event viewer alerts. No point monitoring files when the logger can hook into the alert mechanism directly!

    and sure enough: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SMTPAppender.html


  • Registered Users Posts: 27,161 ✭✭✭✭GreeBo


    Yep, I've used log4j SMTP appender and also configured different throttle levels for different appenders to effectively give you a monitoring solution for free (assuming someone is watching their email!)


  • Registered Users Posts: 16,759 ✭✭✭✭Nalz


    Thanks for the replies guys

    Kind of a novice when it comes to these things so what would be (in layman's terms) the steps involved to get this SMTP appender up and running, or should I just nab a developer and go through it with him :) ?

    Cheers


  • Registered Users Posts: 7,863 ✭✭✭The_B_Man


    It should just be a case of configuring the log4j.properties file with the values of your company's SMTP server, and writing a small bit of code to send the mail through logger.
    Or you could always extend your own logger class that emails messages whenever logger.fatal is called. That way you wont really need to change the existing code.

    You might be able to use the first answer in this link as a guide. Just in the code, change the logger.info part to logger.fatal or severe or whatever.
    http://stackoverflow.com/questions/4306212/using-log4j-to-send-email-reports-via-the-smtpappender


  • Registered Users Posts: 1,263 ✭✭✭00sully


    I don't think you need to write any code at all - if you configure the SMTP appender in the configuration file that should be enough. for example: (directly from log4net site)

    [HTML]<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
    <to value="to@domain.com" />
    <from value="from@domain.com" />
    <subject value="test logging message" />
    <smtpHost value="SMTPServer.domain.com" />
    <bufferSize value="512" />
    <lossy value="true" />
    <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="WARN"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
    </appender>[/HTML]

    It looks as though this is different in Java but again, if you have a configuration file that should suffice to just add the appender (http://wiki.apache.org/logging-log4j/SMTPAppender)

    [HTML]<appender name="AdministratorEmail" class="org.apache.log4j.net.SMTPAppender">
    <param name="BufferSize" value="512" />
    <param name="SMTPHost" value="some.email.host.org" />
    <param name="From" value="appname@server.com" />
    <param name="To" value="adminA@server.com,adminB@server.com" />
    <param name="Subject" value="SomeApplication on SomeServer12" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%d{ISO8601}]%n%n%-5p%n%n%c%n%n%m%n%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="error" />
    <param name="LevelMax" value="fatal" />
    </filter>
    </appender>[/HTML]


  • Advertisement
  • Registered Users Posts: 27,161 ✭✭✭✭GreeBo


    Take a look at the SMTP appender here

    You have to write some classes implementing interfaces if you want non standard behaviour (discriminator, aggregator, etc) but you should get something up and running out of the box.


  • Registered Users Posts: 16,759 ✭✭✭✭Nalz


    Thanks all!


Advertisement