Add log => go-log
This commit is contained in:
parent
c90d0eff0a
commit
5595a8e0e4
17
util/log/README.md
Normal file
17
util/log/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Log
|
||||
|
||||
This is the global logger for all micro based libraries which makes use of [github.com/go-log/log](https://github.com/go-log/log).
|
||||
|
||||
It defaults the logger to the stdlib log implementation.
|
||||
|
||||
## Set Logger
|
||||
|
||||
Set the logger for micro libraries
|
||||
|
||||
```go
|
||||
// import micro/go-log
|
||||
import "github.com/micro/go-micro/util/log"
|
||||
|
||||
// SetLogger expects github.com/go-log/log.Logger interface
|
||||
log.SetLogger(mylogger)
|
||||
```
|
41
util/log/log.go
Normal file
41
util/log/log.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package log is a global internal logger
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/go-log/log"
|
||||
golog "github.com/go-log/log/log"
|
||||
)
|
||||
|
||||
var (
|
||||
// the local logger
|
||||
logger log.Logger = golog.New()
|
||||
)
|
||||
|
||||
// Log makes use of github.com/go-log/log.Log
|
||||
func Log(v ...interface{}) {
|
||||
logger.Log(v...)
|
||||
}
|
||||
|
||||
// Logf makes use of github.com/go-log/log.Logf
|
||||
func Logf(format string, v ...interface{}) {
|
||||
logger.Logf(format, v...)
|
||||
}
|
||||
|
||||
// Fatal logs with Log and then exits with os.Exit(1)
|
||||
func Fatal(v ...interface{}) {
|
||||
Log(v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalf logs with Logf and then exits with os.Exit(1)
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
Logf(format, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// SetLogger sets the local logger
|
||||
func SetLogger(l log.Logger) {
|
||||
logger = l
|
||||
}
|
Loading…
Reference in New Issue
Block a user