Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

logger refactor

  • Loading branch information...
commit e9bbfa80ae3e3d595f44fd02dfd7a26e1f7a2ec0 1 parent 7aa11be
Zachary Patten authored
View
4 bin/cc-knife
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
require 'cucumber-chef'
-$logger = Cucumber::Chef::Logger.new
-$logger.level = (Cucumber::Chef.is_rc? ? Cucumber::Chef::Logger::DEBUG : Cucumber::Chef::Logger::INFO)
+$logger = ZTK::Logger.new(Cucumber::Chef.log_file)
+Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
# if we have bundler binstubs use that; otherwise attempt to detect
knife = (Cucumber::Chef.locate(:file, "bin", "knife") rescue nil)
View
4 bin/cucumber-chef
@@ -57,8 +57,8 @@ class CucumberChef < Thor
exit(255)
end
- $logger = Cucumber::Chef::Logger.new
- Cucumber::Chef.is_rc? and ($logger.level = Cucumber::Chef::Logger::DEBUG)
+ $logger = ZTK::Logger.new(Cucumber::Chef.log_file)
+ Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
message = "cucumber-chef v#{Cucumber::Chef::VERSION}"
puts(set_color(message, :green, true))
View
4 bin/push-cucumber-chef
@@ -6,8 +6,8 @@ def run(command)
@ssh.exec(command)
end
-$logger = Cucumber::Chef::Logger.new
-$logger.level = (Cucumber::Chef.is_rc? ? Cucumber::Chef::Logger::DEBUG : Cucumber::Chef::Logger::INFO)
+$logger = ZTK::Logger.new(Cucumber::Chef.log_file)
+Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
message = "push-cucumber-chef v#{Cucumber::Chef::VERSION}"
puts(message)
View
90 lib/cucumber/chef/logger.rb
@@ -1,90 +0,0 @@
-################################################################################
-#
-# Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
-# Author: Zachary Patten <zachary@jovelabs.com>
-# Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
-# License: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-################################################################################
-
-
-module Cucumber
- module Chef
-
- class LoggerError < Error; end
-
- class Logger < ::Logger
-
- SEVERITIES = Severity.constants.inject([]) {|arr,c| arr[Severity.const_get(c)] = c; arr}
-
-################################################################################
-
- 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
-
-################################################################################
-
- 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
-
-################################################################################
-
- def add(severity, message = 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?)
- message = [message, progname, msg].delete_if{|i| i == nil}.join(": ")
- message = "%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, message]
-
- @logdev.write(message)
-
- true
- end
-
-################################################################################
-
- def set_log_level(level="INFO")
- log_level = (ENV['LOG_LEVEL'] || level)
- self.level = Cucumber::Chef::Logger.const_get(log_level.to_s.upcase)
- end
-
-################################################################################
-
- end
-
- end
-end
-
-################################################################################
View
5 lib/cucumber/chef/templates/cucumber/env.rb
@@ -14,8 +14,9 @@ class CustomWorld
################################################################################
-$logger = Cucumber::Chef::Logger.new
-Cucumber::Chef.is_rc? and ($logger.level = Cucumber::Chef::Logger::DEBUG)
+# $logger = ZTK::Logger.new(Cucumber::Chef.log_file)
+$logger = ZTK::Logger.new(Cucumber::Chef.log_file)
+Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
message = "cucumber-chef v#{Cucumber::Chef::VERSION}"
print(" * #{message}")
View
6 lib/cucumber/chef/utility.rb
@@ -130,6 +130,12 @@ def external_ip
%x( wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' ).chomp
end
+ def log_file
+ config_path = File.join(Cucumber::Chef.locate_parent(".chef"), ".cucumber-chef")
+ FileUtils.mkdir_p(config_path)
+ File.join(config_path, "cucumber-chef.log")
+ end
+
################################################################################
end
View
2  spec/spec_helper.rb
@@ -22,7 +22,7 @@
require 'cucumber-chef'
dev_null = File.open("/dev/null", "w")
-$logger = Cucumber::Chef::Logger.new(dev_null)
+$logger = ZTK::Logger.new(dev_null)
require 'simplecov'
SimpleCov.start do
Please sign in to comment.
Something went wrong with that request. Please try again.