Skip to content

Using the "Logger"

Wesley Levasseur edited this page May 7, 2021 · 2 revisions

Definition

Logger consists of adding processing to allow the transmission and storage of messages following events.

This class is a default Logger if the user does not want to create one himself by implementing ILogger, by default all Levels are activated.

Use

Recall

/**
 * This constructor allows you to create a Logger. It is usually created from the Factory itself.
 *
 * @param name The name of the Logger.
 * @param loggerFactory The Logger Factory.
 */
public Logger(@NotNull final String name, @NotNull final ILoggerFactory loggerFactory) {
    this.name = name;
    this.loggerFactory = loggerFactory;
}

Where ?

Primarily the Logger will serve from a classroom, but it can also be used for other purposes coming from the imagination of the user. You will find some examples of use below.

final ILogger logger1 = this.loggerFactory.getLogger("Logger1");
final Logger logger1_ = (Logger) logger1;
final Logger mainClassLogger = (Logger) this.loggerFactory.getLogger(this.getClass());
final ILogger mainClassLogger_ = mainClassLogger;
final Logger _mainClassLogger = (Logger) this.loggerFactory.getLogger(MainClass.class);
final ILogger _mainClassLogger_ = _mainClassLogger;

The Levels in the Logger?

By default all Levels are enabled. But you can turn them off and back on as you like. You can also check if a Levels is active.

logger1.isDebugging();
logger1.activateDebugging();
logger1.deactivateDebugging();

logger1.isInforming();
logger1.activateInforming();
logger1.deactivateInforming();

logger1.isErroring();
logger1.activateErroring();
logger1.deactivateErroring();

logger1.isTracing();
logger1.activateTracing();
logger1.deactivateTracing();

logger1.isWarning();
logger1.activateWarning();
logger1.deactivateWarning();

Get a logs?

Depending on the Levels you want to log you could do in several ways, some of which are presented to you.

logger1.debug("message");
logger1.info("message", new Throwable("with errors"));
logger1.error("{MessageFormater}", new Object());
logger1.trace("{MessageFormater}", new Object(), new Object());
logger1.warn("{MessageFormater}", new Object(), new Object(), ...);