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()'
fn new() Loggerfn new_entry(mut logger Logger) Entryinterface 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`.
fn (entry Entry) bytes() ?[]byteReturns the bytes representation of this entry from the formatter
fn (entry Entry) str() stringReturns the string representation from the reader and ultimately the formatter.
fn (entry Entry) with_field(key string, value json.Any) EntryAdd a single field (json.Any) to the Entry
fn (entry Entry) with_fields(fields ...Field) EntryAdd a array of fields to the Entry
fn (entry Entry) with_fields_map(fields map[string]json.Any) EntryAdd a map of fields (json.Any) to the Entry
fn (entry Entry) with_time(t time.Time) EntryOverrides the time of the Entry
fn (mut entry Entry) log(level Level, args ...string)fn (mut entry Entry) debug(args ...string)fn (mut entry Entry) print(args ...string)fn (mut entry Entry) info(args ...string)fn (mut entry Entry) warn(args ...string)fn (mut entry Entry) warning(args ...string)fn (mut entry Entry) error(args ...string)fn (mut entry Entry) fatal(args ...string)fn (mut entry Entry) panic(args ...string)fn (mut entry Entry) logln(level Level, args ...string)fn (mut entry Entry) debugln(args ...string)fn (mut entry Entry) println(args ...string)fn (mut entry Entry) infoln(args ...string)fn (mut entry Entry) warnln(args ...string)fn (mut entry Entry) warningln(args ...string)fn (mut entry Entry) errorln(args ...string)fn (mut entry Entry) fatalln(args ...string)fn (mut entry Entry) panicln(args ...string)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.
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.
fn (mut l Logger) with_field(key string, value json.Any) EntryCreate Entry with field
fn (mut l Logger) with_fields(fields ...Field) EntryCreate Entry with fields
fn (mut l Logger) with_fields_map(fields map[string]json.Any) EntryCreate Entry with data map
fn (mut l Logger) with_time(t time.Time) EntryCreate Entry with time
fn (mut l Logger) log(level Level, args ...string)fn (mut l Logger) debug(args ...string)fn (mut l Logger) info(args ...string)fn (mut l Logger) print(args ...string)fn (mut l Logger) warn(args ...string)fn (mut l Logger) warning(args ...string)fn (mut l Logger) error(args ...string)fn (mut l Logger) fatal(args ...string)fn (mut l Logger) panic(args ...string)fn (mut l Logger) logln(level Level, args ...string)fn (mut l Logger) debugln(args ...string)fn (mut l Logger) infoln(args ...string)fn (mut l Logger) println(args ...string)fn (mut l Logger) warnln(args ...string)fn (mut l Logger) warningln(args ...string)fn (mut l Logger) errorln(args ...string)fn (mut l Logger) fatalln(args ...string)fn (mut l Logger) panicln(args ...string)fn (mut l Logger) set_level(level Level)Sets the logger level
fn (l Logger) get_level() LevelReturns the logger level
fn (l Logger) is_level_enabled(level Level) boolChecks if the log level of the logger is greater than the level param
fn (mut l Logger) set_formatter(formatter Formatter)Sets the logger formatter
fn (mut l Logger) set_output(output io.Writer)Sets the logger output
fn (mut l Logger) set_exit_func(func ExitFunc)Sets the logger exit function
fn (mut l Logger) add_hook(hook Hook)Adds a hook to the logger hooks
fn (mut l Logger) replace_hooks(hooks LevelHooks) LevelHooksReplaces the logger hooks and returns the old ones
enum Level {
panic = 0
fatal
error
warn
info
debug
}Logging levels
struct Field {
key string
val json.Any
}Field type, used in with_fields
struct JSONFormatter {
pub:
disable_timestamp bool
data_key string
field_map FieldMap
}JSONFormatter formats logs into parsable json
fn (f JSONFormatter) format(entry Entry) ?[]byteRenders a single log entry
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
}fn (mut f TextFormatter) format(entry Entry) ?[]byte