Module: FeldtRuby::Logging
- Included in:
- Optimize::Objective, Optimize::Optimizer
- Defined in:
- lib/feldtruby/logger.rb
Overview
A simple logging interface front end for classes that need basic logging. Just include and call log methods on logger. Uses a single common logger unless a new one is been explicitly specified..
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#__find_logger_set_on_instance_vars ⇒ Object
Find a logger if one has been set on any of my instance vars or their instance vars (recursively).
-
#new_default_logger(options = {}) ⇒ Object
Override to use another logger as default if no logger is found.
- #setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil) ⇒ Object
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
176 177 178 |
# File 'lib/feldtruby/logger.rb', line 176 def logger @logger end |
Instance Method Details
#__find_logger_set_on_instance_vars ⇒ Object
Find a logger if one has been set on any of my instance vars or their instance vars (recursively).
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/feldtruby/logger.rb', line 216 def __find_logger_set_on_instance_vars # First see if we find it in the immediate ivars self.instance_variables.each do |ivar_name| ivar = self.instance_variable_get ivar_name if ivar.respond_to?(:logger) begin l = ivar.send(:logger) return l if l.is_a?(FeldtRuby::Logger) rescue Exception => e end end end # If we come here it means we did NOT find a logger in immediate # ivar's. So we recurse. self.instance_variables.each do |ivar_name| ivar = self.instance_variable_get ivar_name if ivar.respond_to?(:find_logger_set_on_instance_vars) begin l = ivar.send(:find_logger_set_on_instance_vars) return l if l.is_a?(FeldtRuby::Logger) rescue Exception => e end end end nil end |
#new_default_logger(options = {}) ⇒ Object
Override to use another logger as default if no logger is found.
210 211 212 |
# File 'lib/feldtruby/logger.rb', line 210 def new_default_logger( = {}) FeldtRuby::Logger.new(STDOUT, ) end |
#setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/feldtruby/logger.rb', line 178 def setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil) if Hash === loggerOrOptions = loggerOrOptions logger = nil else = {} logger = loggerOrOptions end # Precedence for loggers if several has been setup: # 1. One specified as parameter to this method # 2. One that has already been set on this object # 3. First one found on an instance var # 4. Create a new standard one self.logger = logger || self.logger || __find_logger_set_on_instance_vars() || new_default_logger() # Now distribute the preferred logger to all instance vars, recursively. self.instance_variables.each do |ivar_name| ivar = self.instance_variable_get ivar_name if ivar.respond_to?(:setup_logger_and_distribute_to_instance_variables) ivar.setup_logger_and_distribute_to_instance_variables self.logger end end end |