feat: improve 'logger' field from logger

This commit is contained in:
Julien Neuhart
2021-12-08 15:41:08 +01:00
parent 8b8a02b68c
commit f376cd5ab1
3 changed files with 12 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ func Command(logger *zap.Logger, binPath string, args ...string) Cmd {
return Cmd{
ctx: nil,
logger: logger.Named("cmd"),
logger: logger.Named(strings.ReplaceAll(binPath, "/", "")),
process: cmd,
}
}
@@ -51,7 +51,7 @@ func CommandContext(ctx context.Context, logger *zap.Logger, binPath string, arg
return Cmd{
ctx: ctx,
logger: logger.Named("cmd"),
logger: logger.Named(strings.ReplaceAll(binPath, "/", "")),
process: cmd,
}, nil
}

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"
"github.com/google/uuid"
@@ -147,10 +148,17 @@ func loggerMiddleware(logger *zap.Logger, disableLoggingForPaths []string) echo.
return func(c echo.Context) error {
startTime := c.Get("startTime").(time.Time)
trace := c.Get("trace").(string)
rootPath := c.Get("rootPath").(string)
// Create the request logger and add it to our locals.
reqLogger := logger.With(zap.String("trace", trace))
c.Set("logger", reqLogger)
c.Set("logger", reqLogger.Named(func() string {
return strings.ReplaceAll(
strings.ReplaceAll(c.Request().URL.Path, rootPath, ""),
"/",
"",
)
}()))
// Call the next middleware in the chain.
err := next(c)
@@ -159,7 +167,6 @@ func loggerMiddleware(logger *zap.Logger, disableLoggingForPaths []string) echo.
}
for _, path := range disableLoggingForPaths {
rootPath := c.Get("rootPath").(string)
URI := fmt.Sprintf("%s%s", rootPath, path)
if c.Request().RequestURI == URI {

View File

@@ -355,7 +355,7 @@ func (mod Chromium) Routes() ([]api.Route, error) {
// drastically. In such a scenario, the given context may also be done before
// the end of the conversion.
func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath string, options Options) error {
debug := debugLogger{logger: logger.Named("chromium.debug")}
debug := debugLogger{logger: logger.Named("browser")}
userProfileDirPath := gotenberg.NewDirPath()
args := append(chromedp.DefaultExecAllocatorOptions[:],