Class: Capistrano::EYLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/eycap/lib/ey_logger.rb

Class Method Summary collapse

Class Method Details

.closeObject



118
119
120
121
122
# File 'lib/eycap/lib/ey_logger.rb', line 118

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_typeObject



98
99
100
# File 'lib/eycap/lib/ey_logger.rb', line 98

def self.deploy_type
  @_deploy_type
end

.failure?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/eycap/lib/ey_logger.rb', line 106

def self.failure?
  !@_success
end

.log(level, message, line_prefix = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/eycap/lib/ey_logger.rb', line 37

def self.log(level, message, 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)]
  message.each 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_pathObject



110
111
112
# File 'lib/eycap/lib/ey_logger.rb', line 110

def self.log_file_path
  @_log_file_path
end

.post_processObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/eycap/lib/ey_logger.rb', line 53

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.message << "\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::EYLogger.post_process_hook( "ey_logger:upload_log_to_slice", :any)


89
90
91
92
# File 'lib/eycap/lib/ey_logger.rb', line 89

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_nameObject



114
115
116
# File 'lib/eycap/lib/ey_logger.rb', line 114

def self.remote_log_file_name
  @_log_file_name ||= "#{@_configuration[:release_name]}-#{@_deploy_type}-#{self.successful? ? "SUCCESS" : "FAILURE"}.log"
end

.setup(configuration, deploy_type, options = {}) ⇒ Object

Sets up the EYLogger to beging capturing capistrano’s logging. You should pass the capistrno configuration and the deploy type as a string. The deploy type is for reporting purposes only but must be included.



27
28
29
30
31
32
33
34
35
# File 'lib/eycap/lib/ey_logger.rb', line 27

def self.setup(configuration, deploy_type, options = {})
  @_configuration = configuration
  @_deploy_type = deploy_type.gsub(/:/, "_")
  @_log_path = options[:deploy_log_path] || Dir.tmpdir
  @_log_path << "/" unless @_log_path =~ /\/$/
  FileUtils.mkdir_p(@_log_path)
  @_setup = true
  @_success = true
end

.setup?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/eycap/lib/ey_logger.rb', line 94

def self.setup?
  !!@_setup
end

.successful?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/eycap/lib/ey_logger.rb', line 102

def self.successful?
  !!@_success
end