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.
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.
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.
Logger logger = new Logger(“com.test”);
Logger childLogger = new Logger(“com.test.subDomain”);
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 –
- Debug – this is the lowest level of the hierarchy.
- Info – this is used when some non negative event has taken place.
- 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.
- 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
- Fatal – used when something so terrible happened that the system might go down.
To be continued …..