69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"os"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||
|
)
|
||
|
|
||
|
func NewLog() *log.Logger {
|
||
|
// f, err := os.OpenFile("flexradio.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||
|
// if err != nil {
|
||
|
// panic(err)
|
||
|
// }
|
||
|
|
||
|
// w := io.MultiWriter(os.Stdout, f)
|
||
|
w := io.Writer(os.Stdout)
|
||
|
|
||
|
l := &log.Logger{
|
||
|
Out: w,
|
||
|
Level: log.DebugLevel,
|
||
|
Formatter: &prefixed.TextFormatter{
|
||
|
DisableColors: false,
|
||
|
TimestampFormat: "02-01-2006 15:04:05",
|
||
|
FullTimestamp: true,
|
||
|
ForceFormatting: true,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
l.Level = log.DebugLevel
|
||
|
|
||
|
return l
|
||
|
}
|
||
|
|
||
|
// Info ...
|
||
|
func Info(format string, v ...interface{}) {
|
||
|
log.Infof(format, v...)
|
||
|
}
|
||
|
|
||
|
// Warn ...
|
||
|
func Warn(format string, v ...interface{}) {
|
||
|
log.Warnf(format, v...)
|
||
|
}
|
||
|
|
||
|
// Error ...
|
||
|
func Error(format string, v ...interface{}) {
|
||
|
log.Errorf(format, v...)
|
||
|
}
|
||
|
|
||
|
func Debug(format string, v ...interface{}) {
|
||
|
log.Debugf(format, v...)
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
|
||
|
// ConfigError ...
|
||
|
ConfigError = "%v type=config.error"
|
||
|
|
||
|
// HTTPError ...
|
||
|
HTTPError = "%v type=http.error"
|
||
|
|
||
|
// HTTPWarn ...
|
||
|
HTTPWarn = "%v type=http.warn"
|
||
|
|
||
|
// HTTPInfo ...
|
||
|
HTTPInfo = "%v type=http.info"
|
||
|
)
|