treplo
April 14, 2021 ยท View on GitHub
Contents
Constants
const (
field_key_msg = 'msg'
field_key_level = 'level'
field_key_time = 'time'
field_key_treplo_error = 'treplo_error'
field_key_func = 'func'
field_key_file = 'file'
)
Default key names for the default fields
const (
all_levels = [Level.panic, .fatal, .error, .warn, .info, .debug]
err_levels = [Level.panic, .fatal, .error]
)
For hooks 'levels()'
new
fn new() Logger
new_entry
fn new_entry(mut logger Logger) Entry
Formatter
interface Formatter {
format(Entry) ?[]byte
}
Formatter interface is used to implement a custom Formatter. The Formatter interface is used to implement a custom Formatter. It takes an Entry. It exposes all the fields, including the default ones: * entry.data["msg"]. The message passed from info, warn, error .. * entry.data["time"]. The timestamp. * entry.data["level"]. The level the entry was logged at. Any additional fields added with with_fieldorwith_fieldsare also in entry.data. Format is expected to return an array of bytes which are then logged to logger.out`.
Entry
bytes
fn (entry Entry) bytes() ?[]byte
Returns the bytes representation of this entry from the formatter
str
fn (entry Entry) str() string
Returns the string representation from the reader and ultimately the formatter.
with_field
fn (entry Entry) with_field(key string, value json.Any) Entry
Add a single field (json.Any) to the Entry
with_fields
fn (entry Entry) with_fields(fields ...Field) Entry
Add a array of fields to the Entry
with_fields_map
fn (entry Entry) with_fields_map(fields map[string]json.Any) Entry
Add a map of fields (json.Any) to the Entry
with_time
fn (entry Entry) with_time(t time.Time) Entry
Overrides the time of the Entry
log
fn (mut entry Entry) log(level Level, args ...string)
debug
fn (mut entry Entry) debug(args ...string)
fn (mut entry Entry) print(args ...string)
info
fn (mut entry Entry) info(args ...string)
warn
fn (mut entry Entry) warn(args ...string)
warning
fn (mut entry Entry) warning(args ...string)
error
fn (mut entry Entry) error(args ...string)
fatal
fn (mut entry Entry) fatal(args ...string)
panic
fn (mut entry Entry) panic(args ...string)
logln
fn (mut entry Entry) logln(level Level, args ...string)
debugln
fn (mut entry Entry) debugln(args ...string)
println
fn (mut entry Entry) println(args ...string)
infoln
fn (mut entry Entry) infoln(args ...string)
warnln
fn (mut entry Entry) warnln(args ...string)
warningln
fn (mut entry Entry) warningln(args ...string)
errorln
fn (mut entry Entry) errorln(args ...string)
fatalln
fn (mut entry Entry) fatalln(args ...string)
panicln
fn (mut entry Entry) panicln(args ...string)
LevelHooks
add
fn (mut hooks LevelHooks) add(hook Hook)
Add a hook to an instance of logger. This is called with log.hooks.Add(new(MyHook)) where MyHook implements the Hook interface.
fire
fn (mut hooks LevelHooks) fire(level Level, entry Entry) ?
Fire all the hooks for the passed level. Used by entry.log to fire appropriate hooks for a log entry.
Logger
with_field
fn (mut l Logger) with_field(key string, value json.Any) Entry
Create Entry with field
with_fields
fn (mut l Logger) with_fields(fields ...Field) Entry
Create Entry with fields
with_fields_map
fn (mut l Logger) with_fields_map(fields map[string]json.Any) Entry
Create Entry with data map
with_time
fn (mut l Logger) with_time(t time.Time) Entry
Create Entry with time
log
fn (mut l Logger) log(level Level, args ...string)
debug
fn (mut l Logger) debug(args ...string)
info
fn (mut l Logger) info(args ...string)
fn (mut l Logger) print(args ...string)
warn
fn (mut l Logger) warn(args ...string)
warning
fn (mut l Logger) warning(args ...string)
error
fn (mut l Logger) error(args ...string)
fatal
fn (mut l Logger) fatal(args ...string)
panic
fn (mut l Logger) panic(args ...string)
logln
fn (mut l Logger) logln(level Level, args ...string)
debugln
fn (mut l Logger) debugln(args ...string)
infoln
fn (mut l Logger) infoln(args ...string)
println
fn (mut l Logger) println(args ...string)
warnln
fn (mut l Logger) warnln(args ...string)
warningln
fn (mut l Logger) warningln(args ...string)
errorln
fn (mut l Logger) errorln(args ...string)
fatalln
fn (mut l Logger) fatalln(args ...string)
panicln
fn (mut l Logger) panicln(args ...string)
set_level
fn (mut l Logger) set_level(level Level)
Sets the logger level
get_level
fn (l Logger) get_level() Level
Returns the logger level
is_level_enabled
fn (l Logger) is_level_enabled(level Level) bool
Checks if the log level of the logger is greater than the level param
set_formatter
fn (mut l Logger) set_formatter(formatter Formatter)
Sets the logger formatter
set_output
fn (mut l Logger) set_output(output io.Writer)
Sets the logger output
set_exit_func
fn (mut l Logger) set_exit_func(func ExitFunc)
Sets the logger exit function
add_hook
fn (mut l Logger) add_hook(hook Hook)
Adds a hook to the logger hooks
replace_hooks
fn (mut l Logger) replace_hooks(hooks LevelHooks) LevelHooks
Replaces the logger hooks and returns the old ones
Level
enum Level {
panic = 0
fatal
error
warn
info
debug
}
Logging levels
Field
struct Field {
key string
val json.Any
}
Field type, used in with_fields
JSONFormatter
struct JSONFormatter {
pub:
disable_timestamp bool
data_key string
field_map FieldMap
}
JSONFormatter formats logs into parsable json
format
fn (f JSONFormatter) format(entry Entry) ?[]byte
Renders a single log entry
TextFormatter
struct TextFormatter {
pub:
disable_colors bool
force_quote bool
disable_quote bool
environment_override_colors bool
disable_timestamp bool
full_timestamp bool
disable_sorting bool
sorting_func SortingFunc = default_sort
disable_level_truncation bool = true
pad_level_text bool
quote_empty_fields bool
field_map FieldMap
level_text_max_length int = 4
}
format
fn (mut f TextFormatter) format(entry Entry) ?[]byte