Module: Thin::Logging

### Home Classes Methods

### In Files

- lib/thin/logging.rb

### Namespace

- CLASS Thin::Logging::SimpleFormatter

### Methods

- ::debug=
- ::debug?
- ::level
- ::level=
- ::log_debug
- ::log_error
- ::log_info
- ::log_msg
- ::logger=
- ::silent=
- ::silent?
- ::trace
- ::trace=
- ::trace?
- ::trace_logger=
- ::trace_msg
- #log
- #log_debug
- #log_error
- #log_info
- #silent
- #silent=
- #trace

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Thin::Logging

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.

### Attributes

logger[R]
trace_logger[R]

### Public Class Methods

debug=(val) click to toggle source

    # File lib/thin/logging.rb, line 113
    def debug=(val)
      self.level = (val ? Logger::DEBUG : Logger::INFO)
    end

debug?() click to toggle source

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 110
    def debug?
      self.level == Logger::DEBUG
    end

level() click to toggle source

    # File lib/thin/logging.rb, line 48
    def level
      @logger ? @logger.level : nil # or 'silent'
    end

level=(value) click to toggle source

    # File lib/thin/logging.rb, line 52
    def level=(value)
      # If logging has been silenced, then re-enable logging
      @logger = Logger.new(STDOUT) if @logger.nil?
      @logger.level = value
    end

log_debug(msg=nil) click to toggle source

Log a message at DEBUG level

    # File lib/thin/logging.rb, line 140
    def log_debug(msg=nil)
      Logging.log_msg(msg || yield, Logger::DEBUG)
    end

log_error(msg, e=nil) click to toggle source

Log a message at ERROR level (and maybe a backtrace)

    # File lib/thin/logging.rb, line 154
    def log_error(msg, e=nil)
      log_msg = msg + ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" if e
      Logging.log_msg(log_msg, Logger::ERROR)
    end

log_info(msg) click to toggle source

Log a message at INFO level

    # File lib/thin/logging.rb, line 147
    def log_info(msg)
      Logging.log_msg(msg || yield, Logger::INFO)
    end

log_msg(msg, level=Logger::INFO) click to toggle source

    # File lib/thin/logging.rb, line 97
    def log_msg(msg, level=Logger::INFO)
      return unless @logger
      @logger.add(level, msg)
    end

logger=(custom_logger) click to toggle source

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 61
    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

silent=(shh) click to toggle source

    # File lib/thin/logging.rb, line 36
    def silent=(shh)
      if shh
        @logger = nil
      else
        @logger ||= Logger.new(STDOUT)
      end
    end

silent?() click to toggle source

    # File lib/thin/logging.rb, line 44
    def silent?
      !@logger.nil?
    end

trace(msg=nil) click to toggle source

Log a message if tracing is activated

    # File lib/thin/logging.rb, line 133
    def trace(msg=nil)
      Logging.trace_msg(msg) if msg
    end

trace=(enabled) click to toggle source

    # File lib/thin/logging.rb, line 24
    def trace=(enabled)
      if enabled
        @trace_logger ||= Logger.new(STDOUT)
      else
        @trace_logger = nil
      end
    end

trace?() click to toggle source

    # File lib/thin/logging.rb, line 32
    def trace?
      !@trace_logger.nil?
    end

trace_logger=(custom_tracer) click to toggle source

    # File lib/thin/logging.rb, line 79
    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

trace_msg(msg) click to toggle source

    # File lib/thin/logging.rb, line 102
    def trace_msg(msg)
      return unless @trace_logger
      @trace_logger.info(msg)
    end

### Public Instance Methods

log(msg) click to toggle source

For backwards compatibility

    # File lib/thin/logging.rb, line 162
    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_debug(msg=nil) click to toggle source

Log a message at DEBUG level

    # File lib/thin/logging.rb, line 140
    def log_debug(msg=nil)
      Logging.log_msg(msg || yield, Logger::DEBUG)
    end

log_error(msg, e=nil) click to toggle source

Log a message at ERROR level (and maybe a backtrace)

    # File lib/thin/logging.rb, line 154
    def log_error(msg, e=nil)
      log_msg = msg + ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n" if e
      Logging.log_msg(log_msg, Logger::ERROR)
    end

log_info(msg) click to toggle source

Log a message at INFO level

    # File lib/thin/logging.rb, line 147
    def log_info(msg)
      Logging.log_msg(msg || yield, Logger::INFO)
    end

silent() click to toggle source

    # File lib/thin/logging.rb, line 124
    def silent
      Logging.silent?
    end

silent=(value) click to toggle source

    # File lib/thin/logging.rb, line 128
    def silent=(value)
      Logging.silent = value
    end

trace(msg=nil) click to toggle source

Log a message if tracing is activated

    # File lib/thin/logging.rb, line 133
    def trace(msg=nil)
      Logging.trace_msg(msg) if msg
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.