Sha256: 4c651bb3e09a1113c3b5a64c54fc8ecf45bd193261adcf07bc3801eee25770b7

Contents?: true

Size: 1.43 KB

Versions: 35

Compression:

Stored size: 1.43 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=$!)
      debug "#{e}\n\t" + e.backtrace.join("\n\t")
    end
    module_function :log_error
    public :log_error
  end
end

Version data entries

35 entries across 35 versions & 6 rubygems

Version Path
grockit-thin-0.8.2 lib/thin/logging.rb
macournoyer-thin-1.0.1 lib/thin/logging.rb
macournoyer-thin-1.1.0 lib/thin/logging.rb
michaelyta-thin-1.2.2 lib/thin/logging.rb
thin-1.2.11 lib/thin/logging.rb
thin-1.2.11-x86-mswin32 lib/thin/logging.rb
thin-1.2.11-x86-mingw32 lib/thin/logging.rb
thin-1.2.10 lib/thin/logging.rb
thin-1.2.10-x86-mswin32 lib/thin/logging.rb
thin-1.2.10-x86-mingw32 lib/thin/logging.rb
thin-1.2.9 lib/thin/logging.rb
thin-1.2.9-x86-mswin32 lib/thin/logging.rb
thin-1.2.9-x86-mingw32 lib/thin/logging.rb
thin-1.2.8 lib/thin/logging.rb
thin-1.2.8-x86-mswin32 lib/thin/logging.rb
thin-1.2.8-x86-mingw32 lib/thin/logging.rb
steamcannon-thin-1.2.8 lib/thin/logging.rb
thin-1.2.7 lib/thin/logging.rb
thin-1.2.7-x86-mswin32 lib/thin/logging.rb
thin-1.2.7-x86-mingw32 lib/thin/logging.rb