Home » Core Java » util » logging (page 2)

logging

Create a sequence of log files

This is an example of how to create a sequence of log files. Creating a sequence of log files implies that you should: Create a new instance of a Logger. Create an instance of FileHandler with a specific number of logging files sequences, a specific size for each file and append set to true. In the example 5 files will ...

Read More »

Create custom Formatter for Logger handler

In this example we shall show you how to create custom Formatter for a Logger‘s Handler. The Handler usually uses a Formatter associated with it to format LogRecords. The Formatter takes a LogRecord and converts it to a string. LogRecord objects are used to pass logging requests between the logging framework and individual log Handlers. To create a custom Formatter ...

Read More »

Set Formatter for Logger handler

With this example we are going to demonstrate how to set a Formatter for a Logger Handler. The Formatter is used by the Handler to format LogRecords. In short, to set a Formatter for a Logger’s handler you should: Create a new Logger instance with getLogger(String name) API method of Logger. Create a new FileHandler to write to a specific ...

Read More »

Set filter on Logger handler

This is an example of how to set a filter on a Logger’s Handler. The Filter is used to provide control over what is logged, beyond the control that the levels provide. Each Logger and each Handler can have a filter associated with it. The Logger or Handler will call the isLoggable(LogRecord record) method to check if a given LogRecord ...

Read More »

Log method call

In this example we shall show you how to log a method call. We have implemented the LogMethodCall Class, with a simple method to log its messages. The basic steps of the example are described below: The call(String arg1, Object arg2) method of the class takes a String argument and an Object argument and returns a boolean value. The method ...

Read More »

Write Log entries to log file

With this example we are going to demonstrate how to write Log entries to a log file. In short, to write Log entries to a log file you should: Create a new FileHandler to write to a specific file. Create a new Logger instance with getLogger(String name) API method of Logger. Add the handler to the Logger, with addHandler(Handler handler) ...

Read More »