Sha256: 40c3d0acf2434ccd5080b1e789475d92007f25e0cd080833430430c813a88ae0

Contents?: true

Size: 1.45 KB

Versions: 48

Compression:

Stored size: 1.45 KB

Contents

module Thin
  # To be included in classes to allow some basic logging
  # that can be silenced (<tt>Logging.silent=</tt>) or made
  # more verbose.
  # <tt>Logging.debug=</tt>: log all error backtrace and messages
  #                          logged with +debug+.
  # <tt>Logging.trace=</tt>: log all raw request and response and
  #                          messages logged with +trace+.
  module Logging
    class << self
      attr_writer :trace, :debug, :silent
      
      def trace?;  !@silent && @trace  end
      def debug?;  !@silent && @debug  end
      def silent?;  @silent            end
    end
    
    # Global silencer methods
    def silent
      Logging.silent?
    end
    def silent=(value)
      Logging.silent = value
    end
    
    # Log a message to the console
    def log(msg)
      puts msg unless Logging.silent?
    end
    module_function :log
    public :log
    
    # Log a message to the console if tracing is activated
    def trace(msg=nil)
      log msg || yield if Logging.trace?
    end
    module_function :trace
    public :trace
    
    # Log a message to the console if debugging is activated
    def debug(msg=nil)
      log msg || yield if Logging.debug?
    end
    module_function :debug
    public :debug
    
    # Log an error backtrace if debugging is activated
    def log_error(e=$!)
      STDERR.print("#{e}\n\t" + e.backtrace.join("\n\t")) if Logging.debug?
    end
    module_function :log_error
    public :log_error
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.7.4 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.7.3 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.7.2 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.7.1 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.7.0 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.9 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.8 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.7 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.6 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.5 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.4 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.3 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.2 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.1 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.6.0 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.5.17 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.5.16 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.5.15 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb
classiccms-0.5.14 vendor/bundle/gems/thin-1.3.1/lib/thin/logging.rb