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
-
.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_stderr(message:, type: :error) ⇒ String
-
.log_stdout(message:, type: :info) ⇒ String
- .logger ⇒ Boolean private
-
.timestamp ⇒ String
(also: log_timestamp)
Class Method Details
.formatted_message(message) ⇒ String (private)
91 92 93 |
# File 'lib/vedeu/logging/log.rb', line 91 def () "#{}#{}\n" if end |
.log(message:, type: :info) ⇒ String
Write a message to the Vedeu log file.
31 32 33 34 35 36 37 |
# File 'lib/vedeu/logging/log.rb', line 31 def log(message:, type: :info) if Vedeu.config.log? && Vedeu.config.loggable?(type) output = log_entry(type, ) logger.debug(output) output end end |
.log_entry(type, message) ⇒ String (private)
Returns the message:
[type] message
102 103 104 105 106 107 108 109 |
# File 'lib/vedeu/logging/log.rb', line 102 def log_entry(type, ) colours = Vedeu.config.log_types.fetch(type, [:default, :default]) [ Vedeu.esc.colour(colours[0]) { "[#{type}]".ljust(11) }, Vedeu.esc.colour(colours[1]) { }, ].join end |
.log_stderr(message:, type: :error) ⇒ String
55 56 57 58 59 |
# File 'lib/vedeu/logging/log.rb', line 55 def log_stderr(message:, type: :error) log(message: , type: type) $stderr.puts log_entry(type, ) end |
.log_stdout(message:, type: :info) ⇒ String
44 45 46 47 48 |
# File 'lib/vedeu/logging/log.rb', line 44 def log_stdout(message:, type: :info) log(message: , type: type) $stdout.puts log_entry(type, ) end |
.logger ⇒ Boolean (private)
80 81 82 83 84 85 86 |
# File 'lib/vedeu/logging/log.rb', line 80 def logger MonoLogger.new(Vedeu.config.log).tap do |log| log.formatter = proc do |_, _, _, | () end end end |
.timestamp ⇒ String Also known as: log_timestamp
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/logging/log.rb', line 63 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 |