created new methods as part of the flogger interface. Debug]

master
Charles Iliya Krempeaux 2015-10-13 19:16:33 -07:00
parent 4bb10531bb
commit 239ff85307
9 changed files with 234 additions and 12 deletions

35
debug.go 100644
View File

@ -0,0 +1,35 @@
package flog
import (
"fmt"
)
var (
debugContext = map[string]interface{}{
"~type":"debug",
}
)
func (flogger *internalFlogger) Debug(v ...interface{}) {
msg := fmt.Sprint(v...)
flogger.route(msg, debugContext)
}
func (flogger *internalFlogger) Debugf(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
flogger.route(msg, debugContext)
}
func (flogger *internalFlogger) Debugln(v ...interface{}) {
msg := fmt.Sprintln(v...)
flogger.route(msg, debugContext)
}

48
error.go 100644
View File

@ -0,0 +1,48 @@
package flog
import (
"fmt"
)
var (
errorContext = map[string]interface{}{
"~type":"error",
}
)
func (flogger *internalFlogger) Error(v ...interface{}) {
msg := fmt.Sprint(v...)
flogger.route(msg, errorContext)
}
func (flogger *internalFlogger) Errorf(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
flogger.route(msg, errorContext)
}
func (flogger *internalFlogger) Errorfe(err error, format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
context := map[string]interface{}{}
for k,v := range errorContext {
context[k] = v
}
context["~error"] = err
flogger.route(msg, context)
}
func (flogger *internalFlogger) Errorln(v ...interface{}) {
msg := fmt.Sprintln(v...)
flogger.route(msg, errorContext)
}

View File

@ -2,24 +2,38 @@ package flog
import ( import (
"fmt"
"os" "os"
) )
var (
fatalContext = map[string]interface{}{
"~type":"fatal",
}
)
func (flogger *internalFlogger) Fatal(v ...interface{}) { func (flogger *internalFlogger) Fatal(v ...interface{}) {
flogger.Print(v...) msg := fmt.Sprint(v...)
flogger.route(msg, fatalContext)
os.Exit(1) os.Exit(1)
} }
func (flogger *internalFlogger) Fatalf(format string, v ...interface{}) { func (flogger *internalFlogger) Fatalf(format string, v ...interface{}) {
flogger.Printf(format, v...) msg := fmt.Sprintf(format, v...)
flogger.route(msg, fatalContext)
os.Exit(1) os.Exit(1)
} }
func (flogger *internalFlogger) Fatalln(v ...interface{}) { func (flogger *internalFlogger) Fatalln(v ...interface{}) {
flogger.Println(v...) msg := fmt.Sprintln(v...)
flogger.route(msg, fatalContext)
os.Exit(1) os.Exit(1)
} }

View File

@ -18,3 +18,12 @@ func New(router Router, cascade ...interface{}) Flogger {
return &flogger return &flogger
} }
func (flogger *internalFlogger) route(message string, moreContext map[string]interface{}) error {
context := newContext(flogger.context, moreContext)
return flogger.router.Route(message, context)
}

View File

@ -2,17 +2,35 @@ package flog
type Flogger interface { type Flogger interface {
Debug(...interface{})
Debugf(string, ...interface{})
Debugln(...interface{})
Error(...interface{})
Errorf(string, ...interface{})
Errorfe(error, string, ...interface{})
Errorln(...interface{})
Fatal(...interface{}) Fatal(...interface{})
Fatalf(string, ...interface{}) Fatalf(string, ...interface{})
Fatalln(...interface{}) Fatalln(...interface{})
Panic(...interface{}) Panic(...interface{})
Panicf(string, ...interface{}) Panicf(string, ...interface{})
Panicfv(interface{}, string, ...interface{})
Panicln(...interface{}) Panicln(...interface{})
Print(...interface{}) Print(...interface{})
Printf(string, ...interface{}) Printf(string, ...interface{})
Println(...interface{}) Println(...interface{})
Trace(...interface{})
Tracef(string, ...interface{})
Traceln(...interface{})
Warn(...interface{})
Warnf(string, ...interface{})
Warnln(...interface{})
With(...interface{}) Flogger With(...interface{}) Flogger
} }

View File

@ -6,20 +6,41 @@ import (
) )
var (
panicContext = map[string]interface{}{
"~type":"panic",
}
)
func (flogger *internalFlogger) Panic(v ...interface{}) { func (flogger *internalFlogger) Panic(v ...interface{}) {
flogger.Print(v...) msg := fmt.Sprint(v...)
panic(fmt.Sprint(v...))
flogger.route(msg, panicContext)
panic(msg)
} }
func (flogger *internalFlogger) Panicf(format string, v ...interface{}) { func (flogger *internalFlogger) Panicf(format string, v ...interface{}) {
flogger.Printf(format, v...) msg := fmt.Sprintf(format, v...)
panic(fmt.Sprintf(format, v...))
flogger.route(msg, panicContext)
panic(msg)
}
func (flogger *internalFlogger) Panicfv(panicValue interface{}, format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
flogger.route(msg, panicContext)
panic(panicValue)
} }
func (flogger *internalFlogger) Panicln(v ...interface{}) { func (flogger *internalFlogger) Panicln(v ...interface{}) {
flogger.Println(v...) msg := fmt.Sprintln(v...)
panic(fmt.Sprintln(v...))
flogger.route(msg, panicContext)
panic(msg)
} }

View File

@ -6,23 +6,30 @@ import (
) )
var (
printContext = map[string]interface{}{
"~type":"print",
}
)
func (flogger *internalFlogger) Print(v ...interface{}) { func (flogger *internalFlogger) Print(v ...interface{}) {
msg := fmt.Sprint(v...) msg := fmt.Sprint(v...)
flogger.router.Route(msg, flogger.context) flogger.route(msg, printContext)
} }
func (flogger *internalFlogger) Printf(format string, v ...interface{}) { func (flogger *internalFlogger) Printf(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...) msg := fmt.Sprintf(format, v...)
flogger.router.Route(msg, flogger.context) flogger.route(msg, printContext)
} }
func (flogger *internalFlogger) Println(v ...interface{}) { func (flogger *internalFlogger) Println(v ...interface{}) {
msg := fmt.Sprintln(v...) msg := fmt.Sprintln(v...)
flogger.router.Route(msg, flogger.context) flogger.route(msg, printContext)
} }

35
trace.go 100644
View File

@ -0,0 +1,35 @@
package flog
import (
"fmt"
)
var (
traceContext = map[string]interface{}{
"~type":"trace",
}
)
func (flogger *internalFlogger) Trace(v ...interface{}) {
msg := fmt.Sprint(v...)
flogger.route(msg, traceContext)
}
func (flogger *internalFlogger) Tracef(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
flogger.route(msg, traceContext)
}
func (flogger *internalFlogger) Traceln(v ...interface{}) {
msg := fmt.Sprintln(v...)
flogger.route(msg, traceContext)
}

35
warn.go 100644
View File

@ -0,0 +1,35 @@
package flog
import (
"fmt"
)
var (
warnContext = map[string]interface{}{
"~type":"warn",
}
)
func (flogger *internalFlogger) Warn(v ...interface{}) {
msg := fmt.Sprint(v...)
flogger.route(msg, warnContext)
}
func (flogger *internalFlogger) Warnf(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
flogger.route(msg, warnContext)
}
func (flogger *internalFlogger) Warnln(v ...interface{}) {
msg := fmt.Sprintln(v...)
flogger.route(msg, warnContext)
}