To be included in classes to allow some basic logging that can be silenced (Logging.silent=) or made more verbose. Logging.trace=: log all raw request and response and
messages logged with +trace+.
Logging.silent=: silence all log all log messages
altogether.
# File lib/thin/logging.rb, line 113 def debug=(val) self.level = (val ? Logger::DEBUG : Logger::INFO) end
Provided for backwards compatibility. Callers should be using the level (on the Logging module or on the instance) to figure out what the log level is.
# File lib/thin/logging.rb, line 110 def debug? self.level == Logger::DEBUG end
# File lib/thin/logging.rb, line 48 def level @logger ? @logger.level : nil # or 'silent' end
# File lib/thin/logging.rb, line 52 def level=(value) # If logging has been silenced, then re-enable logging @logger = Logger.new(STDOUT) if @logger.nil? @logger.level = value end
Log a message at DEBUG level
# File lib/thin/logging.rb, line 140 def log_debug(msg=nil) Logging.log_msg(msg || yield, Logger::DEBUG) end
Log a message at ERROR level (and maybe a backtrace)
# File lib/thin/logging.rb, line 154 def log_error(msg, e=nil) log_msg = msg + ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" if e Logging.log_msg(log_msg, Logger::ERROR) end
Log a message at INFO level
# File lib/thin/logging.rb, line 147 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end
# File lib/thin/logging.rb, line 97 def log_msg(msg, level=Logger::INFO) return unless @logger @logger.add(level, msg) end
Allow user to specify a custom logger to use. This object must respond to: level, level= and debug, info, warn, error, fatal
# File lib/thin/logging.rb, line 61 def logger=(custom_logger) [ :level , :level= , :debug , :info , :warn , :error , :fatal , :unknown , ].each do |method| if not custom_logger.respond_to?(method) raise ArgumentError, "logger must respond to #{method}" end end @logger = custom_logger end
# File lib/thin/logging.rb, line 36 def silent=(shh) if shh @logger = nil else @logger ||= Logger.new(STDOUT) end end
Log a message if tracing is activated
# File lib/thin/logging.rb, line 133 def trace(msg=nil) Logging.trace_msg(msg) if msg end
# File lib/thin/logging.rb, line 24 def trace=(enabled) if enabled @trace_logger ||= Logger.new(STDOUT) else @trace_logger = nil end end
# File lib/thin/logging.rb, line 32 def trace? !@trace_logger.nil? end
# File lib/thin/logging.rb, line 79 def trace_logger=(custom_tracer) [ :level , :level= , :debug , :info , :warn , :error , :fatal , :unknown , ].each do |method| if not custom_tracer.respond_to?(method) raise ArgumentError, "trace logger must respond to #{method}" end end @trace_logger = custom_tracer end
For backwards compatibility
# File lib/thin/logging.rb, line 162 def log msg STDERR.puts('#log has been deprecated, please use the ' 'log_level function instead (e.g. - log_info).') log_info(msg) end
Log a message at DEBUG level
# File lib/thin/logging.rb, line 140 def log_debug(msg=nil) Logging.log_msg(msg || yield, Logger::DEBUG) end
Log a message at ERROR level (and maybe a backtrace)
# File lib/thin/logging.rb, line 154 def log_error(msg, e=nil) log_msg = msg + ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" if e Logging.log_msg(log_msg, Logger::ERROR) end
Log a message at INFO level
# File lib/thin/logging.rb, line 147 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end
Generated with the Darkfish Rdoc Generator 2.