OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / thin-1.2.11-x86-mswin32 / lib / thin / logging.rb
1 module Thin
2   # To be included in classes to allow some basic logging
3   # that can be silenced (<tt>Logging.silent=</tt>) or made
4   # more verbose.
5   # <tt>Logging.debug=</tt>: log all error backtrace and messages
6   #                          logged with +debug+.
7   # <tt>Logging.trace=</tt>: log all raw request and response and
8   #                          messages logged with +trace+.
9   module Logging
10     class << self
11       attr_writer :trace, :debug, :silent
12       
13       def trace?;  !@silent && @trace  end
14       def debug?;  !@silent && @debug  end
15       def silent?;  @silent            end
16     end
17     
18     # Global silencer methods
19     def silent
20       Logging.silent?
21     end
22     def silent=(value)
23       Logging.silent = value
24     end
25     
26     # Log a message to the console
27     def log(msg)
28       puts msg unless Logging.silent?
29     end
30     module_function :log
31     public :log
32     
33     # Log a message to the console if tracing is activated
34     def trace(msg=nil)
35       log msg || yield if Logging.trace?
36     end
37     module_function :trace
38     public :trace
39     
40     # Log a message to the console if debugging is activated
41     def debug(msg=nil)
42       log msg || yield if Logging.debug?
43     end
44     module_function :debug
45     public :debug
46     
47     # Log an error backtrace if debugging is activated
48     def log_error(e=$!)
49       debug "#{e}\n\t" + e.backtrace.join("\n\t")
50     end
51     module_function :log_error
52     public :log_error
53   end
54 end