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
# 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



58
59
60
61
62
63
64
65
# File 'lib/irgat/log.rb', line 58

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/irgat/log.rb', line 41

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] }"

  exist_or_create_folder(log_file_folder)

  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