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 115 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 112 def debug? self.level == Logger::DEBUG end
# File lib/thin/logging.rb, line 50 def level @logger ? @logger.level : nil # or 'silent' end
# File lib/thin/logging.rb, line 54 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 142 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 156 def log_error(msg, e=nil) log_msg = msg if e log_msg += ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" end Logging.log_msg(log_msg, Logger::ERROR) end
Log a message at INFO level
# File lib/thin/logging.rb, line 149 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end
# File lib/thin/logging.rb, line 99 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 63 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 38 def silent=(shh) if shh @logger = nil else @logger ||= Logger.new(STDOUT) end end
# File lib/thin/logging.rb, line 46 def silent? !@logger.nil? end
Log a message if tracing is activated
# File lib/thin/logging.rb, line 135 def trace(msg=nil) Logging.trace_msg(msg) if msg end
# File lib/thin/logging.rb, line 26 def trace=(enabled) if enabled @trace_logger ||= Logger.new(STDOUT) else @trace_logger = nil end end
# File lib/thin/logging.rb, line 34 def trace? !@trace_logger.nil? end
# File lib/thin/logging.rb, line 81 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
# File lib/thin/logging.rb, line 104 def trace_msg(msg) return unless @trace_logger @trace_logger.info(msg) end
For backwards compatibility
# File lib/thin/logging.rb, line 167 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 142 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 156 def log_error(msg, e=nil) log_msg = msg if e log_msg += ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" end Logging.log_msg(log_msg, Logger::ERROR) end
Log a message at INFO level
# File lib/thin/logging.rb, line 149 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end
# File lib/thin/logging.rb, line 126 def silent Logging.silent? end
# File lib/thin/logging.rb, line 130 def silent=(value) Logging.silent = value end
Log a message if tracing is activated
# File lib/thin/logging.rb, line 135 def trace(msg=nil) Logging.trace_msg(msg) if msg end