started new logger output
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sebastian Frank
2019-03-27 13:52:22 +01:00
parent 5d6d03702e
commit 7695f42e20
4 changed files with 58 additions and 28 deletions

View File

@@ -11,6 +11,8 @@ import (
var Log = logging.MustGetLogger("myLogger")
var logBackendLeveled logging.LeveledBackend
var Prefix = ""
// SetLogLevel sets log level for global logger (debug, info, notice, warning, error)
func SetLogLevel(level string) {
logBackendLevel := logging.INFO
@@ -44,7 +46,7 @@ func SetLogLevel(level string) {
func configureLogger() {
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
`%{color}%{time:2006-01-02 15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
))
logBackendLeveled = logging.AddModuleLevel(logBackendFormatter)
logBackendLeveled.SetLevel(logging.NOTICE, "")
@@ -59,34 +61,38 @@ func init() {
configureLogger()
}
func prefix() string {
return Prefix
}
// D is shorthand for Debugf
func D(format string, args ...interface{}) {
Log.Debugf(format, args...)
Log.Debugf(prefix()+format, args...)
}
// I is shorthand for Infof
func I(format string, args ...interface{}) {
Log.Infof(format, args...)
Log.Infof(prefix()+format, args...)
}
// N is shorthand for Noticef
func N(format string, args ...interface{}) {
Log.Noticef(format, args...)
Log.Noticef(prefix()+format, args...)
}
// W is shorthand for Warningf
func W(format string, args ...interface{}) {
Log.Warningf(format, args...)
Log.Warningf(prefix()+format, args...)
}
// E is shorthand for Errorf
func E(format string, args ...interface{}) {
Log.Errorf(format, args...)
Log.Errorf(prefix()+format, args...)
}
// P is shorthand for Panicf
func P(format string, args ...interface{}) {
Log.Panicf(format, args...)
Log.Panicf(prefix()+format, args...)
}
// Eerr is shorthand for
@@ -96,7 +102,7 @@ func P(format string, args ...interface{}) {
func Eerr(err error, format string, args ...interface{}) {
if err != nil {
args = append(args, err)
Log.Errorf(format+"\nError: %s", args...)
Log.Errorf(prefix()+format+" (Error: %s)", args...)
}
}
@@ -119,6 +125,6 @@ func Eexit(err error, format string, args ...interface{}) {
func Perr(err error, format string, args ...interface{}) {
if err != nil {
args = append(args, err)
Log.Panicf(format+"\nError: %s", args...)
Log.Panicf(prefix()+format+" (Error: %s)", args...)
}
}