Implementation of Advance Logging Mechanism

Neova Solutions
3 min readMay 5, 2020

--

The purpose of logging is to track the errors in any application, in a centralized manner. Logging should not be used only in big applications but also in smaller applications, especially if they play a crucial role with respect to the overall system. Log files can show any sort of event within an application or system, such as a failure, error, or a state transformation. When something inevitably goes wrong, such changes in state help indicate which transformation actually caused an error in the system.

Logging is mainly developed and used by system administrators on the operational level, for getting a high-level view of the complete system. A perfect log file should not be noisy and it should not contain distracting information. Log files should log only what is absolutely necessary and beneficial for error tracing.

Now, a common question that comes to every developer’s mind: “What exactly should I be logging?”

This depends very much on the nature of the application which is being developed. Logging everything can be helpful as you have a huge amount of data to analyze when you have an error in the system. But it is not at all helpful if it needs to be inspected by a single person.

Instead, developers should be thinking about, what we can call as 3 R’s of logging:

Logging the Right events in the Right Format for the Right user.

Some of the best practices for logging are:

  1. Add a logging framework before you write the code.
  2. The logging framework must support logging level modifications without restarting the application.
  3. Logging should not be an afterthought.
  4. We should avoid temporary log statements during development and also avoid ‘console.writeline’ statements.For example,

If we write logger function in such a way, then, in case if server or DB fails, then there will be an exception and logging will not be successful.

Common Logging Levels :

Here are some common logging levels, listed in order from least severe to most severe. When logging from your application, follow these levels:

At this level, you are basically looking to capture every possible detail about the application’s behavior. This is likely to consume huge resources in production.

From this level, you’re getting into “noisy” territory and formatting more information than you’d want in normal production situations.

This level corresponds to normal application behavior. You need not care too much about these entries during normal operations, but they generally provide the skeleton of what happened.

This log level indicates that you might have a problem or an unusual situation is detected

An error is a serious issue and it represents the failure of something important in your application. In this, the application itself is not failing but, this will require attention probably sooner than later, but the application can still keep running.

Fatal represents catastrophic situations in your application. Your application may stop to prevent some kind of serious problem, if possible.

There are many tools available in the market which any developer can use according to his/her requirement for a particular application. Some of these tools are:

  1. Log4j ( Mainly used for Java )
  2. Log4j2 ( Mainly used for Java )

Logging in Java requires using one of the available logging frameworks. These frameworks provide the methods and configuration necessary to create and send log messages. Java provides a built-in framework known as java.util.logging package.

Abstraction layers such as SLF4J decouple the logging framework from your application, allowing us to change logging frameworks on demand. The abstraction layer mainly provides a generic API and determines which logging framework to bind to at runtime in an application.

Read more to know 3 core components of Java logging API.

Originally published at https://www.neovasolutions.com on May 5, 2020.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Neova Solutions
Neova Solutions

Written by Neova Solutions

We transform ideas into beautiful products. Since 2007, we are empowering startups to build disruptive products that are feature-rich and robust.

No responses yet

Write a response