Logging levels

The levels of an application log from TRACE to FATAL, the threshold that filters, what to write at each level, the anatomy of a line and the difference from a plain print to the screen.

  • 29 cards
  • 5 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. Understand

A few cards from the deck

  • Application log: what is it?

    Show the answer

    The series of dated events a program writes while it runs, to a file or a stream, so that what happened can be understood afterwards.

    In production, nobody watches the program run and no debugger is attached: the log is the only record of what happened.

  • The threshold is set to INFO. Which messages does this code write to the log?

    ```java
    log.trace("entrée dans total()");
    log.debug("i = {}", i);
    log.info("commande {} créée", id);
    log.warn("stock bas : {}", stock);
    log.error("paiement refusé", e);
    `

    • Order created, low stock, payment refused
    • Only the low stock and the payment refused
    • All five messages, from most detailed to most serious
    • Only the order created, at the INFO level
    Show the answer

    Order created, low stock, payment refused

    The INFO threshold keeps INFO, WARN and ERROR, and drops TRACE and DEBUG. Low stock and payment refused alone would match a WARN threshold.

  • From least to most serious, the levels come in the order TRACE, DEBUG, …, …, ERROR.

    Show the answer

    From least to most serious, the levels come in the order TRACE, DEBUG, INFO, WARN, ERROR.

    INFO tells the normal life of the service, WARN flags an absorbed anomaly. A threshold at one level keeps that level and all the following ones.

  • Log level: what is it?

    Show the answer

    The severity attached to a message: TRACE, DEBUG, INFO, WARN, ERROR (and FATAL in some libraries), from the most detailed to the most serious.

    It lets you sort messages: keep the alerts in production and switch the detail on only while investigating. SLF4J, for example, stops at ERROR.

  • A service in production fills the disk overnight with millions of DEBUG lines. What should be done?

    • Remove every logging call from the code
    • Replace the calls with System.out.println
    • Move all messages to the ERROR level in the code
    • Raise the threshold to INFO in the configuration
    Show the answer

    Raise the threshold to INFO in the configuration

    The threshold exists for exactly this: tune the volume without changing the code, and lower it to DEBUG again for the time of an investigation. Moving everything to ERROR would drown the real errors.