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
Returns the message with timestamp.
-
.log(message:, force: false, type: :info) ⇒ String
Write a message to the Vedeu log file.
-
.log_entry(type, message) ⇒ String
private
Returns the message:.
-
.log_stderr(type: :info, message:) ⇒ String
Write a message to STDERR.
-
.log_stdout(type: :info, message:) ⇒ String
Write a message to STDOUT.
- .logger ⇒ Boolean private
-
.message_types ⇒ Hash<Symbol => Array<Symbol>>
private
The defined message types for Vedeu with their respective colours.
-
.timestamp ⇒ String
(also: log_timestamp)
Returns a formatted timestamp.
Class Method Details
.formatted_message(message) ⇒ String (private)
Returns the message with timestamp.
[ 0.0987] [debug] Something happened.
92 93 94 |
# File 'lib/vedeu/logging/log.rb', line 92 def () "#{timestamp}#{message}\n" if end |
.log(message:, force: false, type: :info) ⇒ String
Write a message to the Vedeu log file.
28 29 30 31 32 33 34 |
# File 'lib/vedeu/logging/log.rb', line 28 def log(message:, force: false, type: :info) if (Vedeu.config.log? || force) && Vedeu.config.loggable?(type) output = log_entry(type, ) logger.debug(output) output end end |
.log_entry(type, message) ⇒ String (private)
Returns the message:
[type]
104 105 106 107 108 109 110 111 |
# File 'lib/vedeu/logging/log.rb', line 104 def log_entry(type, ) colours = .fetch(type, [:default, :default]) [ Vedeu.esc.colour(colours[0]) { "[#{type}]".ljust(11) }, Vedeu.esc.colour(colours[1]) { }, ].join end |
.log_stderr(type: :info, message:) ⇒ String
Write a message to STDERR.
52 53 54 |
# File 'lib/vedeu/logging/log.rb', line 52 def log_stderr(type: :info, message:) $stderr.puts log_entry(type, ) end |
.log_stdout(type: :info, message:) ⇒ String
Write a message to STDOUT.
42 43 44 |
# File 'lib/vedeu/logging/log.rb', line 42 def log_stdout(type: :info, message:) $stdout.puts log_entry(type, ) end |
.logger ⇒ Boolean (private)
77 78 79 80 81 82 83 |
# File 'lib/vedeu/logging/log.rb', line 77 def logger MonoLogger.new(Vedeu.config.log).tap do |log| log.formatter = proc do |_, _, _, | () end end end |
.message_types ⇒ Hash<Symbol => Array<Symbol>> (private)
The defined message types for Vedeu with their respective colours. When used, produces a log entry of the format:
[type]
The ‘type’ will be shown as the first colour defined in the value array, whilst the ‘message’ will be shown using the last colour.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/vedeu/logging/log.rb', line 123 def { create: [:light_cyan, :cyan], store: [:light_cyan, :cyan], update: [:light_cyan, :cyan], reset: [:light_cyan, :cyan], event: [:light_magenta, :magenta], timer: [:light_blue, :blue], info: [:white, :light_grey], test: [:white, :light_grey], debug: [:white, :light_grey], compress: [:white, :light_grey], input: [:light_yellow, :yellow], output: [:light_yellow, :yellow], cursor: [:light_green, :green], buffer: [:light_green, :green], render: [:light_green, :green], error: [:light_red, :red], config: [:light_blue, :blue], dsl: [:light_blue, :blue], editor: [:light_blue, :blue], drb: [:light_blue, :blue], blue: [:light_blue, :blue], cyan: [:light_cyan, :cyan], green: [:light_green, :green], magenta: [:light_magenta, :magenta], red: [:light_red, :red], white: [:white, :light_grey], yellow: [:light_yellow, :yellow], } end |
.timestamp ⇒ String Also known as: log_timestamp
Returns a formatted timestamp. eg. [137.7824]
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vedeu/logging/log.rb', line 60 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 |