Class: Capistrano::CampoutLogger
- Inherits:
-
Object
- Object
- Capistrano::CampoutLogger
- Defined in:
- lib/capistrano-campout/logger.rb
Class Method Summary collapse
- .close ⇒ Object
- .deploy_type ⇒ Object
- .failure? ⇒ Boolean
- .log(level, message, line_prefix = nil) ⇒ Object
- .log_file_path ⇒ Object
- .post_process ⇒ Object
-
.post_process_hook(task, key = :any) ⇒ Object
Adds a post processing hook.
- .remote_log_file_name ⇒ Object
-
.setup(configuration, options = {}) ⇒ Object
Sets up the CampoutLogger to begin capturing capistrano’s logging.
- .setup? ⇒ Boolean
- .successful? ⇒ Boolean
Class Method Details
.close ⇒ Object
120 121 122 123 124 |
# File 'lib/capistrano-campout/logger.rb', line 120 def self.close @_deploy_log_file.flush unless @_deploy_log_file.nil? @_deploy_log_file.close unless @_deploy_log_file.nil? @_setup = false end |
.deploy_type ⇒ Object
100 101 102 |
# File 'lib/capistrano-campout/logger.rb', line 100 def self.deploy_type @_deploy_type end |
.failure? ⇒ Boolean
108 109 110 |
# File 'lib/capistrano-campout/logger.rb', line 108 def self.failure? !@_success end |
.log(level, message, line_prefix = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/capistrano-campout/logger.rb', line 39 def self.log(level, , line_prefix=nil) return nil unless setup? @release_name = @_configuration[:release_name] if @release_name.nil? @_log_file_path = @_log_path + @release_name + ".log" unless @_log_file_path @_deploy_log_file = File.open(@_log_file_path, "w") if @_deploy_log_file.nil? indent = "%*s" % [Logger::MAX_LEVEL, "*" * (Logger::MAX_LEVEL - level)] .each_line do |line| if line_prefix @_deploy_log_file << "#{indent} [#{line_prefix}] #{line.strip}\n" else @_deploy_log_file << "#{indent} #{line.strip}\n" end end end |
.log_file_path ⇒ Object
112 113 114 |
# File 'lib/capistrano-campout/logger.rb', line 112 def self.log_file_path @_log_file_path end |
.post_process ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/capistrano-campout/logger.rb', line 55 def self.post_process unless ::Interrupt === $! puts "\n\nPlease wait while the log file is processed\n" # Should dump the stack trace of an exception if there is one error = $! unless error.nil? @_deploy_log_file << error. << "\n" @_deploy_log_file << error.backtrace.join("\n") @_success = false end self.close hooks = [:any] hooks << (self.successful? ? :success : :failure) puts "Executing Post Processing Hooks" hooks.each do |h| @_post_process_hooks[h].each do |key| @_configuration.parent.find_and_execute_task(key) end end puts "Finished Post Processing Hooks" end end |
.post_process_hook(task, key = :any) ⇒ Object
Adds a post processing hook.
Provide a task name to execute. These tasks are executed after capistrano has actually run its course.
Takes a key to control when the hook is executed.‘ :any - always executed :success - only execute on success :failure - only execute on failure
Example
Capistrano::CampoutLogger.post_process_hook( "campout:post_log", :any)
91 92 93 94 |
# File 'lib/capistrano-campout/logger.rb', line 91 def self.post_process_hook(task, key = :any) @_post_process_hooks ||= Hash.new{|h,k| h[k] = []} @_post_process_hooks[key] << task end |
.remote_log_file_name ⇒ Object
116 117 118 |
# File 'lib/capistrano-campout/logger.rb', line 116 def self.remote_log_file_name @_log_file_name ||= "deploy-#{@_configuration[:release_name]}-#{self.successful? ? "success" : "failure"}.log" end |
.setup(configuration, options = {}) ⇒ Object
Sets up the CampoutLogger to begin capturing capistrano’s logging. You should pass the capistrano configuration
30 31 32 33 34 35 36 37 |
# File 'lib/capistrano-campout/logger.rb', line 30 def self.setup(configuration, = {}) @_configuration = configuration @_log_path = [:deploy_log_path] || Dir.tmpdir @_log_path << "/" unless @_log_path =~ /\/$/ FileUtils.mkdir_p(@_log_path) @_setup = true @_success = true end |
.setup? ⇒ Boolean
96 97 98 |
# File 'lib/capistrano-campout/logger.rb', line 96 def self.setup? !!@_setup end |
.successful? ⇒ Boolean
104 105 106 |
# File 'lib/capistrano-campout/logger.rb', line 104 def self.successful? !!@_success end |