Class: Log4r::Logger
- Inherits:
-
Object
- Object
- Log4r::Logger
- Defined in:
- lib/commons/ruby/log4r/logger.rb
Overview
This is the extended Log4r::Logger class of rCommons.
Example:
require 'commons/ruby/log4r'
module Example
class Sample
LOG = Log4r::Logger.get_logger(self.name)
#@@log = Log4r::Logger.get_logger(self.name) # for Ruby 1.9 or later.
# ...
if LOG.debug?
LOG.debug('This is DEBUG log.')
end
LOG.info('This is INFO log.')
# ...
end
end
Constant Summary collapse
- DEFAULT_XML_CONFIGURATION_FILE =
'log4r.xml'
- DEFAULT_YAML_CONFIGURATION_FILE =
'log4r.yaml'
- @@current_configuration_file =
nil
Class Method Summary collapse
Class Method Details
.get_logger(name) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/commons/ruby/log4r/logger.rb', line 102 def self.get_logger(name) if Logger[name] == nil logger = Logger.new(name) if logger.additive logger.trace = logger.parent.trace # inherit trace flag end return logger else return Logger[name] end end |
.static_initialize ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/commons/ruby/log4r/logger.rb', line 65 def self.static_initialize # 1. ENV config = ENV[Commons::LOG4R_CONF_PROPERTY] # 2. Commons::ENV if config == nil config = Commons::ENV[Commons::LOG4R_CONF_PROPERTY] end # 3. Default XML configuration file if config == nil config = Commons::Lang::ClassLoader.get_resource(DEFAULT_XML_CONFIGURATION_FILE) end # 4. Default YAML configuration file if config == nil config = Commons::Lang::ClassLoader.get_resource(DEFAULT_YAML_CONFIGURATION_FILE) end if config != nil case config[config.rindex('.') .. -1] when '.xml' require 'log4r/configurator' Configurator.load_xml_file(config) @@current_configuration_file = config when '.yaml', '.yml' require 'log4r/yamlconfigurator' YamlConfigurator.load_yaml_file(config) @@current_configuration_file = config else # do nothing. end end end |