Class | Cabin::Channel |
In: |
lib/cabin/channel.rb
lib/cabin/channel.rb |
Parent: | Object |
A wonderful channel for logging.
You can log normal messages through here, but you should be really shipping structured data. A message is just part of your data. "An error occurred" - in what? when? why? how?
Logging channels support the usual ‘info’ ‘warn’ and other logger methods provided by Ruby‘s stdlib Logger class
It additionally allows you to store arbitrary pieces of data in it like a hash, so your call stack can do be this:
@logger = Cabin::Channel.new rubylog = Logger.new(STDOUT) # ruby's stlib logger @logger.subscribe(rubylog) def foo(val) context = @logger.context() context[:foo] = val context[:example] = 100 bar() # Clear any context we just wanted bar() to know about context.clear() @logger.info("Done in foo") end def bar @logger.info("Fizzle") end
The result:
I, [2011-10-11T01:00:57.993200 #1209] INFO -- : {:timestamp=>"2011-10-11T01:00:57.992353-0700", :foo=>"Hello", :example=>100, :message=>"Fizzle", :level=>:info} I, [2011-10-11T01:00:57.993575 #1209] INFO -- : {:timestamp=>"2011-10-11T01:00:57.993517-0700", :message=>"Done in foo", :level=>:info}
metrics | [RW] | All channels come with a metrics provider. |
metrics | [RW] | All channels come with a metrics provider. |
Get a channel for a given identifier. If this identifier has never been used, a new channel is created for it. The default identifier is the application executable name.
This is useful for using the same Cabin::Channel across your entire application.
Get a channel for a given identifier. If this identifier has never been used, a new channel is created for it. The default identifier is the application executable name.
This is useful for using the same Cabin::Channel across your entire application.
Publish data to all outputs. The data is expected to be a hash or a string.
A new hash is generated based on the data given. If data is a string, then it will be added to the new event hash with key :message.
A special key :timestamp is set at the time of this method call. The value is a string ISO8601 timestamp with microsecond precision.
Publish data to all outputs. The data is expected to be a hash or a string.
A new hash is generated based on the data given. If data is a string, then it will be added to the new event hash with key :message.
A special key :timestamp is set at the time of this method call. The value is a string ISO8601 timestamp with microsecond precision.
Subscribe a new input New events will be sent to the subscriber using the ’<<’ method
foo << event
Returns a subscription id you can use later to unsubscribe
Subscribe a new input New events will be sent to the subscriber using the ’<<’ method
foo << event
Returns a subscription id you can use later to unsubscribe