Module: Ramaze::Logging
- Included in:
- Ramaze::Logger::Informer, Ramaze::Logger::LogHub, Ramaze::Logger::RotatingInformer, Ramaze::Logger::Syslog, SpecLogger
- Defined in:
- lib/ramaze/log/logging.rb
Overview
This module provides a basic skeleton for your own loggers to be compatible.
Instance Method Summary collapse
-
#debug(*objects) ⇒ Object
(also: #<<)
Inspects objects if they are no strings.
-
#debug? ⇒ Boolean
Stub for WEBrick.
-
#dev(*objects) ⇒ Object
Inspects objects if they are no strings.
-
#error(ex) ⇒ Object
Takes either an Exception or just a String, formats backtraces to be a bit more readable and passes all of this on to tag_log :error.
-
#info(*objects) ⇒ Object
Converts everything given to strings and passes them on with :info.
-
#shutdown ⇒ Object
Nothing.
-
#tag_log(tag, meth, *msgs) ⇒ Object
Takes the tag (:warn|:debug|:error|:info) and the name of a method to be called upon elements of msgs that don’t respond to :to_str Goes on and sends the tag and transformed messages each to the #log method.
-
#warn(*objects) ⇒ Object
Converts everything given to strings and passes them on with :warn.
Instance Method Details
#debug(*objects) ⇒ Object Also known as: <<
Inspects objects if they are no strings. Tag is :debug
60 61 62 |
# File 'lib/ramaze/log/logging.rb', line 60 def debug(*objects) tag_log(:debug, :inspect, *objects) end |
#debug? ⇒ Boolean
Stub for WEBrick
103 104 105 |
# File 'lib/ramaze/log/logging.rb', line 103 def debug? false end |
#dev(*objects) ⇒ Object
Inspects objects if they are no strings. Tag is :dev
69 70 71 |
# File 'lib/ramaze/log/logging.rb', line 69 def dev(*objects) tag_log(:dev, :inspect, *objects) end |
#error(ex) ⇒ Object
Takes either an Exception or just a String, formats backtraces to be a bit more readable and passes all of this on to tag_log :error
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ramaze/log/logging.rb', line 81 def error(ex) if ex.respond_to?(:exception) = ex.backtrace .map!{|m| m.to_s.gsub(/^#{Regexp.escape(Dir.pwd)}/, '.') } .unshift(ex.inspect) else = ex.to_s end tag_log(:error, :to_s, *) end |
#info(*objects) ⇒ Object
Converts everything given to strings and passes them on with :info
41 42 43 |
# File 'lib/ramaze/log/logging.rb', line 41 def info(*objects) tag_log(:info, :to_s, *objects) end |
#shutdown ⇒ Object
Nothing.
THINK: Is this really required? It doesn’t do anything anyway.
97 98 |
# File 'lib/ramaze/log/logging.rb', line 97 def shutdown end |
#tag_log(tag, meth, *msgs) ⇒ Object
Takes the tag (:warn|:debug|:error|:info) and the name of a method to be called upon elements of msgs that don’t respond to :to_str Goes on and sends the tag and transformed messages each to the #log method. If you include this module you have to define #log or it will raise.
28 29 30 31 32 33 |
# File 'lib/ramaze/log/logging.rb', line 28 def tag_log(tag, meth, *msgs) msgs.each do |msg| string = (msg.respond_to?(:to_str) ? msg : msg.send(meth)) log(tag, string) end end |
#warn(*objects) ⇒ Object
Converts everything given to strings and passes them on with :warn
51 52 53 |
# File 'lib/ramaze/log/logging.rb', line 51 def warn(*objects) tag_log(:warn, :to_s, *objects) end |