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
Returns the value of attribute quiet.
Instance Method Summary collapse
-
#create_logger ⇒ Object
Create the default [file] logger.
-
#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(engine, quiet = true) ⇒ Log
constructor
Set up a logger.
-
#prep_serialize ⇒ Object
Prepare for serialization by removing the file reference.
-
#restore_after_deserialization ⇒ Object
Restore the logger after deserialization.
-
#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(engine, quiet = true) ⇒ Log
Set up a logger. If quiet is true, then message are written to the log but not to the console.
26 27 28 29 30 31 32 33 34 |
# File 'lib/gloo/app/log.rb', line 26 def initialize( engine, quiet=true ) @engine = engine @quite = quiet @debug = engine.settings.debug create_logger debug 'log intialized...' end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/gloo/app/log.rb', line 15 def logger @logger end |
#quiet ⇒ Object
Returns the value of attribute quiet.
14 15 16 |
# File 'lib/gloo/app/log.rb', line 14 def quiet @quiet end |
Instance Method Details
#create_logger ⇒ Object
Create the default [file] logger.
39 40 41 42 43 |
# File 'lib/gloo/app/log.rb', line 39 def create_logger f = File.join( @engine.settings.log_path, 'gloo.log' ) @logger = Logger.new( f ) @logger.level = Logger::DEBUG end |
#debug(msg) ⇒ Object
Write a debug message to the log.
63 64 65 66 67 |
# File 'lib/gloo/app/log.rb', line 63 def debug( msg ) return unless @debug @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.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gloo/app/log.rb', line 93 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.
74 75 76 77 |
# File 'lib/gloo/app/log.rb', line 74 def info( msg ) @logger.info msg puts msg.blue unless @quiet end |
#prep_serialize ⇒ Object
Prepare for serialization by removing the file reference. Without this, the engine cannot be serialized.
115 116 117 |
# File 'lib/gloo/app/log.rb', line 115 def prep_serialize @logger = nil end |
#restore_after_deserialization ⇒ Object
Restore the logger after deserialization.
122 123 124 |
# File 'lib/gloo/app/log.rb', line 122 def restore_after_deserialization create_logger end |
#show(msg) ⇒ Object
Show a message unless we’re in quite mode.
52 53 54 |
# File 'lib/gloo/app/log.rb', line 52 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.
83 84 85 86 |
# File 'lib/gloo/app/log.rb', line 83 def warn( msg ) @logger.warn msg puts msg.yellow unless @quiet end |