Difference between revisions of "Log levels"

From DarkWiki
Jump to: navigation, search
(Levels)
(Levels)
Line 4: Line 4:
  
 
==Levels==
 
==Levels==
 +
 +
===Standard===
 +
 +
These are standard definitions that demand certain actions.
 
   
 
   
 
{| class="wikitable"
 
{| class="wikitable"
Line 16: Line 20:
 
||DEBUG||A piece of diagnostic information, typically used for fault analysis. These only normally appear in test environments (including development ones). However, it may be desirable to switch nodes into debug mode under certain circumstances.
 
||DEBUG||A piece of diagnostic information, typically used for fault analysis. These only normally appear in test environments (including development ones). However, it may be desirable to switch nodes into debug mode under certain circumstances.
 
|}
 
|}
 +
 +
===Deprecated===
 +
 +
These are either poorly defined or not well supported, and must therefore be avoided.
  
 
{| class="wikitable"
 
{| class="wikitable"

Revision as of 07:18, 5 June 2019

Introduction

Log levels are used to indicate the importance of a particular message and are important in fault detection and diagnosis.

Levels

Standard

These are standard definitions that demand certain actions.

Level Meaning
ERROR A serious error has occurred, and someone must take action. Normal operation is where there are no errors occurring.
WARN A problem was encountered, but has been dealt with in some manner. It may be worked around, but it could be indicative that there may be something about to go wrong.
INFO A useful piece of information, typically linked to a specific event. These are the log messages that appear in normal logging.
DEBUG A piece of diagnostic information, typically used for fault analysis. These only normally appear in test environments (including development ones). However, it may be desirable to switch nodes into debug mode under certain circumstances.

Deprecated

These are either poorly defined or not well supported, and must therefore be avoided.

Level Meaning
TRACE This is rarely used. It's used to indicate to the reader the path by which code flows, including all relevant arguments and parameters. Normally, DEBUG is enough.
FATAL This is rarely used, and is no longer supported in some loggers (e.g. SLF4J). It's used to indicate to the system is about to crash.

Standard logging

If the last object is an Exception, it will be logged with its stack trace (unless you use the string insertion markers, "{}").

    @ExceptionHandler({RuntimeException.class})
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public @ResponseBody ErrorResponse handleInternalServerError(Exception ex) {
        LOG.error(
            "handleInternalServerError Unhandled error - {}",
            ex.getClass().getName(),
            ex
        );
        return new ErrorResponse(
            ex.getClass().getName(),
            ex.getMessage()
        );
    }