class Dockly::Util::Logger
Constants
- LEVELS
Attributes
output[W]
print_method[W]
output[RW]
prefix[RW]
print_method[RW]
print_method?[RW]
Public Class Methods
disable!()
click to toggle source
# File lib/dockly/util/logger.rb, line 78 def disable! @logger_enabled = false end
enable!()
click to toggle source
# File lib/dockly/util/logger.rb, line 82 def enable! @logger_enabled = true end
enabled?()
click to toggle source
# File lib/dockly/util/logger.rb, line 86 def enabled? enable! if @logger_enabled.nil? @logger_enabled end
new(prefix = "", output = Dockly::Util::Logger.output, print_method = Dockly::Util::Logger.print_method)
click to toggle source
# File lib/dockly/util/logger.rb, line 7 def initialize(prefix = "", output = Dockly::Util::Logger.output, print_method = Dockly::Util::Logger.print_method) @prefix = prefix @print_method = print_method @output = output end
output()
click to toggle source
# File lib/dockly/util/logger.rb, line 95 def output @output ||= STDOUT end
print_method()
click to toggle source
# File lib/dockly/util/logger.rb, line 91 def print_method (@print_method == false) ? false : true end
Public Instance Methods
format_level(level)
click to toggle source
# File lib/dockly/util/logger.rb, line 34 def format_level(level) (char = level.to_s[0]) ? char.upcase : nil end
format_message(level, message)
click to toggle source
# File lib/dockly/util/logger.rb, line 21 def format_message(level, message) [ format_level(level), Time.now.iso8601, Process.pid.to_s, Thread.current.object_id.to_s, Thread.current[:rake_task].to_s, prefix, get_last_method, message ].compact.reject(&:empty?).join(' ') end
get_last_method()
click to toggle source
# File lib/dockly/util/logger.rb, line 38 def get_last_method if print_method? file_and_method = caller.reject { |trace| trace =~ /dockly\/util\/logger\.rb|block \(\d+ levels\)/ }.first file_and_method.match(/:in `(.+)'$/)[1] end end
log(level, message)
click to toggle source
# File lib/dockly/util/logger.rb, line 13 def log(level, message) output.puts(format_message(level, message)) if self.class.enabled? end
with_prefix(new_prefix = "", output = nil, print_method = nil) { |class.new([prefix, new_prefix].reject(&:empty?).join(' '), output, print_method)| ... }
click to toggle source
# File lib/dockly/util/logger.rb, line 45 def with_prefix(new_prefix = "", output = nil, print_method = nil) output ||= self.output print_method ||= self.print_method yield(self.class.new([prefix, new_prefix].compact.reject(&:empty?).join(' '), output, print_method)) end