2015-08-25

DataTable provides solution, when user having a huge data displayed in
a table and user want to perform filtering operations on a table. It
provides paging options too. DataTables is a plug-in for the jQuery
Javascript library. It is a highly flexible tool, based upon the
foundations of progressive enhancement, and will add advanced
interaction controls to any HTML table.

This blog explains to implement Java logging with DataTables.
Log all the messages in an applicaton in DataTable. So user
can filter the particular messages, date and time. It provides
paging also.

Libraries

User need to include these following files in a folder. (One "css" and two java script files)
jquery.dataTables.min.css
jquery.dataTables.min.js
jquery-1.11.3.min.js

Directory Structure

./src (Java source)

./lib  (contains ".css" and ".js")

Logger Initializing

Logger object is used to log messages.
User should maintainonly one logger for throughout the application,
hence the private constructor.

User need to provide the file name using FileHandler. (DataTableLogger.java)

User can provide a differnet path/file name in

This case user has to copy JavaScripts files and "css" files in
destination folder using File.copy()

Formatter Class

A Formatter is a abstract class provides support for formatting LogRecords. Typically each logging Handler will have a formatter associated with it. The Formatter takes a LogRecord and converts it to a string. Using makes a html tags using getHead and getTail. getHead function will be called at the initializing of Logger (beginning of application). getTail will be called at end of application just before closing the application. (HtmlFormatter.java)

format()

getHead()

getTail()

User can perform variety of operations inside format method. Ex: User can display error messages in red color and Notification messages in greecolor etc.

Demo: User can invoke using the following snippet. (Demo.java)

Show more