Class: CheapAdvice::Trace::DefaultFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- CheapAdvice::Trace::DefaultFormatter
- Defined in:
- lib/cheap_advice/trace.rb
Instance Attribute Summary
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #format(obj, mode) ⇒ Object
-
#record(ar, mode) ⇒ Object
Formats the ActivationRecord for the logger.
Methods inherited from BaseFormatter
Constructor Details
This class inherits a constructor from CheapAdvice::Trace::BaseFormatter
Instance Method Details
#format(obj, mode) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/cheap_advice/trace.rb', line 140 def format obj, mode case mode when :error return "ERROR #{obj.inspect}" when :result return "=> #{obj.inspect}" when :time return super else obj = super || obj end obj = obj.inspect if mode == :args obj = obj.to_s.gsub(/\A\[|\]\Z/, '') end obj end |
#record(ar, mode) ⇒ Object
Formats the ActivationRecord for the logger.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cheap_advice/trace.rb', line 160 def record ar, mode ad = ar.advised msg = nil case mode when :before, :after msg = ad.log_prefix(logger, ar).to_s msg = msg.dup if msg.frozen? ar[:args] ||= format(ar.args, :args) if ad[:log_args] != false ar[:meth] ||= "#{ad.meth_to_s} #{ar.rcvr.class}" msg << "#{format(ar[:"time_#{mode}"], :time)} #{ar[:meth]}" msg << " #{format(ar.rcvr, :rcvr)}" if ad[:log_rcvr] msg << " ( #{ar[:args]} )" if ar[:args] end case mode when :before msg << " {" when :after msg << " }" if ar.error msg << " #{format(ar[:error], :error )}" if ad[:log_error] != false else msg << " #{format(ar[:result], :result)}" if ad[:log_result] != false end end msg end |