Skip to content

Logging

Johannes Ernstsen edited this page Feb 20, 2019 · 2 revisions

Logging in EVHE

For the logging tasks of EVHE Apache's Log4j2 was selected.

This page will describe in short how to use the logger, how it logs from the server, and the best practices of logging

Using Log4J2

To use log4j2 you need to get a logger. This is done with LogManager.getLogger(someClass.class) where LogManager is from the package org.apache.logging.log4j and not the java.util.logging.LogManager.

Typically this is done as a static field in the top of a class and is accessed from all methods needing to log.

How the server is logged

The logging configuration is done in part by having the java.util.logging.manager set to org.apache.logging.log4j.jul.LogManager which directs all JUL logs to log4j2.

When to log

Logging should be done every time an interesting event occurs. Interesting is defined as something someone might want to know about.

To help filter different types of log-statements Log4J uses different levels. This is the description of these levels, taken from the documentation:

  • OFF (most specific, no logging)
  • FATAL (most specific, little data)
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE (least specific, a lot of data)
  • ALL (least specific, all data)

All logging statements in the log is prefixed with their modifier, enabling the debugger to use a grep to find the correct lines. Be sure to use the level correct level when logging for easier debugging.

The logger is set to INFO as default

Clone this wiki locally