mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Drop time precision below seconds in log output. (#450)
This commit is contained in:
parent
018e0e55f7
commit
24151345f5
1 changed files with 12 additions and 1 deletions
|
|
@ -16,6 +16,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/certs"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/filter"
|
||||
|
|
@ -196,6 +197,15 @@ func (cfg *config) prepareDirectory() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// dropSubSeconds drops all parts below resolution of seconds.
|
||||
func dropSubSeconds(_ []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == slog.TimeKey {
|
||||
t := a.Value.Time()
|
||||
a.Value = slog.TimeValue(t.Truncate(time.Second))
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// prepareLogging sets up the structured logging.
|
||||
func (cfg *config) prepareLogging() error {
|
||||
var w io.Writer
|
||||
|
|
@ -219,6 +229,7 @@ func (cfg *config) prepareLogging() error {
|
|||
ho := slog.HandlerOptions{
|
||||
//AddSource: true,
|
||||
Level: cfg.LogLevel.slogLevel(),
|
||||
ReplaceAttr: dropSubSeconds,
|
||||
}
|
||||
handler := slog.NewJSONHandler(w, &ho)
|
||||
logger := slog.New(handler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue