Module: Irgat::Log

Included in:
Irgat
Defined in:
lib/irgat/log.rb

Instance Method Summary collapse

Instance Method Details

#log(output_type, message, debug = nil) ⇒ Object

Store the output messages in a class array variable



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/irgat/log.rb', line 7

def log(output_type, message, debug = nil)
  @log_process ||= Array.new
  # add new hash to point variable
  log_point = Hash.new
  log_point[:type]  = output_type
  log_point[:msj]   = message
  log_point[:debug] = debug.to_i || 3  # highter level if not marked
  @log_process << log_point

  # to stodout
  unless @config[:debug_level].to_i < log_point[:debug]
    puts colorize(log_point)
  end
end

#output_log(module_process, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/irgat/log.rb', line 22

def output_log(module_process, options = {})

  fatal = options[:fatal] || false


  # build report
  report = build_report(module_process.log_process)
  resume = build_resume(fatal, module_process)

  # output to email or log file
  if module_process.config_module[:log_file_actions].include?(module_process.action)
    report_to_log(report, module_process)
  end

  if module_process.config_module[:log_file_actions].include?(module_process.action)
    report_to_email(resume, report, options[:main_msj] )
  end

end

#report_to_email(resume, report, subject) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/irgat/log.rb', line 71

def report_to_email(resume, report, subject )
  # body
  if @config[:debug_level] == 3
    resume = resume + "\n\n LOG \n\n" + report
  end

  send_email({ :subject => subject, :body => resume })
end

#report_to_log(report, module_process) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/irgat/log.rb', line 42

def report_to_log(report, module_process)
  exist_or_create_folder(@config[:log_path])

  log_file_folder = "#{ @config[:log_path] }/#{ module_process.config_module[:subsystem_name] }"

  # Try to create log folder
  # Debug annotation:
  # we can't use here exist_or_create_folder, because, this function, if fails, report a log.
  # If we can't create a log, and exit_with_error method log the error, irgat goes inside a error bucle :-)
  if ! test(?d,log_file_folder)
  ### FIXME ###
    create_log_folder = execute_command("mkdir #{ log_file_folder }", 
                        "Creating '#{ log_file_folder }'",
                        {:debug => 3 })
#        if create_log_folder[:status]

   # dont_log = false unless 
  end

  log_file = "#{ log_file_folder }/#{ Time.now.strftime("%Y-%m-%d") }_#{ module_process.action }_in_#{ @config[:server_name] }.log"

  if log_out = File.new(log_file,"w+")
    log_out.puts report
    log_out.close
  else
    puts "Unable to open log #{ log_file }. Output won't be wrotten"
  end
end