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.8 KiB
Go
89 lines
1.8 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{})
|
||
2 years ago
|
Fatal(v ...interface{})
|
||
|
Fatalf(format string, v ...interface{})
|
||
2 years ago
|
}
|
||
|
|
||
|
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{})
|
||
2 years ago
|
Fatal func(v ...interface{})
|
||
|
Fatalf func(format string, v ...interface{})
|
||
2 years ago
|
)
|
||
|
|
||
|
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
|
||
2 years ago
|
Fatal = logger.Fatal
|
||
|
Fatalf = logger.Fatalf
|
||
2 years ago
|
}
|
||
|
|
||
|
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{}) {
|
||
2 years ago
|
i.log.Printf(format+"\n", v...)
|
||
2 years ago
|
}
|
||
|
|
||
|
func (i *innerLogger) Debug(v ...interface{}) {
|
||
2 years ago
|
i.log.Println(v...)
|
||
2 years ago
|
}
|
||
|
|
||
|
func (i *innerLogger) Info(v ...interface{}) {
|
||
2 years ago
|
i.log.Println(v...)
|
||
2 years ago
|
}
|
||
|
|
||
|
func (i *innerLogger) Infof(format string, v ...interface{}) {
|
||
2 years ago
|
i.log.Printf(format+"\n", v...)
|
||
2 years ago
|
}
|
||
|
|
||
|
func (i *innerLogger) Error(v ...interface{}) {
|
||
2 years ago
|
i.log.Println(v...)
|
||
2 years ago
|
}
|
||
|
|
||
|
func (i *innerLogger) Errorf(format string, v ...interface{}) {
|
||
2 years ago
|
i.log.Printf(format+"\n", v...)
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
func (i *innerLogger) Fatal(v ...interface{}) {
|
||
2 years ago
|
i.log.Fatal(v...)
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
func (i *innerLogger) Fatalf(format string, v ...interface{}) {
|
||
2 years ago
|
i.log.Fatalf(format+"\n", v...)
|
||
2 years ago
|
}
|