log

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 added in v0.2.4

func IsDebug() bool

IsDebug determines whether the current environment is `DEBUG` through the `DEBUG` variable in the current environment variables.

func MustToConsoleAndFile added in v0.2.4

func MustToConsoleAndFile(filepath string, flag int) io.Writer

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 added in v0.2.4

func MustToFile(filename string, flag int) io.Writer

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 added in v0.2.4

func ToConsole() io.Writer

ToConsole returns an `io.Writer` that outputs the log to the console or terminal emulator or an `error`.

func ToConsoleAndFile added in v0.2.4

func ToConsoleAndFile(filepath string, flag int) (io.Writer, error)

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`.

func ToFile added in v0.2.4

func ToFile(filename string, flag int) (io.Writer, error)

ToFile returns an `io.Writer` that saves 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 added in v0.2.4

type Arg struct {
	Key   string
	Value interface{}
}

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 added in v0.2.4

type Level uint8

Level defines the log level

const (
	DEBUG Level = iota
	INFO
	WARNING
	ERROR
	FATAL
)

log level

type Logger added in v0.2.4

type Logger struct {
	L *zerolog.Logger
	// contains filtered or unexported fields
}

Logger records a `zerolog.Logger` pointer and uses this pointer to implement all logging methods

func NewLogger

func NewLogger(level Level, out io.Writer, skip ...int) *Logger

NewLogger returns a new `Logger` pointer.

func (*Logger) Debug added in v0.2.4

func (log *Logger) Debug(msg string, args ...Arg)

Debug logs a `DEBUG` message with some `Arg`s.

func (*Logger) Error added in v0.2.4

func (log *Logger) Error(err error, args ...Arg)

Error logs a `ERROR` message with some `Arg`s.

func (*Logger) Fatal added in v0.2.4

func (log *Logger) Fatal(err error, args ...Arg)

Fatal logs a `FATAL` message with some `Arg`s, and calls `os.Exit(1)` to exit the application.

func (*Logger) Info added in v0.2.4

func (log *Logger) Info(msg string, args ...Arg)

Info logs a `INFO` message with some `Arg`s.

func (*Logger) SetLevel added in v0.2.4

func (log *Logger) SetLevel(level Level)

SetLevel will create a `zerolog.Logger` instance with a new `LEVEL` using the existing `out`(io.Writer)

func (*Logger) Warning added in v0.2.4

func (log *Logger) Warning(msg string, args ...Arg)

Warning logs a `WARNING` message with some `Arg`s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL