Sha256: 04de868eb44357f9f9a0ffe4d819e4b917cd79c7a43908d4613cf842afb17d8d

Contents?: true

Size: 882 Bytes

Versions: 9

Compression:

Stored size: 882 Bytes

Contents

require_relative '../lib/lager'

class Foo
  extend Lager
  log_to $stdout, :debug  # sets up @lager at the class layer

  def self.bar(baz)
    unless baz.is_a?(String)
      @lager.debug { "baz #{baz} is a #{baz.class}, not a string" }
    end
  end

  def initialize
    # set the instance layer's @lager to the class layer's @lager
    @lager = self.class.lager
    # now both layers are using the same instance
  end

  def do_something_complicated
    @lager.debug { "about to do something complicated" }
    # ...
    @lager.debug { "whew! we made it!" }
  end
end

if __FILE__ == $0
  puts "About to spew debug messages"
  Foo.bar(15)
  f = Foo.new
  f.do_something_complicated

  puts "Now updating Foo's log level"
  Foo.log_level :warn
  Foo.new.do_something_complicated

  puts "Now the same calls as before"
  Foo.bar(15)
  f = Foo.new
  f.do_something_complicated
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lager-1.1.3.1 examples/usage.rb
lager-1.1.2.1 examples/usage.rb
lager-1.1.0.1 examples/usage.rb
lager-1.0.0.3 examples/usage.rb
lager-1.0.0.1 examples/usage.rb
lager-0.2.0.9 examples/usage.rb
lager-0.2.0.8 examples/usage.rb
lager-0.2.0.6 examples/usage.rb
lager-0.2.0.5 examples/usage.rb