Skip to content

Instantly share code, notes, and snippets.

@ioquatix
Created December 28, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioquatix/6eafd57374ef73d299fdfddfab2f4979 to your computer and use it in GitHub Desktop.
Save ioquatix/6eafd57374ef73d299fdfddfab2f4979 to your computer and use it in GitHub Desktop.
Async nested logging
#!/usr/bin/env RBENV_VERSION=2.7.0 ruby
gem 'async'
require 'async'
Async do |task|
Async.logger.info("Incoming request...")
Async(logger: task.logger.with(name: "request-id-1234")) do
Async.logger.info("Database Query")
Async do
Async.logger.info("HTTP request")
end
end
end
@ioquatix
Copy link
Author

image

@ioquatix
Copy link
Author

ioquatix commented Dec 28, 2019

You can use serialized output too:

require 'console/serialized/logger'
Console.logger.output = Console::Serialized::Logger.new

image

(There was a bug in console 1.6.0 so preparing 1.7.0 which makes the above possible).

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