mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-19 01:24:26 +00:00
* 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
38 lines
778 B
Go
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()
|
|
}
|