2015-10-14 02:16:33 +00:00
|
|
|
package flog
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
errorContext = map[string]interface{}{
|
|
|
|
"~type":"error",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (flogger *internalFlogger) Error(v ...interface{}) {
|
|
|
|
|
|
|
|
msg := fmt.Sprint(v...)
|
|
|
|
|
2016-07-27 21:51:04 +00:00
|
|
|
errCtx := newErrorContext(errorContext, v...)
|
|
|
|
|
|
|
|
flogger.route(msg, errCtx)
|
2015-10-14 02:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (flogger *internalFlogger) Errorf(format string, v ...interface{}) {
|
|
|
|
|
|
|
|
msg := fmt.Sprintf(format, v...)
|
|
|
|
|
2016-07-27 21:51:04 +00:00
|
|
|
errCtx := newErrorContext(errorContext, v...)
|
|
|
|
|
|
|
|
flogger.route(msg, errCtx)
|
2015-10-14 02:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
|
2016-07-27 21:51:04 +00:00
|
|
|
errCtx := newErrorContext(errorContext, v...)
|
|
|
|
|
|
|
|
flogger.route(msg, errCtx)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newErrorContext(baseContext map[string]interface{}, v ...interface{}) map[string]interface{} {
|
|
|
|
|
|
|
|
|
|
|
|
// Collect any errors.
|
|
|
|
errs := []error{}
|
|
|
|
for _, datum := range v {
|
|
|
|
if err, ok := datum.(error); ok {
|
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if 0 == len(errs) {
|
|
|
|
return baseContext
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Copy the base context.
|
|
|
|
context := map[string]interface{}{}
|
|
|
|
for k,v := range baseContext {
|
|
|
|
context[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Put the collected errors in this new context.
|
|
|
|
context["~errors"] = errs
|
|
|
|
|
|
|
|
|
|
|
|
return context
|
2015-10-14 02:16:33 +00:00
|
|
|
}
|