Class: Hive::Log
- Inherits:
-
Object
- Object
- Hive::Log
- Defined in:
- lib/hive/log.rb
Overview
Hive logging Allow logging to be written to multiple locations.
Instance Attribute Summary collapse
-
#default_progname ⇒ Object
Returns the value of attribute default_progname.
-
#hive_mind ⇒ Object
Returns the value of attribute hive_mind.
Instance Method Summary collapse
-
#add_logger(stream, level) ⇒ Object
Add a new log location:.
-
#clear(component = nil) ⇒ Object
Currently this will clear the Hive Mind log but do nothing to the local files.
-
#debug(*args, &block) ⇒ Object
These methods were originally created using define_method as they are all the same.
- #error(*args, &block) ⇒ Object
- #fatal(*args, &block) ⇒ Object
- #info(*args, &block) ⇒ Object
-
#initialize(args = []) ⇒ Log
constructor
Create the logger:.
-
#stop_logger(stream) ⇒ Object
Stop a log stream:.
- #unknown(*args, &block) ⇒ Object
- #warn(*args, &block) ⇒ Object
Constructor Details
#initialize(args = []) ⇒ Log
Create the logger:
# No log files will be written
log = Hive::Log.new()
# Write log files to standard out and a log file
log = Hive::Log.new( [
{
stream: 'Filename.log',
level: 'DEBUG'
},
{
stream: STDOUT,
level: 'INFO'
},
] )
25 26 27 28 29 30 |
# File 'lib/hive/log.rb', line 25 def initialize(args = []) @loggers = {} args.each do |l| add_logger(l[:stream], l[:level]) end end |
Instance Attribute Details
#default_progname ⇒ Object
Returns the value of attribute default_progname.
8 9 10 |
# File 'lib/hive/log.rb', line 8 def default_progname @default_progname end |
#hive_mind ⇒ Object
Returns the value of attribute hive_mind.
7 8 9 |
# File 'lib/hive/log.rb', line 7 def hive_mind @hive_mind end |
Instance Method Details
#add_logger(stream, level) ⇒ Object
Add a new log location:
# INFO level log to 'Filename.log'
log.add_logger( 'Filename.log', 'INFO' )
# DEBUG level log to standard output
log.add_logger( STDOUT, 'DEBUG' )
38 39 40 41 42 43 44 45 |
# File 'lib/hive/log.rb', line 38 def add_logger(stream, level) log = MonoLogger.new(stream) log.formatter = proc do |severity, datetime, progname, msg| "#{severity[0, 1]} #{datetime.strftime('%Y-%m-%d %H:%M:%S')} -- #{progname}: #{msg}\n" end log.level = MonoLogger.const_get(level) @loggers[stream] = log end |
#clear(component = nil) ⇒ Object
Currently this will clear the Hive Mind log but do nothing to the local files
85 86 87 88 89 |
# File 'lib/hive/log.rb', line 85 def clear(component = nil) if self.hive_mind self.hive_mind.clear_state component: component end end |
#debug(*args, &block) ⇒ Object
These methods were originally created using define_method as they are all the same. However, blocks cannot be used with define_method.
59 60 61 |
# File 'lib/hive/log.rb', line 59 def debug(*args, &block) write_log('debug', *args, &block) end |
#error(*args, &block) ⇒ Object
71 72 73 |
# File 'lib/hive/log.rb', line 71 def error(*args, &block) write_log('error', *args, &block) end |
#fatal(*args, &block) ⇒ Object
75 76 77 |
# File 'lib/hive/log.rb', line 75 def fatal(*args, &block) write_log('fatal', *args, &block) end |
#info(*args, &block) ⇒ Object
63 64 65 |
# File 'lib/hive/log.rb', line 63 def info(*args, &block) write_log('info', *args, &block) end |
#stop_logger(stream) ⇒ Object
Stop a log stream:
# Stop the log to standard output
log.stop_logger( STDOUT )
# Stop the log to 'Filename.log'
log.stop_logger( 'Filename.log' )
53 54 55 |
# File 'lib/hive/log.rb', line 53 def stop_logger(stream) @loggers.delete(stream) end |
#unknown(*args, &block) ⇒ Object
79 80 81 |
# File 'lib/hive/log.rb', line 79 def unknown(*args, &block) write_log('unknown', *args, &block) end |
#warn(*args, &block) ⇒ Object
67 68 69 |
# File 'lib/hive/log.rb', line 67 def warn(*args, &block) write_log('warn', *args, &block) end |