Logging in an application

Why file logs over database logs?

Why do we even need logs, when we have databases?

Databases are cool for storage of data. But as far as log performance is concerned, log files are far better than databases. They prevent databases from getting heavier than they already are, reduce http requests. Also read/write is much faster than read/write of database. Log files look like the clear winner.

Log4j

Now that we have established that log files are much better than logs in database, let us discuss in brief how the logging works in java applications. Log4j is one of the most used java based logging utility. May be, THE most used java based logging utility.

About Log4j

The logging is done using an object called logger, there exists a root logger which exists by default. And any other logger is a child logger of the root logger.

Logging Hierarchy 

Logger logger = new Logger(“com.test”); 
Logger childLogger = new Logger(“com.test.subDomain”);

Log Levels

According to the need and severity of the event that has taken place, the programmer needs to decide what level the log is to be written.
You can create your own log levels, but the most commonly used are –

  1. Debug – this is the lowest level of the hierarchy.
  2. Info – this is used when some non negative event has taken place.
  3. Warn – warn level is used when something has gone wrong in the system, although the incident is not bad enough to bring the whole system down.
  4. Error – This is used when some error has occurred in the system, the error log is considered to be severe. However, the system may not come down
  5. Fatal – used when something so terrible happened that the system might go down.

To be continued …..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: