Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add logger override option, use slog and capture driver as logs #497

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

GuyGoldenberg
Copy link
Contributor

This PR introduces 3 new changes:

  1. Change the default logger from the basic log package to slog
    • Another alternative was to use logr but this introduces a new dependency.
  2. Adding support for overriding the default logger with a custom logger
    • There are some projects allowing the conversion from other logging libraries to slog such as slog-zerolog slog-logrus
  3. Add a new SlogWriter which captures the output (stdout and stderr) from the driver and writes them in the logger with added fields for context (stream and source)

logger = option.Logger
}

if option.CaptureAllOutputWithLogger {
Copy link
Collaborator

@canstand canstand Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GuyGoldenberg, stderr of playwrightDriver is already redirected to options.Stderr in newPipTransport, and stdout only contains one-way communication protocol data. Is there a special reason to log the protocol output? Output is redirected to options.stdout and options.stderr. It is recommended that the caller handle logging itself.

@@ -72,7 +74,7 @@ func (t *pipeTransport) Send(msg map[string]interface{}) error {
if os.Getenv("DEBUGP") != "" {
fmt.Fprint(os.Stdout, "\x1b[32mSEND>\x1b[0m\n")
if err := json.NewEncoder(os.Stdout).Encode(msg); err != nil {
logger.Printf("could not encode json: %v\n", err)
logger.Error("could not encode json", pwlogger.ErrAttr(err))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants