Documentation ¶
Overview ¶
Package log provides a global logger for log.
Example (Stdlog) ¶
package main import ( "os" "github.com/sraphs/go/log" "github.com/sraphs/go/log/stdlog" ) func main() { log.Init( stdlog.New(os.Stdout, "", stdlog.LDefaultFlags).SetCallerDepth(log.CallerSkipFrameCount), ) log.Debug("hello world") // Outputs: // DEBUG: 2022/05/19 10:36:33.528825 example_test.go:31: hello world }
Output:
Example (Zerolog) ¶
package main import ( "os" "github.com/sraphs/go/log" "github.com/sraphs/go/log/zerolog" ) func main() { log.Init( zerolog.New(os.Stdout, zerolog.WithTimestamp(), zerolog.WithCallerWithSkipFrameCount(log.CallerSkipFrameCount), zerolog.WithStack(), ), ) log.Debug("hello world") // Outputs: // {"level":"debug","msg":"hello world","ts":"2022-05-19T10:36:18+08:00","caller":"example_test.go:20"} }
Output:
Index ¶
- Constants
- func Debug(v ...interface{})
- func Error(v ...interface{})
- func Fatal(v ...interface{})
- func GetLevel() logger.Level
- func GetLogger() logger.Logger
- func Info(v ...interface{})
- func Init(l logger.Logger) logger.Logger
- func IsLevelEnabled(lvl logger.Level) bool
- func Panic(v ...interface{})
- func SetLevel(l logger.Level)
- func SetLogger(l logger.Logger)
- func Warn(v ...interface{})
Examples ¶
Constants ¶
View Source
const CallerSkipFrameCount = 1
when use global Debug/Info ... skip 1 frames to get to the caller
Variables ¶
This section is empty.
Functions ¶
func IsLevelEnabled ¶
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
package logger defines as interface a writer may implement in order
|
package logger defines as interface a writer may implement in order |
package zerolog implements a Logger interface using zerolog.
|
package zerolog implements a Logger interface using zerolog. |
Click to show internal directories.
Click to hide internal directories.