SLF4J – Referenced API


SLF4J – Referenced API


”;


In this chapter, we will discuss the classes and methods that we will be using in the subsequent chapters of this tutorial.

Logger Interface

The logger interface of the org.slf4j package is the entry point of the SLF4J API. The following lists down the important methods of this interface.

Sr.No. Methods and Description
1

void debug(String msg)

This method logs a message at the DEBUG level.

2

void error(String msg)

This method logs a message at the ERROR level.

3

void info(String msg)

This method logs a message at the INFO level.

4

void trace(String msg)

This method logs a message at the TRACE level.

5

void warn(String msg)

This method logs a message at the WARN level.

LoggerFactory Class

The LoggerFactory class of the org.slf4j package is a utility class, which is used to generate loggers for various logging APIs such as log4j, JUL, NOP and simple logger.

Sr.No. Method and Description
1

Logger getLogger(String name)

This method accepts a string value representing a name and returns a Logger object with the specified name.

Profiler Class

This class belongs to the package org.slf4j this is used for profiling purpose and it is known as poor man’s profiler. Using this, the programmer can find out the time taken to carry out prolonged tasks.

Following are the important methods of this class.

Sr.No. Methods and Description
1

void start(String name)

This method will start a new child stop watch (named) and, stops the earlier child stopwatches (or, time instruments).

2

TimeInstrument stop()

This method will stop the recent child stopwatch and the global stopwatch and return the current Time Instrument.

3

void setLogger(Logger logger)

This method accepts a Logger object and associates the specified logger to the current Profiler.

4

void log()

Logs the contents of the current time instrument that is associated with a logger.

5

void print()

Prints the contents of the current time instrument.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *