log: group "enum" consts and touch-up docs
Also updated the level descriptions with their documentation from logrus. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4a36022e20
commit
0b6333a412
@ -34,38 +34,42 @@ var (
|
|||||||
L = logrus.NewEntry(logrus.StandardLogger())
|
L = logrus.NewEntry(logrus.StandardLogger())
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type loggerKey struct{}
|
||||||
loggerKey struct{}
|
|
||||||
|
|
||||||
// Fields type to pass to `WithFields`, alias from `logrus`.
|
// Fields type to pass to "WithFields".
|
||||||
Fields = logrus.Fields
|
type Fields = logrus.Fields
|
||||||
|
|
||||||
// Level is a logging level
|
// RFC3339NanoFixed is [time.RFC3339Nano] with nanoseconds padded using
|
||||||
Level = logrus.Level
|
// zeros to ensure the formatted time is always the same number of
|
||||||
)
|
// characters.
|
||||||
|
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
|
||||||
|
|
||||||
|
// Level is a logging level.
|
||||||
|
type Level = logrus.Level
|
||||||
|
|
||||||
|
// Supported log levels.
|
||||||
const (
|
const (
|
||||||
// RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to
|
// TraceLevel level. Designates finer-grained informational events
|
||||||
// ensure the formatted time is always the same number of characters.
|
// than [DebugLevel].
|
||||||
RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
|
TraceLevel Level = logrus.TraceLevel
|
||||||
|
|
||||||
// TextFormat represents the text logging format
|
// DebugLevel level. Usually only enabled when debugging. Very verbose
|
||||||
TextFormat = "text"
|
// logging.
|
||||||
|
DebugLevel Level = logrus.DebugLevel
|
||||||
|
|
||||||
// JSONFormat represents the JSON logging format
|
// InfoLevel level. General operational entries about what's going on
|
||||||
JSONFormat = "json"
|
// inside the application.
|
||||||
|
InfoLevel Level = logrus.InfoLevel
|
||||||
// TraceLevel level.
|
|
||||||
TraceLevel = logrus.TraceLevel
|
|
||||||
|
|
||||||
// DebugLevel level.
|
|
||||||
DebugLevel = logrus.DebugLevel
|
|
||||||
|
|
||||||
// InfoLevel level.
|
|
||||||
InfoLevel = logrus.InfoLevel
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetLevel sets log level globally.
|
// SetLevel sets log level globally. It returns an error if the given
|
||||||
|
// level is not supported.
|
||||||
|
//
|
||||||
|
// level can be one of:
|
||||||
|
//
|
||||||
|
// - "trace" ([TraceLevel])
|
||||||
|
// - "debug" ([DebugLevel])
|
||||||
|
// - "info" ([InfoLevel])
|
||||||
func SetLevel(level string) error {
|
func SetLevel(level string) error {
|
||||||
lvl, err := logrus.ParseLevel(level)
|
lvl, err := logrus.ParseLevel(level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,7 +85,16 @@ func GetLevel() Level {
|
|||||||
return logrus.GetLevel()
|
return logrus.GetLevel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFormat sets log output format
|
// Supported log output formats.
|
||||||
|
const (
|
||||||
|
// TextFormat represents the text logging format.
|
||||||
|
TextFormat = "text"
|
||||||
|
|
||||||
|
// JSONFormat represents the JSON logging format.
|
||||||
|
JSONFormat = "json"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetFormat sets the log output format ([TextFormat] or [JSONFormat]).
|
||||||
func SetFormat(format string) error {
|
func SetFormat(format string) error {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormat:
|
case TextFormat:
|
||||||
|
Loading…
Reference in New Issue
Block a user