Add log => go-log

This commit is contained in:
Asim Aslam 2019-05-31 00:35:04 +01:00
parent c90d0eff0a
commit 5595a8e0e4
2 changed files with 58 additions and 0 deletions

17
util/log/README.md Normal file
View 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
View 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
}