Class: GlooLang::App::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/app/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



24
25
26
27
28
29
30
31
# File 'lib/gloo_lang/app/log.rb', line 24

def initialize( engine, quiet=true )
  @engine = engine
  @quite = quiet

  create_logger

  debug 'log intialized...'
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/gloo_lang/app/log.rb', line 13

def logger
  @logger
end

#quietObject

Returns the value of attribute quiet.



12
13
14
# File 'lib/gloo_lang/app/log.rb', line 12

def quiet
  @quiet
end

Instance Method Details

#create_loggerObject

Create the default [file] logger.



36
37
38
39
40
# File 'lib/gloo_lang/app/log.rb', line 36

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.



60
61
62
# File 'lib/gloo_lang/app/log.rb', line 60

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.



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/gloo_lang/app/log.rb', line 87

def error( msg, ex = nil, engine = nil )
  engine&.heap&.error&.set_to msg
  @logger.error msg
  if ex
    @logger.error ex.message
    @logger.error ex.backtrace
    puts msg unless @quiet
    puts ex.message unless @quiet
    puts ex.backtrace unless @quiet
  else
    puts msg unless @quiet
  end
end

#info(msg) ⇒ Object

Write an information message to the log. Also write to the console unless quiet.



68
69
70
71
# File 'lib/gloo_lang/app/log.rb', line 68

def info( msg )
  @logger.info msg
  puts msg unless @quiet
end

#prep_serializeObject

Prepare for serialization by removing the file reference. Without this, the engine cannot be serialized.



109
110
111
# File 'lib/gloo_lang/app/log.rb', line 109

def prep_serialize
  @logger = nil
end

#restore_after_deserializationObject

Restore the logger after deserialization.



116
117
118
# File 'lib/gloo_lang/app/log.rb', line 116

def restore_after_deserialization
  create_logger
end

#show(msg) ⇒ Object

Show a message unless we’re in quite mode.



49
50
51
# File 'lib/gloo_lang/app/log.rb', line 49

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.



77
78
79
80
# File 'lib/gloo_lang/app/log.rb', line 77

def warn( msg )
  @logger.warn msg
  puts msg unless @quiet
end