Class: Gloo::App::Log
- Inherits:
-
Object
- Object
- Gloo::App::Log
- Defined in:
- lib/gloo/app/log.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#quiet ⇒ Object
readonly
Returns the value of attribute quiet.
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
Write a debug message to the log.
-
#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(quiet) ⇒ Log
constructor
Set up a logger.
-
#show(msg) ⇒ Object
Show a message unless we’re in quite mode.
-
#warn(msg) ⇒ Object
Write a warning message to the log.
Constructor Details
#initialize(quiet) ⇒ Log
Set up a logger. If quiet is true, then message are written to the log but not to the console.
21 22 23 24 25 26 |
# File 'lib/gloo/app/log.rb', line 21 def initialize( quiet ) f = File.join( $settings.log_path, 'gloo.log' ) @logger = Logger.new( f ) @logger.level = Logger::DEBUG @quiet = quiet end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/gloo/app/log.rb', line 14 def logger @logger end |
#quiet ⇒ Object (readonly)
Returns the value of attribute quiet.
14 15 16 |
# File 'lib/gloo/app/log.rb', line 14 def quiet @quiet end |
Instance Method Details
#debug(msg) ⇒ Object
Write a debug message to the log.
38 39 40 |
# File 'lib/gloo/app/log.rb', line 38 def debug( msg ) @logger.debug msg 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gloo/app/log.rb', line 65 def error( msg, ex = nil, engine = nil ) engine&.heap&.error&.set_to msg @logger.error msg if ex @logger.error ex. @logger.error ex.backtrace puts msg.red unless @quiet puts ex..red unless @quiet puts ex.backtrace unless @quiet else puts msg.red unless @quiet end end |
#info(msg) ⇒ Object
Write an information message to the log. Also write to the console unless quiet.
46 47 48 49 |
# File 'lib/gloo/app/log.rb', line 46 def info( msg ) @logger.info msg puts msg.blue unless @quiet end |
#show(msg) ⇒ Object
Show a message unless we’re in quite mode.
31 32 33 |
# File 'lib/gloo/app/log.rb', line 31 def show( msg ) puts msg unless @quiet end |
#warn(msg) ⇒ Object
Write a warning message to the log. Also write to the console unless quiet.
55 56 57 58 |
# File 'lib/gloo/app/log.rb', line 55 def warn( msg ) @logger.warn msg puts msg.yellow unless @quiet end |