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

Merged

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)

run.go Outdated
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.

transport.go Outdated
@@ -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.

@canstand canstand self-requested a review December 9, 2024 07:14
@canstand canstand force-pushed the add-logger-override-support branch from 36d88c0 to ca08a43 Compare December 9, 2024 13:51
Copy link
Collaborator

@canstand canstand left a comment

Choose a reason for hiding this comment

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

I changed slog.TextHandler back to defaultHandler, removed slog.Attrs etc. These are left for users to customize logger.

@canstand canstand merged commit c6f85ed into playwright-community:main Dec 10, 2024
22 checks passed
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