wip refactoring: better logging and error systems

This commit is contained in:
Julien Neuhart
2019-07-07 17:45:07 +02:00
parent a4aa8dafac
commit c8f7ea934c
36 changed files with 1346 additions and 1096 deletions

View File

@@ -0,0 +1 @@
package logger

View File

@@ -0,0 +1,33 @@
package logger
import (
"github.com/sirupsen/logrus"
)
// Logger enforces specific log message formats.
type Logger struct {
*logrus.Entry
}
// New initializes the logger.
func New(level logrus.Level, trace string) *Logger {
l := logrus.New()
l.SetLevel(level)
// TODO no formatter if TTY.
l.SetFormatter(&logrus.JSONFormatter{})
return &Logger{
l.WithField("trace", trace),
}
}
// DebugfOp logs a debug message for given
// logical operation.
func (l *Logger) DebugfOp(op string, format string, args ...interface{}) {
l.WithField("op", op).Debugf(format, args...)
}
// ErrorOp logs an error message for given
// logical operation.
func (l *Logger) ErrorOp(op string, err error) {
l.WithField("op", op).Error(err.Error())
}