geniusjoe commented on code in PR #1449:
URL: https://github.com/apache/pulsar-client-go/pull/1449#discussion_r2619832389


##########
examples/reader/reader.go:
##########
@@ -19,36 +19,61 @@ package main
 
 import (
        "context"
-       "fmt"
-       "log"
+       "io"
+       "log/slog"
+       "os"
 
        "github.com/apache/pulsar-client-go/pulsar"
+       pulsarlog "github.com/apache/pulsar-client-go/pulsar/log"
+       "gopkg.in/natefinch/lumberjack.v2"
 )
 
 func main() {
-       client, err := pulsar.NewClient(pulsar.ClientOptions{URL: 
"pulsar://localhost:6650"})
-       if err != nil {
-               log.Fatal(err)
+       fileLogger := &lumberjack.Logger{
+               Filename:   "/tmp/pulsar-go-sdk.log",
+               MaxSize:    100,
+               MaxBackups: 5,
+               LocalTime:  true,
        }
+       //      this multiLogger both print log to stdout and fileLogger
+       //  if only want to print log to file, just pass fileLogger to 
slog.NewJSONHandler()
+       multiLogger := io.MultiWriter(os.Stdout, fileLogger)
+       logger := slog.New(slog.NewJSONHandler(multiLogger, 
&slog.HandlerOptions{Level: slog.LevelInfo}))
+       slog.SetDefault(logger)

Review Comment:
   This is example code, and I think creating a new function to reuse the logs 
in each example isn't very meaningful. It's better to maintain the current 
state.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to