Class: Vedeu::Logging::Log
- Inherits:
-
Object
- Object
- Vedeu::Logging::Log
- Defined in:
- lib/vedeu/logging/log.rb
Overview
Provides the ability to log anything to the Vedeu log file.
Class Method Summary collapse
- .colours(type) ⇒ Array<Symbol> private
-
.formatted_message(message) ⇒ String
private
-
.log(message:, type: :info) ⇒ String
Write a message to the Vedeu log file.
-
.log_entry(type, message) ⇒ String
private
Returns the message:.
- .log_message(type, message) ⇒ String private
-
.log_stderr(message:, type: :error) ⇒ String
-
.log_stdout(message:, type: :info) ⇒ String
- .log_type(type) ⇒ String private
- .logger ⇒ Boolean private
-
.timestamp ⇒ String
(also: log_timestamp)
Class Method Details
.colours(type) ⇒ Array<Symbol> (private)
120 121 122 |
# File 'lib/vedeu/logging/log.rb', line 120 def colours(type) Vedeu::LOG_TYPES.fetch(type, [:default, :default]) end |
.formatted_message(message) ⇒ String (private)
90 91 92 |
# File 'lib/vedeu/logging/log.rb', line 90 def () "#{timestamp}#{message}\n" if end |
.log(message:, type: :info) ⇒ String
Write a message to the Vedeu log file.
30 31 32 33 34 35 36 |
# File 'lib/vedeu/logging/log.rb', line 30 def log(message:, type: :info) if Vedeu.config.loggable?(type) output = log_entry(type, ) logger.debug(output) output end end |
.log_entry(type, message) ⇒ String (private)
Returns the message:
[type]
101 102 103 |
# File 'lib/vedeu/logging/log.rb', line 101 def log_entry(type, ) log_type(type) + (type, ) end |
.log_message(type, message) ⇒ String (private)
114 115 116 |
# File 'lib/vedeu/logging/log.rb', line 114 def (type, ) Vedeu.esc.colour(colours(type)[1]) { } end |
.log_stderr(message:, type: :error) ⇒ String
54 55 56 57 58 |
# File 'lib/vedeu/logging/log.rb', line 54 def log_stderr(message:, type: :error) log(message: , type: type) $stderr.puts log_entry(type, ) end |
.log_stdout(message:, type: :info) ⇒ String
43 44 45 46 47 |
# File 'lib/vedeu/logging/log.rb', line 43 def log_stdout(message:, type: :info) log(message: , type: type) $stdout.puts log_entry(type, ) end |
.log_type(type) ⇒ String (private)
107 108 109 |
# File 'lib/vedeu/logging/log.rb', line 107 def log_type(type) Vedeu.esc.colour(colours(type)[0]) { "[#{type}]".ljust(11) } end |
.logger ⇒ Boolean (private)
79 80 81 82 83 84 85 |
# File 'lib/vedeu/logging/log.rb', line 79 def logger MonoLogger.new(Vedeu.config.log).tap do |log| log.formatter = proc do |_, _, _, | () end end end |
.timestamp ⇒ String Also known as: log_timestamp
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/logging/log.rb', line 62 def @now = Vedeu.clock_time @time ||= 0.0 @last ||= @now unless @last == @time @time += (@now - @last).round(4) @last = @now end "[#{format('%7.4f', @time.to_s)}] ".rjust(7) end |