@@ -371,46 +371,3 @@ func Test_replaceWithStaticTimestamps(t *testing.T) {
371371 })
372372 }
373373}
374-
375- func TestLogToSlogWriter (t * testing.T ) {
376- // This test makes sure that all the agent's remaining Log calls are correctly
377- // translated to slog.Error calls where appropriate.
378- //
379- // This list was generated using:
380- // git grep -i "log\.\(print\|fatal\)" pkg/ cmd/ | fgrep -e error -e failed
381- given := strings .TrimPrefix (`
382- failed to complete initial sync of %q data gatherer %q: %v
383- error messages will not show in the pod's events because the POD_NAME environment variable is empty
384- retrying in %v after error: %s
385- datagatherer informer for %q has failed and is backing off due to error: %s
386- this is a happy log that should show as INFO` , "\n " )
387- expect := strings .TrimPrefix (`
388- level=ERROR msg="failed to complete initial sync of %q data gatherer %q: %v" source=agent
389- level=ERROR msg="error messages will not show in the pod's events because the POD_NAME environment variable is empty" source=agent
390- level=ERROR msg="retrying in %v after error: %s" source=agent
391- level=ERROR msg="datagatherer informer for %q has failed and is backing off due to error: %s" source=agent
392- level=INFO msg="this is a happy log that should show as INFO" source=agent
393- ` , "\n " )
394-
395- gotBuf := & bytes.Buffer {}
396- slogHandler := slog .NewTextHandler (gotBuf , & slog.HandlerOptions {
397- // Remove the timestamp from the logs so that we can compare them.
398- ReplaceAttr : func (groups []string , a slog.Attr ) slog.Attr {
399- if a .Key == "time" {
400- return slog.Attr {}
401- }
402- return a
403- },
404- })
405- slogLogger := slog .New (slogHandler )
406-
407- logger := log .New (& bytes.Buffer {}, "" , 0 )
408- logger .SetOutput (logs.LogToSlogWriter {Slog : slogLogger , Source : "agent" })
409-
410- for _ , line := range strings .Split (given , "\n " ) {
411- // Simulate the current agent's logs.
412- logger .Print (line )
413- }
414-
415- assert .Equal (t , expect , gotBuf .String ())
416- }
0 commit comments