Sunday, April 8, 2018

ADF Logger - 2 (Java Logger Introduction - Log Message)

Hi All,

I hope you read my last post on java logger.This is second post which explain missing parts from post one. To just recap in first we were trying to understand very basic about logger. The point which we are trying to understand is.

1-"Why default logger logs message on console ? Even we did not set any handler in logger object."
2-"Why default logger only log INFO, WARNING and SEVERE ?"


For this post i am still using old class , you can see the full class at JavaLogFirst.java.
The below code which i am interested for this post is .

/**
* Since default log level is INFO therefore it will not print below log message
*/
private void noPrintDefaultLoggingInfo()
{
_alogger.fine( "Printing number of default handlers " + _alogger.getHandlers().length );
_alogger.finer( "Printing global class " + _alogger.getGlobal() );
_alogger.finest( "Printing filter class " + _alogger.getFilter() );
_alogger.config( "Printing resource bundle name " + _alogger.getResourceBundleName() );
}

Above method is straight forward ,if we run JavaLogFirst class , it will only log message which are info or more than this.


This is happening because when java logger framework trying to create logger object it will read some values from logger properties file.( Logging.properties) . And below properties values are responsible.

# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers.  For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level= INFO



# Limit the message that are printed on the console to INFO and above.
 java.util.logging.ConsoleHandler.level = INFO

In the log file, it has only two properties value which are related to logging level message. .level property is global property and ConsoleHandler.level is clearly related to console handler . And this case default handler is console handler.

The first thing i am going to do is to set  java.util.logging.ConsoleHandler.level = FINEST and then run the main method to see if this is print all logger messages. After running, it is same output , mean changing above entry is not sufficient to print all the logger message.

Now i also changed .level value to FINEST and see if this change help to print all messages. And yes indeed this helped and now i can see all the logger level messages.

.level= FINEST
java.util.logging.ConsoleHandler.level = FINEST