mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 20:02:15 +01:00
wip refactoring: better logging and error systems
This commit is contained in:
1
internal/pkg/logger/doc.go
Normal file
1
internal/pkg/logger/doc.go
Normal file
@@ -0,0 +1 @@
|
||||
package logger
|
||||
33
internal/pkg/logger/logger.go
Normal file
33
internal/pkg/logger/logger.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user