Documentation ¶
Index ¶
- Variables
- func IsDebug() bool
- func MustToConsoleAndFile(filepath string, flag int) io.Writer
- func MustToFile(filename string, flag int) io.Writer
- func ToConsole() io.Writer
- func ToConsoleAndFile(filepath string, flag int) (io.Writer, error)
- func ToFile(filename string, flag int) (io.Writer, error)
- type Arg
- type Level
- type Logger
- func (log *Logger) Debug(msg string, args ...Arg)
- func (log *Logger) Error(err any, args ...Arg)
- func (log *Logger) Fatal(err any, args ...Arg)
- func (log *Logger) Info(msg string, args ...Arg)
- func (log Logger) Out() io.Writer
- func (log *Logger) SetLevel(level Level)
- func (log *Logger) Warning(msg string, args ...Arg)
Constants ¶
This section is empty.
Variables ¶
var ( // Default time format with nanosecond precision TimeFormat = "2006-01-02 15:04:05.999999999" // Console default time format with millisecond accuracy ConsoleTimeFormat = "15:04:05.000" )
Functions ¶
func IsDebug ¶
func IsDebug() bool
IsDebug determines whether the current environment is `DEBUG` through the `DEBUG` variable in the current environment variables.
func MustToConsoleAndFile ¶
MustToConsoleAndFile returns an `io.Writer` that can both output the log to a control or terminal emulator and save the log to a local file, which will panic if there is an error opening the file.
The `flag` parameter is passed to the `os.OpenFile` function. If flag < 0, it will be assigned the value `os.O_RDWR|os.O_CREATE|os.O_TRUNC`.
func MustToFile ¶
MustToFile returns an `io.Writer` that saves the log to a local file and will panic if there is an error opening the file.
The `flag` parameter is passed to the `os.OpenFile` function. If flag < 0, it will be assigned the value `os.O_RDWR|os.O_CREATE|os.O_TRUNC`.
func ToConsole ¶
ToConsole returns an `io.Writer` that outputs the log to the console or terminal emulator or an `error`.
func ToConsoleAndFile ¶
ToConsoleAndFile returns an `io.Writer` that can both output the log to a control or terminal emulator and save the log to a local file, or an `error`.
The `flag` parameter is passed to the `os.OpenFile` function. If flag < 0, it will be assigned the value `os.O_RDWR|os.O_CREATE|os.O_TRUNC`.
Types ¶
type Arg ¶
Arg records the parameters required in the log as key-value pairs, the key is of type `string`, and the value can be of any type.
type Level ¶
type Level int8
Level defines the log level
func EnvLogLevel ¶
func EnvLogLevel() Level
EnvLogLevel returns the logging level set in the LOG_LEVEL environment variable. If LOG_LEVEL is not set, it defaults to log.WARNING.
The mapping of LOG_LEVEL strings to log levels is:
-1, trace -> log.TRACE 0, debug -> log.DEBUG 1, info -> log.INFO 2, warning, warn -> log.WARNING 3, error -> log.ERROR 4, fatal -> log.FATAL
LOG_LEVEL is case insensitive - "TRACE", "trace", and "Trace" all map to log.TRACE.
Other values default to log.WARNING.
type Logger ¶
Logger records a `zerolog.Logger` pointer and uses this pointer to implement all logging methods
func (*Logger) Fatal ¶
Fatal logs a `FATAL` message with some `Arg`s, and calls `os.Exit(1)` to exit the application.