Class: Gloo::App::Log
- Inherits:
-
Object
- Object
- Gloo::App::Log
- Defined in:
- lib/gloo/app/log.rb
Constant Summary collapse
- DEBUG =
'debug'.freeze
- INFO =
'info'.freeze
- WARN =
'warn'.freeze
- ERROR =
'error'.freeze
- LEVELS =
[ DEBUG, INFO, WARN, ERROR ].freeze
- CLEARED =
"\n\n --- Log files cleared. --- \n\n".freeze
- LOG_FILE =
'gloo.log'.freeze
- ERROR_FILE =
'error.log'.freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
Class Method Summary collapse
-
.is_level?(str) ⇒ Boolean
Does the given str represent a logging level?.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the log files.
-
#create_loggers ⇒ Object
Create the default [file] logger.
-
#debug(msg) ⇒ Object
Write a debug message to the log.
-
#err_file ⇒ Object
Get the error log file.
-
#error(msg, ex = nil, engine = nil) ⇒ Object
Write an error message to the log and set the error in the engine's data heap.
-
#info(msg) ⇒ Object
Write an information message to the log.
-
#initialize(engine, quiet = true) ⇒ Log
constructor
Set up a logger.
-
#log_file ⇒ Object
Get the log file.
-
#show(msg, color = nil) ⇒ Object
Show a message unless we're in quite mode.
-
#warn(msg) ⇒ Object
Write a warning message to the log.
-
#write(msg, level) ⇒ Object
Write to the specified level.
Constructor Details
#initialize(engine, quiet = true) ⇒ Log
Set up a logger. If quiet is true, then message are written to the log but not to the console.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gloo/app/log.rb', line 37 def initialize( engine, quiet = true ) @engine = engine @quiet = quiet @debug = engine.settings.debug @theme = engine.theme create_loggers debug 'log intialized...' end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
26 27 28 |
# File 'lib/gloo/app/log.rb', line 26 def logger @logger end |
#quiet ⇒ Object
Returns the value of attribute quiet.
25 26 27 |
# File 'lib/gloo/app/log.rb', line 25 def quiet @quiet end |
Class Method Details
.is_level?(str) ⇒ Boolean
Does the given str represent a logging level?
84 85 86 87 88 |
# File 'lib/gloo/app/log.rb', line 84 def self.is_level?( str ) return false unless str.is_a? String return LEVELS.include? str.strip.downcase end |
Instance Method Details
#clear ⇒ Object
Clear the log files.
97 98 99 100 101 102 |
# File 'lib/gloo/app/log.rb', line 97 def clear File.write( log_file, CLEARED ) File.write( err_file, CLEARED ) create_loggers end |
#create_loggers ⇒ Object
Create the default [file] logger.
51 52 53 54 55 56 57 |
# File 'lib/gloo/app/log.rb', line 51 def create_loggers @logger = Logger.new( log_file ) @logger.level = Logger::DEBUG @error = Logger.new( err_file ) @error.level = Logger::WARN end |
#debug(msg) ⇒ Object
Write a debug message to the log.
143 144 145 146 147 |
# File 'lib/gloo/app/log.rb', line 143 def debug( msg ) return unless @debug @logger.debug msg end |
#err_file ⇒ Object
Get the error log file.
73 74 75 |
# File 'lib/gloo/app/log.rb', line 73 def err_file return File.join( @engine.settings.log_path, ERROR_FILE ) end |
#error(msg, ex = nil, engine = nil) ⇒ Object
Write an error message to the log and set the error in the engine's data heap. Also write to the console unless quiet.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/gloo/app/log.rb', line 172 def error( msg, ex = nil, engine = nil ) engine&.heap&.error&.set_to( msg ) if engine @logger.error msg @error.error msg if ex @error.error ex. @error.error ex.backtrace puts @theme.error( msg ) unless @quiet puts @theme.error( ex. ) unless @quiet puts ex.backtrace unless @quiet else puts @theme.error( msg ) unless @quiet end end |
#info(msg) ⇒ Object
Write an information message to the log.
152 153 154 155 |
# File 'lib/gloo/app/log.rb', line 152 def info( msg ) @logger.info msg # puts msg.blue unless @quiet end |
#log_file ⇒ Object
Get the log file.
66 67 68 |
# File 'lib/gloo/app/log.rb', line 66 def log_file return File.join( @engine.settings.log_path, LOG_FILE ) end |
#show(msg, color = nil) ⇒ Object
Show a message unless we're in quite mode.
111 112 113 114 115 116 117 118 119 |
# File 'lib/gloo/app/log.rb', line 111 def show( msg, color = nil ) return if @quiet if color puts ColorizedString[ msg ].colorize( color.to_sym ) else puts msg end end |
#warn(msg) ⇒ Object
Write a warning message to the log. Also write to the console unless quiet.
161 162 163 164 165 |
# File 'lib/gloo/app/log.rb', line 161 def warn( msg ) @logger.warn msg @error.warn msg puts @theme.warn( msg ) unless @quiet end |