Module: Thin::Logging

Included in:
Command, Connection, Controllers::Controller, Server
Defined in:
lib/thin/logging.rb

Overview

To be included in classes to allow some basic logging that can be silenced (Logging.silent=) or made more verbose. Logging.debug=: log all error backtrace and messages

logged with +debug+.

Logging.trace=: log all raw request and response and

messages logged with +trace+.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.debug=(value) ⇒ Object (writeonly)

Sets the attribute debug

Parameters:

  • value

    the value to set the attribute debug to.



11
12
13
# File 'lib/thin/logging.rb', line 11

def debug=(value)
  @debug = value
end

.silent=(value) ⇒ Object (writeonly)

Sets the attribute silent

Parameters:

  • value

    the value to set the attribute silent to.



11
12
13
# File 'lib/thin/logging.rb', line 11

def silent=(value)
  @silent = value
end

.trace=(value) ⇒ Object (writeonly)

Sets the attribute trace

Parameters:

  • value

    the value to set the attribute trace to.



11
12
13
# File 'lib/thin/logging.rb', line 11

def trace=(value)
  @trace = value
end

Class Method Details

.debug(msg = nil) ⇒ Object (writeonly)

Log a message to the console if debugging is activated



41
42
43
# File 'lib/thin/logging.rb', line 41

def debug(msg=nil)
  log msg || yield if Logging.debug?
end

.debug?Boolean

Returns:

  • (Boolean)


14
# File 'lib/thin/logging.rb', line 14

def debug?;  !@silent && @debug  end

.log(msg) ⇒ Object

Log a message to the console



27
28
29
# File 'lib/thin/logging.rb', line 27

def log(msg)
  puts msg unless Logging.silent?
end

.log_error(e = $!) ⇒ Object

Log an error backtrace if debugging is activated



48
49
50
# File 'lib/thin/logging.rb', line 48

def log_error(e=$!)
  debug "#{e}\n\t" + e.backtrace.join("\n\t")
end

.silent?Boolean

Returns:

  • (Boolean)


15
# File 'lib/thin/logging.rb', line 15

def silent?;  @silent            end

.trace(msg = nil) ⇒ Object (writeonly)

Log a message to the console if tracing is activated



34
35
36
# File 'lib/thin/logging.rb', line 34

def trace(msg=nil)
  log msg || yield if Logging.trace?
end

.trace?Boolean

Returns:

  • (Boolean)


13
# File 'lib/thin/logging.rb', line 13

def trace?;  !@silent && @trace  end

Instance Method Details

#debug(msg = nil) ⇒ Object

Log a message to the console if debugging is activated



41
42
43
# File 'lib/thin/logging.rb', line 41

def debug(msg=nil)
  log msg || yield if Logging.debug?
end

#log(msg) ⇒ Object

Log a message to the console



27
28
29
# File 'lib/thin/logging.rb', line 27

def log(msg)
  puts msg unless Logging.silent?
end

#log_error(e = $!) ⇒ Object

Log an error backtrace if debugging is activated



48
49
50
# File 'lib/thin/logging.rb', line 48

def log_error(e=$!)
  debug "#{e}\n\t" + e.backtrace.join("\n\t")
end

#silentObject

Global silencer methods



19
20
21
# File 'lib/thin/logging.rb', line 19

def silent
  Logging.silent?
end

#silent=(value) ⇒ Object



22
23
24
# File 'lib/thin/logging.rb', line 22

def silent=(value)
  Logging.silent = value
end

#trace(msg = nil) ⇒ Object

Log a message to the console if tracing is activated



34
35
36
# File 'lib/thin/logging.rb', line 34

def trace(msg=nil)
  log msg || yield if Logging.trace?
end