You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/logger/README.md
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ A simple, debug-style logging framework for Go that follows the pattern matching
12
12
-**Pattern matching**: Enable/disable loggers using wildcards and exclusions via the `DEBUG` environment variable
13
13
-**Printf interface**: Standard printf-style formatting
14
14
-**Time diff display**: Shows time elapsed since last log call (like debug npm package)
15
-
-**Automatic color coding**: Each namespace gets a unique color when stderr is a TTY
15
+
-**Automatic color coding**: Each namespace gets a unique color, determined by `DEBUG_COLORS` and rendered by lipgloss
16
16
-**Zero overhead**: Logger enabled state is computed once at construction time
17
17
-**Thread-safe**: Safe for concurrent use
18
18
@@ -38,6 +38,17 @@ The `Logger` type provides namespace-based debug logging with pattern matching,
38
38
|`NewSlogHandler`|`func(logger *Logger) *SlogHandler`| Creates a `slog.Handler` wrapping the given `Logger`|
39
39
|`NewSlogLoggerWithHandler`|`func(logger *Logger) *slog.Logger`| Creates a `slog.Logger` backed by the given `Logger`|
40
40
41
+
**Behavioral contracts**:
42
+
43
+
-`New` MUST compute the enabled state exactly once at construction time from the `DEBUG` environment variable (or `ACTIONS_RUNNER_DEBUG=true` as a fallback); subsequent changes to those variables MUST NOT affect already-constructed `Logger` instances.
44
+
-`Logger.Printf` and `Logger.Print` MUST be no-ops (return immediately before any string formatting or I/O) when `Enabled()` returns `false`.
45
+
-`Logger.Printf` and `Logger.Print` MUST write all output to `os.Stderr` and MUST append a trailing newline to every message.
46
+
-`Logger.Printf` and `Logger.Print` MUST include a `+<duration>` suffix showing elapsed time since the previous call on the same instance.
47
+
-`Logger.Printf` and `Logger.Print` MUST acquire an internal mutex before updating the `lastLog` timestamp; concurrent callers MUST receive independent, accurate time-diff values without data races.
48
+
-`SlogHandler.Enabled` MUST return `false` when the underlying `Logger.Enabled()` is `false`, preventing attribute collection overhead for disabled loggers.
49
+
-`SlogHandler.WithAttrs` and `SlogHandler.WithGroup` MUST return the receiver unchanged; attributes and groups are not accumulated across calls.
50
+
- Color styling MUST be disabled when `DEBUG_COLORS=0`; when enabled, actual color rendering is delegated to lipgloss which adapts to the output terminal's capabilities.
Colors are automatically assigned to each namespace when:
115
-
- Stderr is a TTY (terminal)
116
-
-`DEBUG_COLORS` is not set to `0`
125
+
Color styling is enabled when `DEBUG_COLORS` is not set to `0`. The [lipgloss](https://github.com/charmbracelet/lipgloss) library handles actual color rendering and adapts to the output terminal's capabilities; colors are typically suppressed when piping output to a non-TTY stream.
117
126
118
-
Each namespace gets a consistent color based on a hash of its name. This makes it easy to visually distinguish between different loggers.
127
+
Each namespace gets a consistent color based on a FNV-1a hash of its name. This makes it easy to visually distinguish between different loggers.
0 commit comments