Sha256: e2033d7f0be4a813f3ed254d16f831da95d82c23ae2c8e956bfc30efacd1494d

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

require "cabin/namespace"

module Cabin::Logger
  attr_accessor :level
  LEVELS = {
    :fatal => 0,
    :error => 1,
    :warn => 2,
    :info => 3,
    :debug => 4
  }

  # Define the usual log methods: info, fatal, etc.
  # Each level-based method accepts both a message and a hash data.
  %w(fatal error warn info debug).each do |level|
    level = level.to_sym
    # def info, def warn, etc...
    define_method(level) do |message, data={}|
      next unless LEVELS[@level] >= LEVELS[level]
      if message.is_a?(Hash)
        data.merge!(message)
      else
        data[:message] = message
      end
      data[:level] = level
      publish(data)
    end
  end # end defining level-based log methods
end # module Cabin::Logger

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cabin-0.1.1 lib/cabin/logger.rb
cabin-0.1.0 lib/cabin/logger.rb