mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 11:52:14 +01:00
all logs now have an op field
This commit is contained in:
@@ -1 +1,3 @@
|
||||
// Package logger defines a standard
|
||||
// logger for the application.
|
||||
package logger
|
||||
|
||||
@@ -1,33 +1,63 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Logger enforces specific log message formats.
|
||||
type Logger struct {
|
||||
*logrus.Entry
|
||||
entry *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{})
|
||||
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
l.SetFormatter(&logrus.JSONFormatter{})
|
||||
}
|
||||
return &Logger{
|
||||
l.WithField("trace", trace),
|
||||
entry: l.WithField("trace", trace),
|
||||
}
|
||||
}
|
||||
|
||||
// WithFields creates a new logger with
|
||||
// given fields.
|
||||
func (l *Logger) WithFields(fields map[string]interface{}) *Logger {
|
||||
return &Logger{
|
||||
entry: l.entry.WithFields(fields),
|
||||
}
|
||||
}
|
||||
|
||||
// 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...)
|
||||
l.entry.WithField("op", op).Debugf(format, args...)
|
||||
}
|
||||
|
||||
// ErrorOp logs an error message for given
|
||||
// InfofOp logs an info message for given
|
||||
// logical operation.
|
||||
func (l *Logger) InfofOp(op string, format string, args ...interface{}) {
|
||||
l.entry.WithField("op", op).Infof(format, args...)
|
||||
}
|
||||
|
||||
// ErrorOp logs an error for given
|
||||
// logical operation.
|
||||
func (l *Logger) ErrorOp(op string, err error) {
|
||||
l.WithField("op", op).Error(err.Error())
|
||||
l.entry.WithField("op", op).Error(err.Error())
|
||||
}
|
||||
|
||||
// ErrorfOp logs an error message for given
|
||||
// logical operation.
|
||||
func (l *Logger) ErrorfOp(op string, message string) {
|
||||
l.entry.WithField("op", op).Error(message)
|
||||
}
|
||||
|
||||
// FatalOp logs an error message for given
|
||||
// logical operation.
|
||||
func (l *Logger) FatalOp(op string, err error) {
|
||||
l.entry.WithField("op", op).Error(err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user