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

Don't output to stdout directly #512

Open
RangelReale opened this issue Jul 10, 2023 · 2 comments
Open

Don't output to stdout directly #512

RangelReale opened this issue Jul 10, 2023 · 2 comments

Comments

@RangelReale
Copy link

Is your feature request related to a problem? Please describe.
When the handlers returns any non-nil error, reportFailure is called and it does a raw log.Printf call, outputting a line in the standard go format like 2023/07/10 20:12:21 {"errorMessage":"error"}, breaking our logs handling which expects all logs to be JSON.

Describe the solution you'd like
Libraries should not output to stdout, at least a logger should be configurable.

Describe alternatives you've considered

Additional context

@bmoffatt
Copy link
Collaborator

The error logging was added in #416 to help with behavioral compatibility when migrating from the the go1.x runtime to provided.al2 - so don't think we'd change the default. I would however be OK with adding an option to disable all logging by this library.


slog with v1.21 looks like it provides an option to change the behavior of the default log.Printf calls. Does this solve your output formatting problem? Or would you still find it useful to be able to entirely opt-out of any info logging done by aws-lambda-go?

Something like:

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)
lambda.Start(/* ... */)

ref: https://pkg.go.dev/log/slog#SetDefault

SetDefault makes l the default Logger. After this call, output from the log package's default Logger (as with log.Print, etc.) will be logged at LevelInfo using l's Handler.

@RangelReale
Copy link
Author

I think disabling all logs by default would be preferable, I don't expect that importing a library would output anything by default. Logging providers are very expensive with logs, we like to have complete control of them because this is a cost problem.

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

No branches or pull requests

2 participants