Class: Cucumber::Chef::Logger
- Inherits:
-
Logger
- Object
- Logger
- Cucumber::Chef::Logger
- Defined in:
- lib/cucumber/chef/logger.rb
Constant Summary collapse
- SEVERITIES =
Severity.constants.inject([]) {|arr,c| arr[Severity.const_get(c)] = c; arr}
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
-
#initialize(file = nil) ⇒ Logger
constructor
A new instance of Logger.
- #parse_caller(at) ⇒ Object
- #set_log_level(level = "INFO") ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ Logger
Returns a new instance of Logger.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cucumber/chef/logger.rb', line 34 def initialize(file=nil) if file.nil? config_path = File.join(Cucumber::Chef.locate_parent(".chef"), ".cucumber-chef") FileUtils.mkdir_p(config_path) file = File.join(config_path, "cucumber-chef.log") end #super(file, 7, (1024 * 1024)) super(file) set_log_level end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cucumber/chef/logger.rb', line 61 def add(severity, = nil, progname = nil, &block) return if (@level > severity) called_by = parse_caller(caller[1]) msg = (block && block.call) return if (msg.nil? || msg.strip.empty?) = [, progname, msg].delete_if{|i| i == nil}.join(": ") = "%19s.%06d | %5s | %5s | %s%s\n" % [Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"), Time.now.utc.usec, Process.pid.to_s, SEVERITIES[severity], called_by, ] @logdev.write() true end |
#parse_caller(at) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cucumber/chef/logger.rb', line 48 def parse_caller(at) if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at file = Regexp.last_match[1] line = Regexp.last_match[2] method = Regexp.last_match[3] "#{File.basename(file)}:#{line}:#{method} | " else "" end end |