Class: Innate::LogHub
- Inherits:
-
Object
- Object
- Innate::LogHub
- Includes:
- Optioned, Logger::Severity
- Defined in:
- lib/innate/log/hub.rb
Overview
Innate only provides logging via stdlib Logger to avoid bloat and dependencies, you may specify multiple loggers in the Log instance of LogHub to accomendate your needs, by default we log to $stderr to be compatible with CGI.
Please read the documentation of logger.rb (or even better, its source) to get a feeling of how to use it correctly within Innate
A few shortcuts:
-
Create logger for stderr/stdout
logger = Logger.new($stdout) logger = Logger.new($stderr)
-
Create logger for a file
logger = Logger.new('test.log')
-
Create logger for file object
file = File.open('test.log', 'a+') logger = Logger.new(file)
-
Create logger with rotation on specified file size
# 10 files history, 5 MB each logger = Logger.new('test.log', 10, (5 << 20)) # 100 files history, 1 MB each logger = Logger.new('test.log', 100, (1 << 20))
-
Create a logger which ages logfiles daily/weekly/monthly
logger = Logger.new('test.log', 'daily') logger = Logger.new('test.log', 'weekly') logger = Logger.new('test.log', 'monthly')
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#loggers ⇒ Object
Returns the value of attribute loggers.
-
#program ⇒ Object
Returns the value of attribute program.
Instance Method Summary collapse
-
#initialize(*loggers) ⇒ LogHub
constructor
loggers
should be a list of Logger instances. -
#level=(lvl) ⇒ Object
set level for all loggers.
- #method_missing(meth, *args, &block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #write(*args) ⇒ Object
Methods included from Optioned
Constructor Details
#initialize(*loggers) ⇒ LogHub
loggers
should be a list of Logger instances
46 47 48 49 50 51 |
# File 'lib/innate/log/hub.rb', line 46 def initialize(*loggers) @loggers = loggers.flatten @program = nil @active = true self.level = DEBUG end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/innate/log/hub.rb', line 62 def method_missing(meth, *args, &block) eval %~ def #{meth}(*args, &block) return unless @active args.each{|arg| @loggers.each{|logger| logger.#{meth}(arg, &block) }} end ~ send(meth, *args, &block) end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
43 44 45 |
# File 'lib/innate/log/hub.rb', line 43 def active @active end |
#loggers ⇒ Object
Returns the value of attribute loggers.
43 44 45 |
# File 'lib/innate/log/hub.rb', line 43 def loggers @loggers end |
#program ⇒ Object
Returns the value of attribute program.
43 44 45 |
# File 'lib/innate/log/hub.rb', line 43 def program @program end |
Instance Method Details
#level=(lvl) ⇒ Object
set level for all loggers
54 55 56 57 |
# File 'lib/innate/log/hub.rb', line 54 def level=(lvl) @loggers.each{|l| l.level = lvl } @level = lvl end |
#start ⇒ Object
59 |
# File 'lib/innate/log/hub.rb', line 59 def start; @active = true; end |
#stop ⇒ Object
60 |
# File 'lib/innate/log/hub.rb', line 60 def stop; @active = false; end |
#write(*args) ⇒ Object
73 74 75 |
# File 'lib/innate/log/hub.rb', line 73 def write(*args) self.<<(*args) end |