Package log implements multilevel logging.
- Custom prefix
- Multiple levels
- Highlight color
- File line
- Call stack
- All
- Trace
- Debug
- Info
- Notice
- Warn
- Error
- Panic
- Fatal
- Off
go get github.com/hslam/log
import "github.com/hslam/log"
package main
import (
"github.com/hslam/log"
)
func main() {
logger := log.New()
logger.SetPrefix("LogPrefix")
logger.SetLevel(log.AllLevel)
logger.SetHighlight(true)
logger.SetLine(true)
logger.Assertf(1 == 1, "%d %s %t", 1024, "HelloWorld", true)
logger.Allf("%d %s %t", 1024, "HelloWorld", true)
logger.Tracef("%d %s %t", 1024, "HelloWorld", true)
logger.Debugf("%d %s %t", 1024, "HelloWorld", true)
logger.Infof("%d %s %t", 1024, "HelloWorld", true)
logger.Noticef("%d %s %t", 1024, "HelloWorld", true)
logger.Warnf("%d %s %t", 1024, "HelloWorld", true)
logger.Errorf("%d %s %t", 1024, "HelloWorld", true)
defer func() {
recover()
logger.Fatalf("%d %s %t", 1024, "HelloWorld", true)
}()
logger.Panicf("%d %s %t", 1024, "HelloWorld", true)
}
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [ALL] [main.go:16] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [TRACE] [main.go:17] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [DEBUG] [main.go:18] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [INFO] [main.go:19] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [NOTICE] [main.go:20] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [WARN] [main.go:21] ["1024 HelloWorld true"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [ERROR] [main.go:22] ["1024 HelloWorld true"] [stack="main.main\n\t/Users/huangmeng/go/src/github.com/hslam/tmp/log/main.go:22\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [PANIC] [main.go:27] ["1024 HelloWorld true"] [stack="main.main\n\t/Users/huangmeng/go/src/github.com/hslam/tmp/log/main.go:27\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250"]
[LogPrefix] [2023/05/13 18:21:51.183 +08:00] [FATAL] [main.go:25] ["1024 HelloWorld true"] [stack="main.main.func1\n\t/Users/huangmeng/go/src/github.com/hslam/tmp/log/main.go:25\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nmain.main\n\t/Users/huangmeng/go/src/github.com/hslam/tmp/log/main.go:27\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250"]
This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)
log was written by Meng Huang.