Note that there are some explanatory texts on larger screens.

plurals
  1. POIDs for log messages when using SLF4J
    primarykey
    data
    text
    <p>I would like to add a unique identifier to log statements, so I am able to add documentation (externally, e.g. a wiki) to every log statement, so a user can quickly access the message related documentation using the id. The logging framework I would like to use is SLF4J/logback.</p> <p>I was not able to find documentation about related approaches except for some bits regarding auditing frameworks.</p> <p>There is the Marker concept which I thought could be usable for ID injection, or I could just add the ID to the message text itself.</p> <p>How would I add IDs to the logging statements "the right way"? Are there possibilities I didn't think of?</p> <p><strong>EDIT</strong></p> <p>The term <em>unique ID</em> just states there <em>should</em> be an identifier per log statement. A developer e.g. adds such an ID to a table/enum/whatever manually, which could be done wrong. Such ID has to be stable, so documentation can be based on it. So the ID itself is not what I am wondering about.</p> <p>My question is: what would be the right way of pushing the ID to the logger together with the message text? Would Markers be suited for this kind of requirement, should I embed the ID into the message text or is there some other possibility?</p> <p>So, basically, would I use</p> <pre><code>logger.info(IDMarkers.DB_CONNECTION_FAILED, "no connection to the database"); </code></pre> <p>or instead just</p> <pre><code>logger.info("[{}] no connection to the database", LogIDs.DB_CONNECTION_FAILED); </code></pre> <p>First approach has the advantage that showing the IDs is up to the logging system/its configuration.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload