--- sidebar_position: 2 title: "2" description: "Logging Specification v2" --- # Version 2 This document aims to outline a unified specification, inspired by various logging implementations. ## Cross-language considerations ### Casing This specification assumes that methods are written in CamelCase and enums in CONSTANT_CASE. If the programming language your implementation uses has different conventions, use them instead. ### Enums This specification assumes that the programming language your implementation uses supports enums. If it doesn't, use integer constants instead. If that isn't possible, use strings. ## What a good logger needs A good logger implementation needs the following things: - levels, to distinguish message importance - a message's origin, to know from where a message came - the actual log message ## Levels An implementation must provide at least five log levels and may implement an optional one to be able to determine a message's priority.
Name Method name Printed name Enum name Optional
Diagnostic diag DIAG DIAGNOSTIC No
Verbose verb VERB VERBOSE No
Silent Warning sarn SARN SILENT_WARNING No
Informational info INFO INFORMATIONAL No
Warning warn WARN WARNING No
Error error ERR! ERROR No
Crash crash CRSH CRASH If the language and/or platform does not provide a good native crash handler
## Format A format is required to represent a log message as well as relevant information in a human way. The logging format shall be minimal but extensible with so-called "format features", which may be chained together. A few optional and required features are listed in this specification. Implementation-specific features may be added, depending on the use case, environment, language and other variables. ### Default format `[ ] ` ### Feature `formatting` The content stays the same but the message is colorized. This feature is optional. ### Feature `runtime` Prepends the time the implementation or application is running in milliseconds. \ Example by extending the default: `[ms] [ ] ` This feature is required. ### Features `date` & `time` Prepends the date and/or the time to the output. \ Example by extending the default: `[ [time]] [ ] ` This feature is required unless the language of the implementation does not provide good support for dates and time. ### Features `methodName` & `lineNumber` Appends the method name and/or line number to the origin. Example by extending the default: `[ #~] ` This feature is required unless the language of the implementation does not provide insufficient or any automatic (ie. without developer intervention on log call) support. ### All features Below is an example of how the format would look like if all features mentioned in this specification were enabled. #### With placeholders `[ms] [