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}

Methods

[]   []   []=   []=   context   context   each   each   filter   filter   filters   filters   get   get   new   new   publish   publish   remove   remove   set   set   subscribe   subscribe   unsubscribe   unsubscribe  

Included Modules

Cabin::Mixins::Timestamp Cabin::Mixins::Logger Cabin::Mixins::Pipe Cabin::Mixins::Timer Cabin::Mixins::Terminal Cabin::Mixins::Timestamp Cabin::Mixins::Logger Cabin::Mixins::Pipe Cabin::Mixins::Timer Cabin::Mixins::Terminal

Attributes

metrics  [RW]  All channels come with a metrics provider.
metrics  [RW]  All channels come with a metrics provider.

Public Class methods

Register a new filter. The block is passed the event. It is expected to modify that event or otherwise do nothing.

Register a new filter. The block is passed the event. It is expected to modify that event or otherwise do nothing.

Get a list of filters included in this class.

Get a list of filters included in this class.

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.

Create a new logging channel. The default log level is ‘info‘

Create a new logging channel. The default log level is ‘info‘

Public Instance methods

Get a context value by name.

Get a context value by name.

Set some contextual map value

Set some contextual map value

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.

Remove a context value by name.

Remove a context value by name.

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

Unsubscribe. Takes a ‘subscription id’ as returned by the subscribe method

Unsubscribe. Takes a ‘subscription id’ as returned by the subscribe method

[Validate]