Posts

Showing posts with the label Log4j

2014 Logging Frameworks You Would Like to Work With

In my previous post I have given an overview about Java's logging state as of January 2014 In this post I want to recommend which libraries to use for your java project. Main Logging Frameworks Most notable frameworks in this section include:  Java Util Logging ,  Log4j ,  Logback ,  Log4j2 I will go over them one by one: Java Util Logging  - This is Java's official logging framework it has been there since 2002 and is mostly copied from log4j which have released their library two years before (2000). no significant updates have been released to the Java logging component and it is mostly abandoned (although it still resides in the rt.jar core java files), the brave developers who had tried using it report a complicated logging framework which needs a good overhaul and the general advice is to stay away from it! Log4j  - No need to introduce Log4j which is the most used logging framework, and is with us for over 14 years!, log4j is a ve...

2014 Overview of Logging in Java

Why do you even need a logging framework [In a nutshell] ? Logging severity (Debug / Info / Error etc) Different loggers for different tasks Logging configuration in a single XML instead of all over your application Lots of other reasons Sorry, it is so obvious to me that I can't elaborate here any further What sorts of logging components are there ? Main Logging frameworks (use these to do the actual logging [log4j, logback etc]) Logging APIs (Facade): Due to several different logging frameworks, a need for a unified API has risen, and of course now there are several different "unified" APIs. Logging Parsers : Components which enable us to read log streams (files, socket etc) conveniently as well as introduce advanced searching & filtering within the log files Main Logging Frameworks The main logging frameworks is what people usually refer to when talking about in app logging, and I suggest a rough division in this department: Robust ...

Log All Your Web-method Calls

After a good deal of trial-and-error, and delving into the CXF code, I've found a way to get CXF to log every web-method call -- parameters and all. Put the following into your Tomcat's log4j.xml: <logger name="org.apache.cxf.service.invoker"> <level value="trace"> </level> </logger> The level should be set to "trace" by default; you won't get ton's of output, just a line (maybe 2) every time a web method is called. Unfortunately, the line is a bit wordy, as in Invoking method public boolean com.company.entities.ws.EntityManagementImpl.login(java.lang.String,java.lang.String,java.lang.String) throws java.io.UnsupportedEncodingException on object com.company.entities.ws.EntityManagementImpl@71e6b with params [CLI, arg2, arg3]. but it was either use the built in log statement or write a whole interceptor and add it to the chain processing the call. If we get really annoyed we could always tweak the source and rebuil...

Do you want your Log4J to send you emails with notifications?

Log4j.SMTPAppender Include the following files in the Component’s Classpath:   mail.jar   and   activation.jar . This appender’s trigger for sending an alert email is ERROR or FATAL. Lesser logs cannot be a trigger to send an email although they can be cached to be sent later on (bundled with a trigger level) when an ERROR / FATAL log occurs. In order to enable lesser than ERROR level logs, two arguments should be defined:   BufferSize   and   threshold . For an   XML   file use the following lines: <appender name="mail" class="org.apache.log4j.net.SMTPAppender"> <param name="SMTPHost" value="172.16.100.3" /> <param name="From" value="ChaiAvi@Chaiware.googlepages.com" /> <param name="To" value="Chaiavi@Chaiware.googlepages.com" /> <param name="Subject" value="[LOG] ..." /> <param name="BufferSize" value="2" /> <param name=...