https://github.com/hslam/log
Package log implements multilevel logging.
https://github.com/hslam/log
go golang logger multilevel
Last synced: about 1 month ago
JSON representation
Package log implements multilevel logging.
- Host: GitHub
- URL: https://github.com/hslam/log
- Owner: hslam
- License: mit
- Created: 2020-01-15T22:41:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-17T13:55:34.000Z (about 3 years ago)
- Last Synced: 2023-07-27T18:04:44.531Z (almost 3 years ago)
- Topics: go, golang, logger, multilevel
- Language: Go
- Homepage:
- Size: 523 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# log
[](https://godoc.org/github.com/hslam/log)
[](https://github.com/hslam/log/actions)
[](https://codecov.io/gh/hslam/log)
[](https://goreportcard.com/report/github.com/hslam/log)
[](https://github.com/hslam/log/releases/latest)
[](https://github.com/hslam/log/blob/master/LICENSE)
Package log implements multilevel logging.
## Feature
* Custom prefix
* Multiple levels
* Highlight color
* File line
* Call stack
## Level
* All
* Trace
* Debug
* Info
* Notice
* Warn
* Error
* Panic
* Fatal
* Off
## Get started
### Install
```
go get github.com/hslam/log
```
### Import
```
import "github.com/hslam/log"
```
### Usage
#### Example
```go
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)
}
```
### Output
```
[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"]
```
#### Highlight

### License
This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)
### Author
log was written by Meng Huang.