Sha256: caf3091dfdc2ec38b6e427741c74f4376b9adeed6b66f580e8dda467558ee22d

Contents?: true

Size: 802 Bytes

Versions: 12

Compression:

Stored size: 802 Bytes

Contents

require 'webgen/websiteaccess'

module Webgen

  # This module should be included in all classes that need a logging facility.
  module Loggable

    # Log the result of the +block+ using the log level +log_level+.
    def log(sev_level, &block)
      source = (self.kind_of?(Class) ? self.name : self.class.name) + '#' + caller[0][%r"`.*"][1..-2]
      if WebsiteAccess.website && WebsiteAccess.website.logger && (!WebsiteAccess.website.config['logger.mask'] || source =~ WebsiteAccess.website.config['logger.mask'])
        WebsiteAccess.website.logger.send(sev_level, source, &block)
      end
    end

    # Shortcut for writing a line to the normal log output.
    def puts(*args)
      (args.last == :verbose ? log(:verbose) { args[0..-2].join } : log(:stdout) { args.join })
    end

  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 lib/webgen/loggable.rb
gettalong-webgen-0.5.5.20081001 lib/webgen/loggable.rb
gettalong-webgen-0.5.5.20081010 lib/webgen/loggable.rb
gettalong-webgen-0.5.5.20081012 lib/webgen/loggable.rb
gettalong-webgen-0.5.6.20081020 lib/webgen/loggable.rb
webgen-0.5.0 lib/webgen/loggable.rb
webgen-0.5.4 lib/webgen/loggable.rb
webgen-0.5.2 lib/webgen/loggable.rb
webgen-0.5.3 lib/webgen/loggable.rb
webgen-0.5.1 lib/webgen/loggable.rb
webgen-0.5.5 lib/webgen/loggable.rb
webgen-0.5.6 lib/webgen/loggable.rb