Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jason916/peanut_core
A common logging package for Golang
https://github.com/jason916/peanut_core
go logger logging
Last synced: 9 days ago
JSON representation
A common logging package for Golang
- Host: GitHub
- URL: https://github.com/jason916/peanut_core
- Owner: Jason916
- Created: 2017-11-12T13:25:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-21T05:24:48.000Z (over 5 years ago)
- Last Synced: 2024-06-20T01:52:29.578Z (5 months ago)
- Topics: go, logger, logging
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# peanut_core
A common logging package for Golanglevel
=
* 5 levels: info trace error warning successerror
=
* logging when an error occurs and make it coloredcolor
=
* support 'set default color' function
* make msg coloredwrite file
=
* by time
* by size(default 1024)
* write file at regular intervals
* support rotateconfig
=
* get config from fileCLI Installation
=
$ go get github.com/Jason916/peanut_core/logGetting Started
=
```go
package mainimport (
"github.com/Jason916/peanut_core/log"
"fmt"
)func init() {
// set default color for logging
log.SetDefaultColor(log.DefaultColor)}
func main() {
// make msg colored
log.Trace("this is trace tag")log.Info("this is info tag")
log.Success("this is success tag")
// write log file
plogWriteConfig := log.NewPLogWriterConfig()
plogWriter, err := log.NewPLogWriter(".", "test_log", true, plogWriteConfig)if err != nil{
log.Error("write log failed, cause by: ", err)
return
}plog := log.NewPLogger(plogWriter)
plog.PInfo("test info ")
plog.PError("test write error")
plog.PTrace("test write trace")if err := plog.PClose(); err != nil {
fmt.Println("log close failed, cause by: ", err)
}
}