Module: Checkup::Logger
- Defined in:
- lib/checkup/logger.rb
Class Attribute Summary collapse
-
.quiet ⇒ Object
Returns the value of attribute quiet.
Class Method Summary collapse
- .clear! ⇒ Object
-
.error(string) ⇒ Object
Outputs an error to the console and writes it to the backup.log Called when an Exception has caused the backup process to abort.
- .has_errors? ⇒ Boolean
-
.has_warnings? ⇒ Boolean
Returns true if any warnings have been issued.
-
.message(string) ⇒ Object
Outputs a messages to the console and writes it to the backup.log.
-
.messages ⇒ Object
Returns an Array of all messages written to the log file for this session.
-
.normal(string) ⇒ Object
Outputs the data as if it were a regular ‘puts’ command, but also logs it to the backup.log.
-
.silent(string) ⇒ Object
Silently logs data to the log file.
- .truncate!(max_bytes = 500_000) ⇒ Object
-
.warn(string) ⇒ Object
Outputs a notice to the console and writes it to the backup.log Sets #has_warnings? true so :on_warning notifications will be sent.
Class Attribute Details
.quiet ⇒ Object
Returns the value of attribute quiet.
7 8 9 |
# File 'lib/checkup/logger.rb', line 7 def quiet @quiet end |
Class Method Details
.clear! ⇒ Object
63 64 65 66 |
# File 'lib/checkup/logger.rb', line 63 def clear! .clear @has_warnings = false end |
.error(string) ⇒ Object
Outputs an error to the console and writes it to the backup.log Called when an Exception has caused the backup process to abort.
19 20 21 22 23 |
# File 'lib/checkup/logger.rb', line 19 def error(string) @has_errors = true to_console loggify(string, :error, :red), true to_file loggify(string, :error) end |
.has_errors? ⇒ Boolean
53 54 55 |
# File 'lib/checkup/logger.rb', line 53 def has_errors? @has_errors ||= false end |
.has_warnings? ⇒ Boolean
Returns true if any warnings have been issued
59 60 61 |
# File 'lib/checkup/logger.rb', line 59 def has_warnings? @has_warnings ||= false end |
.message(string) ⇒ Object
Outputs a messages to the console and writes it to the backup.log
11 12 13 14 |
# File 'lib/checkup/logger.rb', line 11 def (string) to_console loggify(string, :message, :green) to_file loggify(string, :message) end |
.messages ⇒ Object
Returns an Array of all messages written to the log file for this session
49 50 51 |
# File 'lib/checkup/logger.rb', line 49 def @messages ||= [] end |
.normal(string) ⇒ Object
Outputs the data as if it were a regular ‘puts’ command, but also logs it to the backup.log
36 37 38 39 |
# File 'lib/checkup/logger.rb', line 36 def normal(string) to_console loggify(string) to_file loggify(string) end |
.silent(string) ⇒ Object
Silently logs data to the log file
43 44 45 |
# File 'lib/checkup/logger.rb', line 43 def silent(string) to_file loggify(string, :silent) end |
.truncate!(max_bytes = 500_000) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/checkup/logger.rb', line 68 def truncate!(max_bytes = 500_000) log_file = File.join(Config.log_path, 'checkup.log') return unless File.exist?(log_file) if File.stat(log_file).size > max_bytes FileUtils.mv(log_file, log_file + '~') File.open(log_file + '~', 'r') do |io_in| File.open(log_file, 'w') do |io_out| io_in.seek(-max_bytes, IO::SEEK_END) && io_in.gets while line = io_in.gets io_out.puts line end end end FileUtils.rm_f(log_file + '~') end end |
.warn(string) ⇒ Object
Outputs a notice to the console and writes it to the backup.log Sets #has_warnings? true so :on_warning notifications will be sent
28 29 30 31 32 |
# File 'lib/checkup/logger.rb', line 28 def warn(string) @has_warnings = true to_console loggify(string, :warning, :yellow), true to_file loggify(string, :warning) end |