[client] Forward frontend console logs through the standard logger

Use the shared logrus logger alias and carry the JS origin in a dedicated
"ui" log field instead of inlining a [ui ...] tag in the message, keeping
frontend logs distinct from the Go-caller source.
This commit is contained in:
Zoltán Papp
2026-06-10 16:06:26 +02:00
parent 11281b681b
commit 439b85c584
+11 -11
View File
@@ -5,12 +5,12 @@ package services
import ( import (
"context" "context"
"github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// UILog lets the frontend forward console output into the Go logrus // UILog lets the frontend forward console output into the Go logrus
// pipeline. The JS origin rides in the message ("[ui <file:line>] ...") // pipeline. The JS origin is carried as the "ui" log field so it stays
// because logrus's ReportCaller always pins the source to this file. // distinct from logrus's own Go-caller source.
type UILog struct{} type UILog struct{}
func NewUILog() *UILog { return &UILog{} } func NewUILog() *UILog { return &UILog{} }
@@ -18,21 +18,21 @@ func NewUILog() *UILog { return &UILog{} }
// Log forwards one frontend console entry. level is trace/debug/info/warn/ // Log forwards one frontend console entry. level is trace/debug/info/warn/
// error (anything else → info); source is the JS origin (may be empty). // error (anything else → info); source is the JS origin (may be empty).
func (s *UILog) Log(_ context.Context, level, source, msg string) { func (s *UILog) Log(_ context.Context, level, source, msg string) {
origin := "unknown"
if source != "" { if source != "" {
msg = "[ui " + source + "] " + msg origin = source
} else {
msg = "[ui] " + msg
} }
entry := log.WithField("ui", origin)
switch level { switch level {
case "trace": case "trace":
logrus.Trace(msg) entry.Trace(msg)
case "debug": case "debug":
logrus.Debug(msg) entry.Debug(msg)
case "warn", "warning": case "warn", "warning":
logrus.Warn(msg) entry.Warn(msg)
case "error": case "error":
logrus.Error(msg) entry.Error(msg)
default: default:
logrus.Info(msg) entry.Info(msg)
} }
} }