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


##########
examples/producer/producer.go:
##########
@@ -20,40 +20,58 @@ 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() {
+       fileLogger := &lumberjack.Logger{
+               Filename:   "/tmp/pulsar-go-sdk.log",
+               MaxSize:    100,
+               MaxBackups: 5,
+               LocalTime:  true,
+       }
+       //      this multiLogger both print log to stdout and fileLogger

Review Comment:
   Grammar issues in comment: "print" should be "prints" (subject-verb 
agreement), and "log" should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and the file via 
fileLogger
   ```



##########
examples/producer/producer.go:
##########
@@ -20,40 +20,58 @@ 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() {
+       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()

Review Comment:
   Grammar issues in comment: missing subject "you" after "if", and "log" 
should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and fileLogger
        //  if you only want to print logs to file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
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()

Review Comment:
   Grammar issues in comment: missing subject "you" after "if", and "log" 
should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and fileLogger
        //  if you only want to print logs to a file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
examples/consumer/consumer.go:
##########
@@ -19,18 +19,38 @@ 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

Review Comment:
   Grammar issues in comment: "print" should be "prints" (subject-verb 
agreement), and "log" should be "logs" (plural).
   ```suggestion
        //      this multiLogger both prints logs to stdout and fileLogger
   ```



##########
examples/consumer-listener/consumer-listener.go:
##########
@@ -18,45 +18,65 @@
 package main
 
 import (
-       "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

Review Comment:
   Grammar issues in comment: "print" should be "prints" (subject-verb 
agreement), and "log" should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and fileLogger
   ```



##########
examples/consumer/consumer.go:
##########
@@ -19,18 +19,38 @@ 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()

Review Comment:
   Grammar issues in comment: missing subject "you" after "if", and "log" 
should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and fileLogger
        //  if you only want to print logs to a file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
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:
   The logger initialization code (lines 32-42) is duplicated across all 
example files (producer, consumer, reader, consumer-listener). Consider 
extracting this into a shared helper function or a common example utilities 
package to improve maintainability and consistency across examples.



##########
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

Review Comment:
   Grammar issues in comment: "print" should be "prints" (subject-verb 
agreement), and "log" should be "logs" (plural).
   ```suggestion
        //      this multiLogger both prints logs to stdout and fileLogger
   ```



##########
examples/consumer-listener/consumer-listener.go:
##########
@@ -18,45 +18,65 @@
 package main
 
 import (
-       "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()

Review Comment:
   Grammar issues in comment: missing subject "you" after "if", and "log" 
should be "logs" (plural).
   ```suggestion
        //      this multiLogger prints logs to both stdout and fileLogger
        //  if you only want to print logs to a file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
examples/producer/producer.go:
##########
@@ -20,40 +20,58 @@ 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() {
+       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()

Review Comment:
   Comment formatting is inconsistent: there's an extra space after the "//" on 
line 39, and the comment on line 41 has two spaces after "//". Comments should 
consistently use "// " (one space after "//").
   ```suggestion
        // this multiLogger both print log to stdout and fileLogger
        // if only want to print log to file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
examples/consumer-listener/consumer-listener.go:
##########
@@ -18,45 +18,65 @@
 package main
 
 import (
-       "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()

Review Comment:
   Comment formatting is inconsistent: there's an extra space after the "//" on 
line 37, and the comment on line 39 has two spaces after "//". Comments should 
consistently use "// " (one space after "//").
   ```suggestion
        // this multiLogger both print log to stdout and fileLogger
        // if only want to print log to file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
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()

Review Comment:
   Comment formatting is inconsistent: there's an extra space after the "//" on 
line 38, and the comment on line 40 has two spaces after "//". Comments should 
consistently use "// " (one space after "//").
   ```suggestion
        // this multiLogger both print log to stdout and fileLogger
        // if only want to print log to file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



##########
examples/consumer/consumer.go:
##########
@@ -19,18 +19,38 @@ 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()

Review Comment:
   Comment formatting is inconsistent: there's an extra space after the "//" on 
line 38, and the comment on line 40 has two spaces after "//". Comments should 
consistently use "// " (one space after "//").
   ```suggestion
        // this multiLogger both print log to stdout and fileLogger
        // if only want to print log to file, just pass fileLogger to 
slog.NewJSONHandler()
   ```



-- 
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