Log4j: a brief introduction

What is Log4j? 

Log4j is a logging Java Framework, which offers a more efficient and modular alternative to System.out.println. It is an Apache Software Foundation Project, which in turn is part of bigger initiative called Apache Logging. The current version is now Log4j 2.0, which has superseded Log4j 1.x.

Why Log4j? 

Log4j controls the logging behavior through the editing of a configuration file at the runtime and without modifying the application binary. One of its distinctive features is the notion of inheritance of loggers. In a nutshell,  by employing a ‘log hierarchy’ it is possible to control which log statements are outputted according to the notion of  ‘logging level’.

There are 6 levels of logging in Log4j:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

The ability of selecting the logging level helps reduce the volume of logged output and make life easier when inspecting logs.

The target of the log output can be a file, an OutputStream, a java.io.Writer, a remote Log4j server, a remote Unix Syslog daemon, etc.

 What do I need to know first and foremost? 

There are 3 main concepts underlying Log4j,  as follows :

  • LOGGERS
  • APPENDERS
  • LAYOUT

Loggers: Loggers are basic, developer customized, org.apache.log4j.Logger objects, which provide control mechanism over disabling or enabling certain type of log statements when logged against them. Each class in your application can have an individual logger or a common logger. Log4j provides a root logger where all loggers (including custom ones) will inherit from. This also means that it is not strictly necessary to have an individual logger for each class as you can always use the root logger by calling Logger.getRootLogger(). Nevertheless, it is not recommended to use the root logger.

As mentioned already, we can set the level of each logger, according to the set of logging levels. The root logger always has a default level assigned to it, which is DEBUG.

Appenders: Appenders define the properties of a Logger, meaning that they set the target or the destination of a specific logger. For example, the Default root level Logger has  a default Console Appender associated with it, thus it prints to the Console by default.

Layouts: Layouts define the style and content of the output log. Some built-in layouts are provided with log4j, although it is also possible create your own layouts, if required. For example, a layout can specify the date and time or include information about the line number from which the log originates.

 


Relevant links and resources:

http://logging.apache.org/

http://logging.apache.org/log4j/1.2/index.html

http://logging.apache.org/log4j/2.x/

https://supportweb.cs.bham.ac.uk/docs/tutorials/docsystem/build/tutorials/log4j/log4j.html

http://salmanawan.com/hello-world-%E2%80%93-log4j-tutorial/

Watch “Free Spring Framework Webinar” on YouTube

Inside IBM’s billion-dollar bet on Watson

http://www.news-republic.com/Web/ArticleWeb.aspx?regionid=3&articleid=26149003

Apple present its new programming language: Swift

At WWDC ’14, Apples has launched Swift, a brand new Xcode Programming Language, which seems to howtshine Objectve C when it comes to performance and syntax simplicity.

Here the Apple press release:

“Swift is a powerful new programming language for iOS and OS X® that makes it easier than ever for developers to create incredible apps. Designed for Cocoa® and Cocoa Touch®, Swift combines the performance and efficiency of compiled languages with the simplicity and interactivity of popular scripting languages. By design, Swift helps developers write safer and more reliable code by eliminating entire categories of common programming errors, and coexists with Objective-C® code, so developers can easily integrate Swift into their existing apps. Xcode® Playgrounds make writing Swift code incredibly interactive by instantly displaying the output of Swift code.”

Few resources:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/index.html

http://www.learnswift.tips/

Data Science: An Introduction – Wikibooks, open books for an open world

I thought it was worth mentioning this collaborative book on Data Science, which is gradually taking shape on Wikibooks. From time to time I have a look and new sections are completed with a very accessible language:

Data Science: An Introduction – Wikibooks, open books for an open world.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: