Externalizing the logger and handler configuration to properties file

In all my previous posts under java logging, I have configured logger and handler programmatically. We can externalize those configurations to properties file also. The advantage of this approach is that we can change configurations at any time without recompiling java class. In this post I will show with example how to do that. Let’s…… Continue reading Externalizing the logger and handler configuration to properties file

Logging to database using java logging framework

This post explains how to log messages to the database. Create a table with below schema CREATE TABLE logging ( loggername VARCHAR(50) NULL DEFAULT NULL, threadId INT(11) NULL DEFAULT NULL, loglevel VARCHAR(50) NULL DEFAULT NULL, logmessage VARCHAR(50) NULL DEFAULT NULL ) Create a custom handler which will log the message to the database. In our…… Continue reading Logging to database using java logging framework

Creating a custom log message format

This post explains how to create a custom log message format. Out of the box java provides two log formats SimpleFormatter and XMLFormatter. Both extends the abstract super class Formatter. We can create our own custom format. Below is the code of the custom format CustomFormatter 1 package Logging; 2 3 import java.util.logging.Formatter; 4 import…… Continue reading Creating a custom log message format