You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/log/logger.go

89 lines
1.7 KiB
Go

package log
import (
"log"
"os"
)
type Logger interface {
Debugf(format string, v ...interface{})
Debug(v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
}
func init() {
SetLogger(newInnerLogger())
}
var (
Debugf func(format string, v ...interface{})
Debug func(v ...interface{})
Info func(v ...interface{})
Infof func(format string, v ...interface{})
Error func(v ...interface{})
Errorf func(format string, v ...interface{})
Fatal func(v ...interface{})
Fatalf func(format string, v ...interface{})
)
func SetLogger(logger Logger) {
if logger == nil {
return
}
Debugf = logger.Debugf
Debug = logger.Debug
Info = logger.Info
Infof = logger.Infof
Error = logger.Error
Errorf = logger.Errorf
Fatal = logger.Fatal
Fatalf = logger.Fatalf
}
type innerLogger struct {
log *log.Logger
}
func newInnerLogger() Logger {
return &innerLogger{
log: log.New(os.Stderr, "[N-Net] ", log.LstdFlags|log.Lshortfile),
}
}
func (i *innerLogger) Debugf(format string, v ...interface{}) {
i.log.Printf(format+"\n", v)
}
func (i *innerLogger) Debug(v ...interface{}) {
i.log.Println(v)
}
func (i *innerLogger) Info(v ...interface{}) {
i.log.Println(v)
}
func (i *innerLogger) Infof(format string, v ...interface{}) {
i.log.Printf(format+"\n", v)
}
func (i *innerLogger) Error(v ...interface{}) {
i.log.Println(v)
}
func (i *innerLogger) Errorf(format string, v ...interface{}) {
i.log.Printf(format+"\n", v)
}
func (i *innerLogger) Fatal(v ...interface{}) {
i.log.Fatal(v)
}
func (i *innerLogger) Fatalf(format string, v ...interface{}) {
i.log.Fatalf(format+"\n", v)
}