Logging: slog foundation with component, device and transport attributes - #32018
Draft
andig wants to merge 19 commits into
Draft
Logging: slog foundation with component, device and transport attributes#32018andig wants to merge 19 commits into
andig wants to merge 19 commits into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
handler.Handle, the UI message path re-applies redaction totext.String()even though the full line was already redacted, which adds unnecessary work and could be simplified by reusing the redacted text or avoiding the secondredactedcall. - The new
Logger.With/handler.withAPI is quite loosely typed; consider documenting or constraining expected argument patterns (e.g. key/value pairs vsslog.Attr) to make misuse less likely and to avoid silently generating!BADKEYattributes. - The
levelStringhelper derives textual levels from numeric comparisons againstLevelTrace/LevelFatal; it may be clearer and less fragile to explicitly map the defined custom levels (LevelTrace,LevelFatal) and standard slog levels to their string representations rather than relying on ranges.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `handler.Handle`, the UI message path re-applies redaction to `text.String()` even though the full line was already redacted, which adds unnecessary work and could be simplified by reusing the redacted text or avoiding the second `redacted` call.
- The new `Logger.With`/`handler.with` API is quite loosely typed; consider documenting or constraining expected argument patterns (e.g. key/value pairs vs `slog.Attr`) to make misuse less likely and to avoid silently generating `!BADKEY` attributes.
- The `levelString` helper derives textual levels from numeric comparisons against `LevelTrace`/`LevelFatal`; it may be clearer and less fragile to explicitly map the defined custom levels (`LevelTrace`, `LevelFatal`) and standard slog levels to their string representations rather than relying on ranges.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…xtLoggerWithDefault
andig
marked this pull request as draft
July 21, 2026 17:19
…ore first read" This reverts commit 38cfa7b.
# Conflicts: # charger/daheimladen.go # charger/em2go-duo.go # charger/em2go.go # charger/evsedin.go # charger/homeassistant.go # charger/openwb-native_linux.go # meter/mbmd.go # tariff/proxy_cache.go
Adds a log panel to the device configuration modal that shows the log entries of
that device only, refreshed every two seconds while the modal is open.
The device logger area (db:<id> plus title) moves into config.Config.LogArea so
both the logger setup and the new /api/config/devices/{class}/{id}/log endpoint
derive it from the same place.
Shares the log level/count query parsing between the system and device log handlers, moves the per-level log styles into app.css instead of repeating them per view, and drops the unused reactive level and per-line keys from the device log component. The device log endpoint now verifies that the requested class matches the stored device instead of ignoring the path segment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactors logging onto
log/slog, stepwise (core first, then devices, then the log API):util.Loggernow embeds*slog.Logger; the printf-styleTRACE…FATALlevel loggers are provided viaslog.NewLogLogger, so all existing call sites remain unchanged. Log levels are kept, with trace and fatal as custom slog levels.slog.Handlerapplies redaction centrally (now also covering the ui log feed, previously unredacted) and fans out structured entries to stdout (classic line format, gated by per-area level), the logstash ring buffer and the ui./api/system/logreturns structured entries (time,area,level,message,attrs);format=txtrenders the classic line format server-side. Log and issue views render entries client-side.componentwith subtype (site,loadpointincl.id,charger/abb,vehicle/tesla, …) — class attached by setup, subtype appended by the device constructor via the newutil.LoggerFromContext;pluginfor plugins including transports (http,mqtt,modbus,oauth, …);titlewhere configured. Attribute keys are constants inutil.util.LoggerFromContext(ctx, subtype)andutil.PluginLoggerFromContext(ctx, area)replace theContextLoggerWithDefault(ctx, util.NewLogger(…))idiom; device constructors with context now log under the per-device logger (instance name as area, component/title attributes), falling back to the classic type area when used standalone.modbus.Connection.Loggertakes a*util.Loggerand tags traces itself, aligned with http and mqtt.registry.AddCtx), so every constructor logs under the per-device logger with full attribution; tests passt.Context().SLOG=1environment variable opts the console output into the slog default text format (time=… level=… msg=… area=… component=…); the classic line format remains the default, and the log api, ring buffer and ui are unaffected.db:<id>plus title) moves intoconfig.Config.LogArea, shared by the logger setup and the new/api/config/devices/{class}/{id}/logendpoint.🤖 Generated with Claude Code