- move LogLevel and predefined levels into levels.go - add level-specific constructors for info/warn/error/fatal/debug - add predefined HTTP method log levels and LogLevelForMethod - unify Logger Print/Println internals and add Printf - improve GoDoc coverage for exported APIs
This commit is contained in:
+23
-8
@@ -6,16 +6,28 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Formatter
|
||||
// Format: %t - time, %N - name, %l - level, %L - level uppercase, %b - traceback, %B - full traceback, %m - message,
|
||||
// %M - method, %f - filename, %n - line number, %s - method signature, %p - full path
|
||||
// Example: "%t [%l] %N: %m (%f:%n %s)"
|
||||
// Formatter configures how log records are rendered.
|
||||
//
|
||||
// TimeStampFormat: %Y - year, %m - month, %d - day, %H - hour, %M - minute, %S - second,
|
||||
// %z - timezone(i.e. 0300), %Z - timezone(i.e. 03:00)
|
||||
// Example: "%d.%m.%Y %H:%M:%S"
|
||||
// Format tokens:
|
||||
// - %t: time
|
||||
// - %N: name
|
||||
// - %l: level
|
||||
// - %L: uppercase level
|
||||
// - %b: first traceback frame
|
||||
// - %B: full traceback
|
||||
// - %m: message
|
||||
// - %M: method
|
||||
// - %f: filename
|
||||
// - %n: line number
|
||||
// - %s: method signature
|
||||
// - %p: full path
|
||||
//
|
||||
// TraceBackFormat: %M - method, %f - filename, %n - line number, %s - method signature, %p - full path
|
||||
// Example format: "%t [%l] %N: %m (%f:%n %s)"
|
||||
//
|
||||
// TimeStampFormat uses strftime-like directives such as %Y, %m, %d, %H, %M,
|
||||
// %S, %z, and %Z.
|
||||
//
|
||||
// TraceBackFormat supports the traceback-related tokens %M, %f, %n, %s, and %p.
|
||||
type Formatter struct {
|
||||
Format string
|
||||
MessageSeparator string
|
||||
@@ -31,6 +43,7 @@ type Formatter struct {
|
||||
ColorOnlyStdout bool
|
||||
}
|
||||
|
||||
// DefaultTextFormatter is the default formatter used by text writers.
|
||||
var DefaultTextFormatter = &Formatter{
|
||||
Format: "%t %l %N: %m",
|
||||
MessageSeparator: " ",
|
||||
@@ -40,6 +53,8 @@ var DefaultTextFormatter = &Formatter{
|
||||
ColorOutput: true,
|
||||
ColorOnlyStdout: true,
|
||||
}
|
||||
|
||||
// DefaultJsonFormatter is the default formatter used by JSON writers.
|
||||
var DefaultJsonFormatter = &Formatter{
|
||||
Format: "%m",
|
||||
MessageSeparator: " ",
|
||||
|
||||
Reference in New Issue
Block a user