Class: ActiveTracker::RailsLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tracker/rails_logger.rb

Instance Method Summary collapse

Constructor Details

#initializeRailsLogger

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, message = nil, progname = nil)
  severity ||= UNKNOWN
  return true if severity < level

  if message.nil?
    if block_given?
      message = yield
    else
      message = progname
    end
  end

  @lines << "#{message}\n"
  true
end

#debug(message) ⇒ Object



48
49
50
51
52
# File 'lib/active_tracker/rails_logger.rb', line 48

def debug(message)
  message = yield if block_given?
  return if message.blank?
  add(DEBUG, message)
end

#debug!Object



38
# File 'lib/active_tracker/rails_logger.rb', line 38

def debug!; self.level = DEBUG; end

#debug?Boolean

Returns:

  • (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(message = "")
  message = yield if block_given?
  return if message.blank?
  add(ERROR, message)
end

#error!Object



44
# File 'lib/active_tracker/rails_logger.rb', line 44

def error!; self.level = ERROR; end

#error?Boolean

Returns:

  • (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(message = "")
  message = yield if block_given?
  return if message.blank?
  add(FATAL, message)
end

#fatal!Object



46
# File 'lib/active_tracker/rails_logger.rb', line 46

def fatal!; self.level = FATAL; end

#fatal?Boolean

Returns:

  • (Boolean)


45
# File 'lib/active_tracker/rails_logger.rb', line 45

def fatal?; @level <= FATAL; end

#formatterObject



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(message = "")
  message = yield if block_given?
  return if message.blank?
  add(INFO, message)

  # 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

Returns:

  • (Boolean)


39
# File 'lib/active_tracker/rails_logger.rb', line 39

def info?; @level <= INFO; end

#levelObject



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

#linesObject



16
17
18
# File 'lib/active_tracker/rails_logger.rb', line 16

def lines
  @lines
end

#resetObject



12
13
14
# File 'lib/active_tracker/rails_logger.rb', line 12

def reset
  @lines = ""
end

#silence(*args) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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(message = "")
  message = yield if block_given?
  return if message.blank?
  add(WARN, message)
end

#warn!Object



42
# File 'lib/active_tracker/rails_logger.rb', line 42

def warn!; self.level = WARN; end

#warn?Boolean

Returns:

  • (Boolean)


41
# File 'lib/active_tracker/rails_logger.rb', line 41

def warn?; @level <= WARN; end