Class: RedmineInstaller::Logger
- Defined in:
- lib/redmine-installer/logger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #error(*messages) ⇒ Object
- #finish ⇒ Object
- #info(*messages) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #log(severity, *messages) ⇒ Object
- #move_to(redmine, suffix: '%d%m%Y_%H%M%S') ⇒ Object
- #path ⇒ Object
- #std(*messages) ⇒ Object
- #warn(*messages) ⇒ Object
Constructor Details
#initialize ⇒ Logger
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
#close ⇒ Object
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(*) log('ERROR', *) end |
#finish ⇒ Object
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(*) log(' INFO', *) end |
#log(severity, *messages) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/redmine-installer/logger.rb', line 74 def log(severity, *) .each do || @output.puts("#{severity}: #{}") 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 |
#path ⇒ Object
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(*) log(' STD', *) end |
#warn(*messages) ⇒ Object
66 67 68 |
# File 'lib/redmine-installer/logger.rb', line 66 def warn(*) log(' WARN', *) end |