Parent

Files

Class Index [+]

Quicksearch

Logging

@author Sylvain Desbureaux Most of work grabbed from nuby on rails Hodel 3000 logger nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us.

I’ve added the way to retrieve the method which sent the log and the class via caller method.

I’ve also taken care to take the next one in caller if the methode is lik each, block,…

In your environmment file(s) (development.rb, test.rb,…) you’ll need to add that in order to use this logger: @example

  require File.dirname(__FILE__) + "/../../app/models/logging"
  config.logger = Logging.new(config.paths.log.first )

And you’ll need to put this file (renammed logging.rb here) in app/models folder

Public Instance Methods

format_message(severity, timestamp, progname, msg) click to toggle source
    # File lib/easy_logger/logging_example.rb, line 17
17:   def format_message(severity, timestamp, progname, msg)
18:     i = 2
19:     methode = caller[i].split('`')[1].split("'")[0]
20:     each_true = false
21:     puts methode if methode == "each"
22:     each_true = true if methode == ""
23:     while methode == "debug" || methode == "info" || methode == "error" || methode.split(' ')[0] == "each"
24:       i += 1
25:       methode = caller[i].split('`')[1].split("'")[0]
26:       puts methode if each_true
27:     end
28:     methode = methode.split(' ')[0] == "block" ? methode.split(' ')[1].center(17) : methode.center(17)
29:     objecte = caller[i].split(':')[0].split('/')[1].split('.')[0].camelize.center(16)
30:     "#{timestamp.strftime("%d %b %H:%M:%S")}|rails[#{$PID}]|#{severity.center(8)}|#{objecte}|#{methode}| #{msg2str(msg).gsub(/\n/, '').lstrip}\n"
31:   end
msg2str(msg) click to toggle source
    # File lib/easy_logger/logging_example.rb, line 34
34:   def msg2str(msg)
35:     case msg
36:     when ::String
37:       msg
38:     when ::Exception
39:       "#{ msg.message } (#{ msg.class }): " <<
40:       (msg.backtrace || []).join(" | ")
41:     else
42:       msg.inspect
43:     end
44:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.