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.trace=
: log all raw request and response and
messages logged with +trace+.
Logging.silent=
: silence all log all log messages
altogether.
Defined Under Namespace
Classes: SimpleFormatter
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.trace_logger ⇒ Object
Returns the value of attribute trace_logger.
Class Method Summary collapse
- .debug=(val) ⇒ Object
-
.debug? ⇒ Boolean
Provided for backwards compatibility.
- .level ⇒ Object
- .level=(value) ⇒ Object
-
.log_debug(msg = nil) ⇒ Object
Log a message at DEBUG level.
-
.log_error(msg, e = nil) ⇒ Object
Log a message at ERROR level (and maybe a backtrace).
-
.log_info(msg) ⇒ Object
Log a message at INFO level.
- .log_msg(msg, level = Logger::INFO) ⇒ Object
- .silent=(shh) ⇒ Object
- .silent? ⇒ Boolean
-
.trace(msg = nil) ⇒ Object
Log a message if tracing is activated.
- .trace=(enabled) ⇒ Object
- .trace? ⇒ Boolean
- .trace_msg(msg) ⇒ Object
Instance Method Summary collapse
-
#log(msg) ⇒ Object
For backwards compatibility.
-
#log_debug(msg = nil) ⇒ Object
Log a message at DEBUG level.
-
#log_error(msg, e = nil) ⇒ Object
Log a message at ERROR level (and maybe a backtrace).
-
#log_info(msg) ⇒ Object
Log a message at INFO level.
-
#silent ⇒ Object
module methods.
- #silent=(value) ⇒ Object
-
#trace(msg = nil) ⇒ Object
Log a message if tracing is activated.
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
22 23 24 |
# File 'lib/thin/logging.rb', line 22 def logger @logger end |
.trace_logger ⇒ Object
Returns the value of attribute trace_logger.
23 24 25 |
# File 'lib/thin/logging.rb', line 23 def trace_logger @trace_logger end |
Class Method Details
.debug=(val) ⇒ Object
114 115 116 |
# File 'lib/thin/logging.rb', line 114 def debug=(val) self.level = (val ? Logger::DEBUG : Logger::INFO) end |
.debug? ⇒ Boolean
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.
111 112 113 |
# File 'lib/thin/logging.rb', line 111 def debug? self.level == Logger::DEBUG end |
.level ⇒ Object
49 50 51 |
# File 'lib/thin/logging.rb', line 49 def level @logger ? @logger.level : nil # or 'silent' end |
.level=(value) ⇒ Object
53 54 55 56 57 |
# File 'lib/thin/logging.rb', line 53 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) ⇒ Object
Log a message at DEBUG level
136 137 138 |
# File 'lib/thin/logging.rb', line 136 def log_debug(msg=nil) Logging.log_msg(msg || yield, Logger::DEBUG) end |
.log_error(msg, e = nil) ⇒ Object
Log a message at ERROR level (and maybe a backtrace)
150 151 152 153 |
# File 'lib/thin/logging.rb', line 150 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) ⇒ Object
Log a message at INFO level
143 144 145 |
# File 'lib/thin/logging.rb', line 143 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end |
.log_msg(msg, level = Logger::INFO) ⇒ Object
98 99 100 101 |
# File 'lib/thin/logging.rb', line 98 def log_msg(msg, level=Logger::INFO) return unless @logger @logger.add(level, msg) end |
.silent=(shh) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/thin/logging.rb', line 37 def silent=(shh) if shh @logger = nil else @logger ||= Logger.new(STDOUT) end end |
.silent? ⇒ Boolean
45 46 47 |
# File 'lib/thin/logging.rb', line 45 def silent? !@logger.nil? end |
.trace(msg = nil) ⇒ Object
Log a message if tracing is activated
129 130 131 |
# File 'lib/thin/logging.rb', line 129 def trace(msg=nil) Logging.trace_msg(msg) if msg end |
.trace=(enabled) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/thin/logging.rb', line 25 def trace=(enabled) if enabled @trace_logger ||= Logger.new(STDOUT) else @trace_logger = nil end end |
.trace? ⇒ Boolean
33 34 35 |
# File 'lib/thin/logging.rb', line 33 def trace? !@trace_logger.nil? end |
.trace_msg(msg) ⇒ Object
103 104 105 106 |
# File 'lib/thin/logging.rb', line 103 def trace_msg(msg) return unless @trace_logger @trace_logger.info(msg) end |
Instance Method Details
#log(msg) ⇒ Object
For backwards compatibility
158 159 160 161 162 |
# File 'lib/thin/logging.rb', line 158 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) ⇒ Object
Log a message at DEBUG level
136 137 138 |
# File 'lib/thin/logging.rb', line 136 def log_debug(msg=nil) Logging.log_msg(msg || yield, Logger::DEBUG) end |
#log_error(msg, e = nil) ⇒ Object
Log a message at ERROR level (and maybe a backtrace)
150 151 152 153 |
# File 'lib/thin/logging.rb', line 150 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) ⇒ Object
Log a message at INFO level
143 144 145 |
# File 'lib/thin/logging.rb', line 143 def log_info(msg) Logging.log_msg(msg || yield, Logger::INFO) end |
#silent ⇒ Object
module methods
120 121 122 |
# File 'lib/thin/logging.rb', line 120 def silent Logging.silent? end |