@@ -166,6 +166,11 @@ func Init(opts ...Option) error {
166166
167167 setDefaultLogger (sOpts .level , sOpts .json , logW )
168168
169+ // Update DefaultLogger to use the newly configured default.
170+ // This is critical because DefaultLogger was set at package init time
171+ // and klog, grpclog, and controller-runtime all reference it.
172+ DefaultLogger = slog .Default ()
173+
169174 klog .SetSlogLogger (DefaultLogger )
170175 // Route gRPC's internal INFO messages to DEBUG level so they only appear
171176 // when --dev or --log_level=debug is set. This reduces verbose gRPC logs
@@ -228,6 +233,39 @@ func Fatalf(format string, args ...any) {
228233 os .Exit (1 )
229234}
230235
236+ func logStructured (level slog.Level , msg string , args ... any ) {
237+ ctx := context .Background ()
238+ logger := slog .Default ()
239+ if ! logger .Enabled (ctx , level ) {
240+ return
241+ }
242+ var pcs [1 ]uintptr
243+ runtime .Callers (3 , pcs [:]) // skip [Callers, logStructured, Info/Debug/Warn/Error]
244+ r := slog .NewRecord (time .Now (), level , msg , pcs [0 ])
245+ r .Add (args ... )
246+ _ = logger .Handler ().Handle (ctx , r )
247+ }
248+
249+ // Info logs a structured info message with key-value pairs.
250+ func Info (msg string , args ... any ) {
251+ logStructured (slog .LevelInfo , msg , args ... )
252+ }
253+
254+ // Debug logs a structured debug message with key-value pairs.
255+ func Debug (msg string , args ... any ) {
256+ logStructured (slog .LevelDebug , msg , args ... )
257+ }
258+
259+ // Warn logs a structured warning message with key-value pairs.
260+ func Warn (msg string , args ... any ) {
261+ logStructured (slog .LevelWarn , msg , args ... )
262+ }
263+
264+ // Error logs a structured error message with key-value pairs.
265+ func Error (msg string , args ... any ) {
266+ logStructured (slog .LevelError , msg , args ... )
267+ }
268+
231269// New returns a new logr.Logger.
232270// deprecated: Remove usage and this method.
233271func New (enabled bool ) logr.Logger {
0 commit comments