Class: Rack::Bug::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/logger.rb

Constant Summary collapse

DEBUG =
0
INFO =
1
WARN =
2
ERROR =
3
FATAL =
4
UNKNOWN =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, path) ⇒ Logger

Returns a new instance of Logger.



3
4
5
6
7
# File 'lib/rack/bug/logger.rb', line 3

def initialize(level, path)
  @level = level
  @log_path = path
  @logfile = nil
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



9
10
11
# File 'lib/rack/bug/logger.rb', line 9

def level
  @level
end

Instance Method Details

#debugObject



34
# File 'lib/rack/bug/logger.rb', line 34

def debug;   log(DEBUG,   yield) if @level >= DEBUG;   end

#errorObject



37
# File 'lib/rack/bug/logger.rb', line 37

def error;   log(ERROR,   yield) if @level >= ERROR;   end

#fatalObject



38
# File 'lib/rack/bug/logger.rb', line 38

def fatal;   log(FATAL,   yield) if @level >= FATAL;   end

#infoObject



35
# File 'lib/rack/bug/logger.rb', line 35

def info;    log(INFO,    yield) if @level >= INFO;    end

#log(severity, message) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rack/bug/logger.rb', line 18

def log(severity, message)
  if defined? Rails and not Rails.logger.nil?
    Rails.logger.add(severity, "[Rack::Bug]: " + message)
  end

  if severity >= @level
    logfile.puts(message)
  end
end

#logfileObject



28
29
30
31
32
# File 'lib/rack/bug/logger.rb', line 28

def logfile
  @logfile ||= File::open(path, "a+")
rescue
  $stderr
end

#unknownObject



39
# File 'lib/rack/bug/logger.rb', line 39

def unknown; log(UNKNOWN, yield) if @level >= UNKNOWN; end

#warnObject



36
# File 'lib/rack/bug/logger.rb', line 36

def warn;    log(WARN,    yield) if @level >= WARN;    end