You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB
Go

7 years ago
/*
6 years ago
Package log is a simple and configurable Logging in Go, with level, log and log.
7 years ago
It is completely API compatible with the standard library logger.
The simplest way to use log is simply the package-level exported logger:
package main
import (
"os"
5 years ago
log "github.com/fangdingjun/go-log/v5"
7 years ago
)
func main() {
log.Print("some message")
log.Infof("$HOME = %v", os.Getenv("HOME"))
log.Errorln("Got err:", os.ErrPermission)
}
Output:
07:34:23.039 INFO some message
07:34:23.039 INFO $HOME = /home/fangdingjun
7 years ago
07:34:23.039 ERROR Got err: permission denied
You also can config `log.Default` or new `log.Logger` to customize formatter and writer.
package main
import (
"os"
5 years ago
log "github.com/fangdingjun/go-log/v5"
7 years ago
)
func main() {
logger := &log.Logger{
Level: log.INFO,
6 years ago
Formatter: new(log.TextFormatter),
Out: &log.FixedSizeFileWriter{
7 years ago
Name: "/tmp/test.log",
MaxSize: 10 * 1024 * 1024, // 10m
MaxCount: 10,
},
}
logger.Info("some message")
}
Output log in `/tmp/test.log`:
2018-05-19T07:49:05.979+0000 INFO devbox main 9981 example/main.go:17 some message
For a full guide visit https://github.com/fangdingjun/go-log
7 years ago
*/
package log