I wanted to implement pluggable logging abstraction to my project, where we refer to github.com/micro/go-micro/util/log for logging but add this file to plugin.go to gain enhanced logging experience compared to default go-micro logging implementation.
This will also allows me in the future, change underneath logger implementation, without changing logging code everyware.
currently go-micro/util/log only expose Log Logf Fatal Fatalf and SetLogger methods. would be nice if we can expand to add SetFormatter, Debug , Info, Warn etc.
if you prefer to keep it as-is, please consider at least exposing underneath logger i.e., GetLogger() so that we can use native logger capabilities when needed.
@asim i think that @xmlking says reasonable thing
We're working on a debug/log interface. It's unclear how it looks but it's more likely an abstraction over reading and writing logs and then some simple higher level functions for logging with Debug, Error, etc. Looking at your interface. It's far too verbose for something like micro. It's likely you'd still define your own interface but it might layer on something differently.
would be nice if new Micro logging framework allow us to using any logrus, uber-go/zap backends via adopters.
would be nice to have method like WithFields(fields map[string]interface{}) *Logger so that we can inject loggers with pre-populated context for each handler as needed. if we just need to log without context, we can use package level global logger.
Why not just use logrus and be done with it?
Make sense as it is API comparable with standard library.
Only benefit i can think having wrapper is, ability to switch logger implication if I find better performing logger in the future
This is simply using glog to embed go-micro, like this:
import "github.com/micro/go-micro/util/log"
// Start 开始时,接管 go-micro 日志
func Start() (err error) {
log.SetLogger(&logging)
return
}
// Close 关闿—¶ï¼Œåˆ·æ—¥å¿—文件
func Close() (err error) {
Flush()
return
}
func (l *loggingT) Log(v ...interface{}) {
logging.println(infoLog, v...)
}
func (l *loggingT) Logf(format string, v ...interface{}) {
logging.printf(infoLog, format, v...)
}
func main() {
service = micro.NewService(
micro.Name("xxx"),
micro.BeforeStart(glog.Start),
micro.AfterStop(glog.Close),
)
service.Init()
if err := service.Run(); err != nil {
glog.Fatal(err)
}
}
I've implemented some additional Trace/Debug/Info methods into the util/log package but we'll likely move to creating a debug/log package for logging that will enable both reading and writing logs. Closing this for now. If you feel strongly about this feature you can create an issue in the development repo.
Most helpful comment
would be nice if new Micro logging framework allow us to using any
logrus,uber-go/zapbackends via adopters.would be nice to have method like
WithFields(fields map[string]interface{}) *Loggerso that we can inject loggers with pre-populatedcontextfor each handler as needed. if we just need to log without context, we can use package level global logger.