cloud-game/pkg/util/logging/init.go
Sadlil Rhythom 0e17092acb Refactor of cloud game overlord and overworker (#70)
* Introduce Makefile and go vendor directory for faster build

* WIP: Refactor cloud-game codebase with spliting overlord and worker binary

* Fix all issues and have a running build

* Complete first version of refactor
2019-09-12 03:35:21 +08:00

38 lines
778 B
Go

package logging
import (
"flag"
"log"
"github.com/golang/glog"
"github.com/spf13/pflag"
)
func init() {
_ = flag.Set("logtostderr", "true")
}
// LogWriter serves as a bridge between the standard log package and the glog package.
type LogWriter struct{}
// Write implements the io.Writer interface.
func (writer LogWriter) Write(data []byte) (n int, err error) {
glog.InfoDepth(3, string(data))
return len(data), nil
}
// Init initializes logs the way we want.
func Init() {
log.SetOutput(LogWriter{})
log.SetFlags(0)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
// Convinces goflags that we have called Parse() to avoid noisy logs.
_ = flag.CommandLine.Parse([]string{})
}
// Flush flushes logs immediately.
func Flush() {
glog.Flush()
}