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

proposal: log: Asynchronous logging #15065

Closed
maxzerbini opened this issue Apr 1, 2016 · 3 comments
Closed

proposal: log: Asynchronous logging #15065

maxzerbini opened this issue Apr 1, 2016 · 3 comments

Comments

@maxzerbini
Copy link

Hi,
I think it could be useful to have at least three new methods in the log package:

  • AsyncPrint(v ...interface{})
  • AsyncPrintf(format string, v ...interface{})
  • AsyncPrintln(v ...interface{})

these methods should produce the same output of the respective synchronous methods, but the operations will be performed in a separated goroutine.

The same methods should also be added to the Logger type.

The implementation of these methods can be realized using a buffered channel in which messages to be logged are written and a consumer goroutine reads the requests and write the logs. The maximum limit of requests in the buffer should be configurable.

Best regards,
Massimo

@bradfitz
Copy link
Contributor

bradfitz commented Apr 1, 2016

See https://golang.org/doc/faq#x_in_std

This is already possible by implementing your own io.Writer type that does the behavior you need, and using that with log.New.

@bradfitz bradfitz closed this as completed Apr 1, 2016
@maxzerbini
Copy link
Author

Yes it's correct, but all major logging libraries offer the ability to write log asynchronously, it seems unusual that Go does not provide "natively" even using a different approach from what I've described.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 1, 2016

You might have a point, but your API proposal is not what we'd do in Go and distracts from the problem.

You could imagine a new constructor or setter method in the log package to enable N bytes of in-memory buffering before pushback occurs.

Do you have an implementation? A proof of concept outside the standard library would be a requirement to adding anything to the standard library anyway.

Let's move this discussion to a forum (see https://golang.org/wiki/Questions) for now, though, because I imagine this has come up before.

If the golang-nuts@ thread yields any new info, the summary of that information can be posted here and we can reconsider.

@golang golang locked and limited conversation to collaborators Apr 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants