Class: CliApplication::Log::File

Inherits:
Base
  • Object
show all
Defined in:
lib/cli_application/log/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#set_exception

Constructor Details

#initialize(app, log, class_folder) ⇒ File

Returns a new instance of File.



7
8
9
10
11
12
# File 'lib/cli_application/log/file.rb', line 7

def initialize(app, log, class_folder)
  @app = app
  @log = log
  @class_folder = class_folder
  init_log
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/cli_application/log/file.rb', line 5

def filename
  @filename
end

#folderObject (readonly)

Returns the value of attribute folder.



4
5
6
# File 'lib/cli_application/log/file.rb', line 4

def folder
  @folder
end

Instance Method Details

#log(message) ⇒ Object



38
39
40
41
# File 'lib/cli_application/log/file.rb', line 38

def log(message)
  ::File.open(@filename, 'a') {|f| f.write message + "\n" }
  ::File.chmod(0777, @filename)
end

#save_app_finish_informationObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/cli_application/log/file.rb', line 27

def save_app_finish_information
  log(I18n.t('config.log_section.finish_header'))
  unless @exception.nil?
    log(@exception.message)
    log(@exception.backtrace.join("\n"))
  end
  log(I18n.t('config.log_section.app_executed_at', time: Time.zone.now, executed_at: @app.executed_at.round(3)))
  log(I18n.t('config.log_section.app_memory', value: StTools::Human.memory))
  log(I18n.t('config.log_section.app_exitcode', exitcode: @app.exitcode, status: ((@app.exitcode == 0 ? 'SUCCESS' : 'FAIL'))))
end

#save_app_run_informationObject



22
23
24
25
# File 'lib/cli_application/log/file.rb', line 22

def save_app_run_information
  log(I18n.t('config.log_section.run_header'))
  log("")
end

#save_app_start_informationObject



14
15
16
17
18
19
20
# File 'lib/cli_application/log/file.rb', line 14

def save_app_start_information
  log(I18n.t('config.log_section.start_header'))
  log(I18n.t('config.log_section.app_name', name: $PROGRAM_NAME))
  log(I18n.t('config.log_section.app_script_name', name: ::File.basename($PROGRAM_NAME)))
  log(I18n.t('config.log_section.app_started_at', time: Time.zone.now))
  log("")
end