Class: RSI::LogManager
- Inherits:
-
Object
- Object
- RSI::LogManager
- Includes:
- Singleton
- Defined in:
- lib/rsi/logmanager.rb
Overview
Manages logger creation for classes which mixin RSI::Loggable. LogManager has default settings for the log directory (Dir::tmpdir) and for the log file name (“app.log”).
If you’d like to override the defaults, call #root=() and/or #log_filename=() before LogManager is first used (ie, before RSI::Loggable#logger() is called the first time). You can also supply an arbitrary IO to #root_fh=() .
By default, the LogManager will create logs with level set to Logger::INFO. Individual classes mixing in RSI::Loggable may choose to override this by calling #logger.level=() .
Instance Attribute Summary collapse
-
#log_filename ⇒ Object
Returns the value of attribute log_filename.
-
#root ⇒ Object
Returns the value of attribute root.
-
#root_fh ⇒ Object
Returns the value of attribute root_fh.
-
#root_logger ⇒ Object
readonly
Returns the value of attribute root_logger.
Instance Method Summary collapse
-
#initialize ⇒ LogManager
constructor
A new instance of LogManager.
- #logger_for(obj = "root") ⇒ Object
Constructor Details
#initialize ⇒ LogManager
Returns a new instance of LogManager.
62 63 64 65 66 67 68 |
# File 'lib/rsi/logmanager.rb', line 62 def initialize() @root = Dir::tmpdir @log_filename = "app.log" @root_fh = nil @logger_cache = {} @root_logger = nil end |
Instance Attribute Details
#log_filename ⇒ Object
Returns the value of attribute log_filename.
60 61 62 |
# File 'lib/rsi/logmanager.rb', line 60 def log_filename @log_filename end |
#root ⇒ Object
Returns the value of attribute root.
60 61 62 |
# File 'lib/rsi/logmanager.rb', line 60 def root @root end |
#root_fh ⇒ Object
Returns the value of attribute root_fh.
60 61 62 |
# File 'lib/rsi/logmanager.rb', line 60 def root_fh @root_fh end |
#root_logger ⇒ Object (readonly)
Returns the value of attribute root_logger.
59 60 61 |
# File 'lib/rsi/logmanager.rb', line 59 def root_logger @root_logger end |
Instance Method Details
#logger_for(obj = "root") ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rsi/logmanager.rb', line 73 def logger_for( obj="root" ) if obj.kind_of?( String ) n = obj elsif obj.kind_of?( Module ) n = obj.name else n = obj.class.name end unless @logger_cache.has_key?( n ) configure() if @root_logger.nil? @logger_cache[n] = Logger.new( @root_logger ) @logger_cache[n].progname = n @logger_cache[n].level = Logger::INFO end return @logger_cache[n] end |