Module: Logsy
- Defined in:
- lib/logsy.rb,
lib/logsy/store.rb,
lib/logsy/railtie.rb,
lib/logsy/version.rb,
lib/logsy/configuration.rb,
lib/logsy/json_formatter.rb,
lib/logsy/rack_middleware.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, RackMiddleware, Railtie, Store
Constant Summary collapse
- VERSION =
'0.2.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
18 19 20 |
# File 'lib/logsy.rb', line 18 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
30 31 32 |
# File 'lib/logsy.rb', line 30 def []=(key, value) Store.[key.to_sym] = value&.to_s end |
.configuration ⇒ Object
57 58 59 |
# File 'lib/logsy.rb', line 57 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
52 53 54 55 |
# File 'lib/logsy.rb', line 52 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.
43 44 45 |
# File 'lib/logsy.rb', line 43 def reset Store.reset end |
.reset_configuration! ⇒ Object
Test helper.
62 63 64 |
# File 'lib/logsy.rb', line 62 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.
36 37 38 |
# File 'lib/logsy.rb', line 36 def Store. end |