Class: ActiveTracker::RailsLogger
- Inherits:
-
Object
- Object
- ActiveTracker::RailsLogger
- Defined in:
- lib/active_tracker/rails_logger.rb
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil) ⇒ Object (also: #log)
- #debug(message) ⇒ Object
- #debug! ⇒ Object
- #debug? ⇒ Boolean
- #error(message = "") ⇒ Object
- #error! ⇒ Object
- #error? ⇒ Boolean
- #fatal(message = "") ⇒ Object
- #fatal! ⇒ Object
- #fatal? ⇒ Boolean
- #formatter ⇒ Object
- #info(message = "") ⇒ Object
- #info! ⇒ Object
- #info? ⇒ Boolean
-
#initialize ⇒ RailsLogger
constructor
A new instance of RailsLogger.
- #level ⇒ Object
- #level=(severity) ⇒ Object
- #lines ⇒ Object
- #reset ⇒ Object
- #silence(*args) {|_self| ... } ⇒ Object
- #warn(message = "") ⇒ Object
- #warn! ⇒ Object
- #warn? ⇒ Boolean
Constructor Details
#initialize ⇒ RailsLogger
Returns a new instance of RailsLogger.
8 9 10 |
# File 'lib/active_tracker/rails_logger.rb', line 8 def initialize reset end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object Also known as: log
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_tracker/rails_logger.rb', line 20 def add(severity, = nil, progname = nil) severity ||= UNKNOWN return true if severity < level if .nil? if block_given? = yield else = progname end end @lines << "#{}\n" true end |
#debug(message) ⇒ Object
48 49 50 51 52 |
# File 'lib/active_tracker/rails_logger.rb', line 48 def debug() = yield if block_given? return if .blank? add(DEBUG, ) end |
#debug! ⇒ Object
38 |
# File 'lib/active_tracker/rails_logger.rb', line 38 def debug!; self.level = DEBUG; end |
#debug? ⇒ Boolean
37 |
# File 'lib/active_tracker/rails_logger.rb', line 37 def debug?; @level <= DEBUG; end |
#error(message = "") ⇒ Object
73 74 75 76 77 |
# File 'lib/active_tracker/rails_logger.rb', line 73 def error( = "") = yield if block_given? return if .blank? add(ERROR, ) end |
#error! ⇒ Object
44 |
# File 'lib/active_tracker/rails_logger.rb', line 44 def error!; self.level = ERROR; end |
#error? ⇒ Boolean
43 |
# File 'lib/active_tracker/rails_logger.rb', line 43 def error?; @level <= ERROR; end |
#fatal(message = "") ⇒ Object
79 80 81 82 83 |
# File 'lib/active_tracker/rails_logger.rb', line 79 def fatal( = "") = yield if block_given? return if .blank? add(FATAL, ) end |
#fatal! ⇒ Object
46 |
# File 'lib/active_tracker/rails_logger.rb', line 46 def fatal!; self.level = FATAL; end |
#fatal? ⇒ Boolean
45 |
# File 'lib/active_tracker/rails_logger.rb', line 45 def fatal?; @level <= FATAL; end |
#formatter ⇒ Object
112 113 114 |
# File 'lib/active_tracker/rails_logger.rb', line 112 def formatter ActiveSupport::Logger::SimpleFormatter end |
#info(message = "") ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_tracker/rails_logger.rb', line 54 def info( = "") = yield if block_given? return if .blank? add(INFO, ) # matches = message.match(/Completed (\d+) .*? in (\d+)ms/) # if matches # @status = matches[1] # @time_taken = matches[2] # end # @lines << message if info? && @recording end |
#info! ⇒ Object
40 |
# File 'lib/active_tracker/rails_logger.rb', line 40 def info!; self.level = INFO; end |
#info? ⇒ Boolean
39 |
# File 'lib/active_tracker/rails_logger.rb', line 39 def info?; @level <= INFO; end |
#level ⇒ Object
85 86 87 |
# File 'lib/active_tracker/rails_logger.rb', line 85 def level @level end |
#level=(severity) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_tracker/rails_logger.rb', line 89 def level=(severity) if severity.is_a?(Integer) @level = severity else case severity.to_s.downcase when 'debug' @level = DEBUG when 'info' @level = INFO when 'warn' @level = WARN when 'error' @level = ERROR when 'fatal' @level = FATAL when 'unknown' @level = UNKNOWN else raise ArgumentError, "invalid log level: #{severity}" end end end |
#lines ⇒ Object
16 17 18 |
# File 'lib/active_tracker/rails_logger.rb', line 16 def lines @lines end |
#reset ⇒ Object
12 13 14 |
# File 'lib/active_tracker/rails_logger.rb', line 12 def reset @lines = "" end |
#silence(*args) {|_self| ... } ⇒ Object
116 117 118 |
# File 'lib/active_tracker/rails_logger.rb', line 116 def silence(*args) yield self end |
#warn(message = "") ⇒ Object
67 68 69 70 71 |
# File 'lib/active_tracker/rails_logger.rb', line 67 def warn( = "") = yield if block_given? return if .blank? add(WARN, ) end |
#warn! ⇒ Object
42 |
# File 'lib/active_tracker/rails_logger.rb', line 42 def warn!; self.level = WARN; end |
#warn? ⇒ Boolean
41 |
# File 'lib/active_tracker/rails_logger.rb', line 41 def warn?; @level <= WARN; end |