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 Attribute Summary collapse
-
.count ⇒ Fixnum
private
Used by tests to access the ‘count` instance variable.
Class Method Summary collapse
- .colours(type) ⇒ Array<Symbol> private
-
.formatted_message(message) ⇒ String
private
-
.indent(&block) ⇒ NilClass|void
private
Used by Events::Trigger to indent log messages to show activity which occurs as part of that event triggering.
- .indentation ⇒ 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
-
.outdent(&block) ⇒ void
private
Used by Events::Trigger to outdent log messages to show activity which occurs as part of the previous event triggering.
-
.timestamp ⇒ String
(also: log_timestamp)
Class Attribute Details
.count ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Used by tests to access the ‘count` instance variable.
23 24 25 |
# File 'lib/vedeu/logging/log.rb', line 23 def count @count end |
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)
127 128 129 |
# File 'lib/vedeu/logging/log.rb', line 127 def () "#{}#{}\n" if end |
.indent(&block) ⇒ NilClass|void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used by Events::Trigger to indent log messages to show activity which occurs as part of that event triggering.
31 32 33 34 35 36 37 38 |
# File 'lib/vedeu/logging/log.rb', line 31 def indent(&block) @count ||= 0 @count += 1 yield if block_given? ensure outdent end |
.indentation ⇒ String (private)
132 133 134 |
# File 'lib/vedeu/logging/log.rb', line 132 def indentation ' ' * (@count ||= 0) * 2 end |
.log(message:, type: :info) ⇒ String
Write a message to the Vedeu log file.
51 52 53 54 55 56 57 |
# File 'lib/vedeu/logging/log.rb', line 51 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] message
143 144 145 |
# File 'lib/vedeu/logging/log.rb', line 143 def log_entry(type, ) log_type(type) + (type, ) end |
.log_message(type, message) ⇒ String (private)
156 157 158 |
# File 'lib/vedeu/logging/log.rb', line 156 def (type, ) Vedeu.esc.colour(colours(type)[1]) { indentation + } end |
.log_stderr(message:, type: :error) ⇒ String
75 76 77 78 79 |
# File 'lib/vedeu/logging/log.rb', line 75 def log_stderr(message:, type: :error) log(message: , type: type) $stderr.puts log_entry(type, ) end |
.log_stdout(message:, type: :info) ⇒ String
64 65 66 67 68 |
# File 'lib/vedeu/logging/log.rb', line 64 def log_stdout(message:, type: :info) log(message: , type: type) $stdout.puts log_entry(type, ) end |
.log_type(type) ⇒ String (private)
149 150 151 |
# File 'lib/vedeu/logging/log.rb', line 149 def log_type(type) Vedeu.esc.colour(colours(type)[0]) { "[#{type}]".ljust(11) } end |
.logger ⇒ Boolean (private)
161 162 163 164 165 166 167 |
# File 'lib/vedeu/logging/log.rb', line 161 def logger MonoLogger.new(Vedeu.config.log).tap do |log| log.formatter = proc do |_, _, _, | () end end end |
.outdent(&block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Used by Events::Trigger to outdent log messages to show activity which occurs as part of the previous event triggering.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vedeu/logging/log.rb', line 88 def outdent(&block) result = yield if block_given? if @count && @count > 0 @count -= 1 else @count = 0 end result end |
.timestamp ⇒ String Also known as: log_timestamp
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vedeu/logging/log.rb', line 102 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 |