@@ -3,7 +3,7 @@ package sample
33import (
44 "context"
55 "fmt"
6- "log"
6+ "log/slog "
77 "math/rand/v2"
88 "sync/atomic"
99 "time"
@@ -36,7 +36,7 @@ func SampleByRandLogStreams(
3636 g .Go (func () error {
3737 processed , err := processLogGroup (ctx , client , cutoff , srcGroup , dstGroup , randLogStreamsNumber )
3838 if err != nil {
39- fmt . Printf ( "error processing log group %s: %v \n " , srcGroup , err )
39+ slog . WarnContext ( ctx , "error processing log group" , "log_group" , srcGroup , "error" , err )
4040 return nil
4141 }
4242 processedLogStreams .Add (processed )
@@ -45,7 +45,7 @@ func SampleByRandLogStreams(
4545 }
4646
4747 _ = g .Wait ()
48- log . Printf ( "processed %d log streams \n " , processedLogStreams .Load ())
48+ slog . InfoContext ( ctx , "complete log stream processing" , "number " , processedLogStreams .Load ())
4949}
5050
5151func processLogGroup (
@@ -60,17 +60,17 @@ func processLogGroup(
6060 return processed , fmt .Errorf ("describe log streams: %w" , err )
6161 }
6262 if len (allStreams ) == 0 {
63- fmt . Println ( "no log streams found" )
63+ slog . InfoContext ( ctx , "no log streams found" )
6464 return processed , nil
6565 }
66- fmt . Printf ( "number of log streams: %d \n " , len (allStreams ))
66+ slog . InfoContext ( ctx , "list log streams" , "number " , len (allStreams ))
6767
6868 randStreams := pickRandomLogStreams (allStreams , randLogStreamsNumber )
6969 randStreamNames := make ([]string , len (randStreams ))
7070 for i , s := range randStreams {
7171 randStreamNames [i ] = aws .ToString (s .LogStreamName )
7272 }
73- fmt . Printf ( "randomly selected streams: %v \n " , randStreamNames )
73+ slog . InfoContext ( ctx , "pick random log streams" , "number" , len ( randStreamNames ) )
7474
7575 for _ , srcStreamName := range randStreamNames {
7676 // logGroupName/streamName/year/month/day/hour/minutes - almost the same format as CloudWatch Data Protection uses
@@ -80,8 +80,8 @@ func processLogGroup(
8080 srcStreamName ,
8181 time .Now ().UTC ().Format ("2006/01/02/15/04" ),
8282 )
83- fmt .Println ("destination stream name:" , dstStreamName )
8483
84+ slog .InfoContext (ctx , "copy log streams" , "src_stream" , srcStreamName , "dst_stream" , dstStreamName )
8585 err = cloudwatchlogs .CopyLogStream (
8686 ctx ,
8787 client ,
@@ -91,7 +91,7 @@ func processLogGroup(
9191 dstStreamName ,
9292 )
9393 if err != nil {
94- fmt . Printf ( "error copying log stream %s: %v \n " , srcStreamName , err )
94+ slog . WarnContext ( ctx , "error copying log stream" , "error" , err )
9595 continue
9696 }
9797 processed ++
0 commit comments