Class: Cayuga::Object::Logger
- Defined in:
- lib/cayuga/object/logger.rb
Instance Attribute Summary
Attributes inherited from Object
Instance Method Summary collapse
- #generic_log_file(name) ⇒ Object
- #log_appender(name) ⇒ Object
- #log_filename(name) ⇒ Object (also: #[])
- #log_log!(name, filename: nil, stream: nil, filter: nil, level: :info) ⇒ Object
- #log_log?(name) ⇒ Boolean
- #log_names ⇒ Object
Methods inherited from Singleton
Methods inherited from Object
Methods included from Tools::Loggable
Instance Method Details
#generic_log_file(name) ⇒ Object
10 11 12 |
# File 'lib/cayuga/object/logger.rb', line 10 def generic_log_file(name) "#{factory.logs_directory}/#{name.stringify.filenamify('.log')}" end |
#log_appender(name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cayuga/object/logger.rb', line 24 def log_appender(name) all = SemanticLogger.appenders.select { |log| log.name == name.stringify } count = all.count raise RuntimeError, "More than one log with name #{name}" if count > 1 if count == 1 all[0] else nil end end |
#log_filename(name) ⇒ Object Also known as: []
18 19 20 |
# File 'lib/cayuga/object/logger.rb', line 18 def log_filename(name) @logs[name.symbolize] end |
#log_log!(name, filename: nil, stream: nil, filter: nil, level: :info) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cayuga/object/logger.rb', line 39 def log_log!(name, filename: nil, stream: nil, filter: nil, level: :info) symbol = name.symbolize return log_filename(symbol) if log_log?(symbol) if log_appender_exists?(symbol) logger.warn('no entry for log', payload = { name: symbol }) logger.warn('no entry for log', payload = { log: log_names }) @logs[symbol] = filename || stream if log_filename(symbol).nil? @logs[symbol] = factory.logs_directory + '/' + name.classify.log_file end return end if filename.nil? if stream.nil? #must be a class filename = factory.logs_directory + '/' + name.classify.log_file log = SemanticLogger.add_appender(file_name: filename, filter: filter) else log = SemanticLogger.add_appender(io: stream, filter: filter) end else log = SemanticLogger.add_appender(file_name: filename, filter: filter) end log.name = name.stringify log.level = level @logs[name.symbolize] = filename || stream || name.stringify logger.info('logs', payload = { log_names: log_names }) logger.info('logs', payload = { count: SemanticLogger.appenders.count }) end |
#log_log?(name) ⇒ Boolean
35 36 37 |
# File 'lib/cayuga/object/logger.rb', line 35 def log_log?(name) not @logs[name.symbolize].nil? end |
#log_names ⇒ Object
14 15 16 |
# File 'lib/cayuga/object/logger.rb', line 14 def log_names @logs.keys.freeze end |