lib/calabash-cucumber/logging.rb in calabash-cucumber-0.17.0 vs lib/calabash-cucumber/logging.rb in calabash-cucumber-0.17.1
- old
+ new
@@ -1,8 +1,10 @@
module Calabash
module Cucumber
+ require "fileutils"
require "run_loop"
+ require "calabash-cucumber/dot_dir"
# These methods are not part of the API.
#
# They may change at any time.
@@ -30,10 +32,34 @@
# red
def self.log_error(msg)
puts self.red("ERROR: #{msg}") if msg
end
+ # !@visibility private
+ def self.log_to_file(message)
+ timestamp = self.timestamp
+
+ begin
+ File.open(self.calabash_log_file, "a:UTF-8") do |file|
+ message.split($-0).each do |line|
+ file.write("#{timestamp} #{line}#{$-0}")
+ end
+ end
+ rescue => e
+ message =
+%Q{Could not write:
+
+#{message}
+
+to calabash.log because:
+
+#{e}
+}
+ self.log_debug(message)
+ end
+ end
+
private
# @!visibility private
def self.windows_env?
RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
@@ -71,9 +97,30 @@
end
# @!visibility private
def self.green(string)
colorize(string, 32)
+ end
+
+ # @!visibility private
+ def self.timestamp
+ Time.now.strftime("%Y-%m-%d_%H-%M-%S")
+ end
+
+ # @!visibility private
+ def self.logs_directory
+ path = File.join(Calabash::Cucumber::DotDir.directory, "logs")
+ FileUtils.mkdir_p(path)
+ path
+ end
+
+ # @!visibility private
+ def self.calabash_log_file
+ path = File.join(self.logs_directory, "calabash.log")
+ if !File.exist?(path)
+ FileUtils.touch(path)
+ end
+ path
end
end
end