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.
89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
2 years ago
|
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{})
|
||
|
Panic(v ...interface{})
|
||
|
Panicf(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{})
|
||
|
Panic func(v ...interface{})
|
||
|
Panicf 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
|
||
|
Panic = logger.Panic
|
||
|
Panicf = logger.Panicf
|
||
|
}
|
||
|
|
||
|
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, 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, v)
|
||
|
}
|
||
|
|
||
|
func (i *innerLogger) Error(v ...interface{}) {
|
||
|
i.log.Println(v)
|
||
|
}
|
||
|
|
||
|
func (i *innerLogger) Errorf(format string, v ...interface{}) {
|
||
|
i.log.Printf(format, v)
|
||
|
}
|
||
|
|
||
|
func (i *innerLogger) Panic(v ...interface{}) {
|
||
|
i.log.Panic(v)
|
||
|
}
|
||
|
|
||
|
func (i *innerLogger) Panicf(format string, v ...interface{}) {
|
||
|
i.log.Panicf(format, v)
|
||
|
}
|