Module: Logsy
- Defined in:
- lib/logsy.rb,
lib/logsy/store.rb,
lib/logsy/version.rb,
lib/logsy/configuration.rb,
lib/logsy/json_formatter.rb,
lib/logsy/controller_hooks.rb,
lib/logsy/sidekiq_middleware.rb,
lib/logsy/sidekiq_middleware/client.rb,
lib/logsy/sidekiq_middleware/server.rb
Defined Under Namespace
Modules: ControllerHooks, SidekiqMiddleware Classes: Configuration, Error, JsonFormatter, Store
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.[](key) ⇒ Object
Read a tag from the per-request store.
-
.[]=(key, value) ⇒ Object
Write a tag into the per-request store.
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Configure the gem.
-
.reset ⇒ Object
Clear all tags.
-
.reset_configuration! ⇒ Object
Test helper.
-
.tags ⇒ Object
All tags currently set, as a hash.
Class Method Details
.[](key) ⇒ Object
Read a tag from the per-request store.
Logsy[:user_id] # => 'u-1' or nil
16 17 18 |
# File 'lib/logsy.rb', line 16 def [](key) Store.[key.to_sym] end |
.[]=(key, value) ⇒ Object
Write a tag into the per-request store. From this point on, every log line emitted during the current request (or job) carries it. Non-nil values are coerced to String so log fields have a consistent type when ingested by structured log stores (which often infer field type from the first value they see).
Logsy[:user_id] = user.id # 42 -> "42"
Logsy[:order_id] = nil # nil stays nil
28 29 30 |
# File 'lib/logsy.rb', line 28 def []=(key, value) Store.[key.to_sym] = value&.to_s end |
.configuration ⇒ Object
55 56 57 |
# File 'lib/logsy.rb', line 55 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configure the gem. Yields the Configuration instance.
Logsy.configure do |c|
c.job_propagated_keys = %i[request_id user_id]
end
50 51 52 53 |
# File 'lib/logsy.rb', line 50 def configure yield(configuration) configuration end |
.reset ⇒ Object
Clear all tags. The Rails executor calls this between requests, and the Sidekiq middleware calls it between jobs. You usually don’t need to call it yourself.
41 42 43 |
# File 'lib/logsy.rb', line 41 def reset Store.reset end |
.reset_configuration! ⇒ Object
Test helper.
60 61 62 |
# File 'lib/logsy.rb', line 60 def reset_configuration! @configuration = nil end |
.tags ⇒ Object
All tags currently set, as a hash. Used by the formatter on every log line; consumers can call it for debugging.
34 35 36 |
# File 'lib/logsy.rb', line 34 def Store. end |