2 # To be included in classes to allow some basic logging
3 # that can be silenced (<tt>Logging.silent=</tt>) or made
5 # <tt>Logging.debug=</tt>: log all error backtrace and messages
7 # <tt>Logging.trace=</tt>: log all raw request and response and
8 # messages logged with +trace+.
11 attr_writer :trace, :debug, :silent
13 def trace?; !@silent && @trace end
14 def debug?; !@silent && @debug end
15 def silent?; @silent end
18 # Global silencer methods
23 Logging.silent = value
26 # Log a message to the console
28 puts msg unless Logging.silent?
33 # Log a message to the console if tracing is activated
35 log msg || yield if Logging.trace?
37 module_function :trace
40 # Log a message to the console if debugging is activated
42 log msg || yield if Logging.debug?
44 module_function :debug
47 # Log an error backtrace if debugging is activated
49 debug "#{e}\n\t" + e.backtrace.join("\n\t")
51 module_function :log_error