Class: RedmineInstaller::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine-installer/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



25
26
27
28
29
30
31
# File 'lib/redmine-installer/logger.rb', line 25

def initialize
  if ENV['REDMINE_INSTALLER_LOGFILE']
    @output = File.open(ENV['REDMINE_INSTALLER_LOGFILE'], 'w')
  else
    @output = Tempfile.create('redmine_installer.log')
  end
end

Class Method Details

.verify(log_file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/redmine-installer/logger.rb', line 6

def self.verify(log_file)
  log_file = log_file.to_s

  unless File.exist?(log_file)
    puts "File '#{log_file}' does not exist."
    exit(false)
  end

  content = File.open(log_file, &:to_a)
  digest1 = content.pop
  digest2 = Digest::SHA256.hexdigest(content.join)

  if digest1 == digest2
    puts RedmineInstaller.pastel.green("Logfile is OK. Digest verified.")
  else
    puts RedmineInstaller.pastel.red("Logfile is not OK. Digest wasn't verified.")
  end
end

Instance Method Details

#closeObject



43
44
45
46
# File 'lib/redmine-installer/logger.rb', line 43

def close
  @output.flush
  @output.close
end

#error(*messages) ⇒ Object



62
63
64
# File 'lib/redmine-installer/logger.rb', line 62

def error(*messages)
  log('ERROR', *messages)
end

#finishObject



37
38
39
40
41
# File 'lib/redmine-installer/logger.rb', line 37

def finish
  close
  digest = Digest::SHA256.file(path).hexdigest
  File.open(path, 'a') { |f| f.write(digest) }
end

#info(*messages) ⇒ Object



58
59
60
# File 'lib/redmine-installer/logger.rb', line 58

def info(*messages)
  log(' INFO', *messages)
end

#log(severity, *messages) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/redmine-installer/logger.rb', line 74

def log(severity, *messages)
  messages.each do |message|
    @output.puts("#{severity}: #{message}")
  end

  @output.flush
end

#move_to(redmine, suffix: '%d%m%Y_%H%M%S') ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/redmine-installer/logger.rb', line 48

def move_to(redmine, suffix: '%d%m%Y_%H%M%S')
  close

  new_path = File.join(redmine.log_path, Time.now.strftime("redmine_installer_#{suffix}.log"))

  FileUtils.mkdir_p(redmine.log_path)
  FileUtils.mv(path, new_path)
  @output = File.open(new_path, 'a+')
end

#pathObject



33
34
35
# File 'lib/redmine-installer/logger.rb', line 33

def path
  @output.path
end

#std(*messages) ⇒ Object



70
71
72
# File 'lib/redmine-installer/logger.rb', line 70

def std(*messages)
  log('  STD', *messages)
end

#warn(*messages) ⇒ Object



66
67
68
# File 'lib/redmine-installer/logger.rb', line 66

def warn(*messages)
  log(' WARN', *messages)
end