mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-06 21:49:08 +02:00
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.
39 lines
890 B
Go
39 lines
890 B
Go
//go:build !android && !ios && !freebsd && !js
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// UILog lets the frontend forward console output into the Go logrus
|
|
// pipeline. The JS origin is carried as the "ui" log field so it stays
|
|
// distinct from logrus's own Go-caller source.
|
|
type UILog struct{}
|
|
|
|
func NewUILog() *UILog { return &UILog{} }
|
|
|
|
// Log forwards one frontend console entry. level is trace/debug/info/warn/
|
|
// error (anything else → info); source is the JS origin (may be empty).
|
|
func (s *UILog) Log(_ context.Context, level, source, msg string) {
|
|
origin := "unknown"
|
|
if source != "" {
|
|
origin = source
|
|
}
|
|
entry := log.WithField("ui", origin)
|
|
switch level {
|
|
case "trace":
|
|
entry.Trace(msg)
|
|
case "debug":
|
|
entry.Debug(msg)
|
|
case "warn", "warning":
|
|
entry.Warn(msg)
|
|
case "error":
|
|
entry.Error(msg)
|
|
default:
|
|
entry.Info(msg)
|
|
}
|
|
}
|