Class: Insight::Logger
- Inherits:
-
Object
- Object
- Insight::Logger
- Defined in:
- lib/insight/logger.rb
Constant Summary collapse
- DEBUG =
0
- INFO =
1
- WARN =
2
- ERROR =
3
- FATAL =
4
- UNKNOWN =
5
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #debug ⇒ Object
- #error ⇒ Object
- #fatal ⇒ Object
- #info ⇒ Object
-
#initialize(level, path) ⇒ Logger
constructor
A new instance of Logger.
- #log(severity, message) ⇒ Object
- #logfile ⇒ Object
- #unknown ⇒ Object
- #warn ⇒ Object
Constructor Details
#initialize(level, path) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 7 |
# File 'lib/insight/logger.rb', line 3 def initialize(level, path) @level = level @log_path = path @logfile = nil end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
9 10 11 |
# File 'lib/insight/logger.rb', line 9 def level @level end |
Instance Method Details
#debug ⇒ Object
35 |
# File 'lib/insight/logger.rb', line 35 def debug; log(DEBUG, yield) end |
#error ⇒ Object
38 |
# File 'lib/insight/logger.rb', line 38 def error; log(ERROR, yield) end |
#fatal ⇒ Object
39 |
# File 'lib/insight/logger.rb', line 39 def fatal; log(FATAL, yield) end |
#info ⇒ Object
36 |
# File 'lib/insight/logger.rb', line 36 def info; log(INFO, yield) end |
#log(severity, message) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/insight/logger.rb', line 18 def log(severity, ) = .inspect unless String === return unless severity >= @level if defined? Rails and Rails.respond_to?(:logger) and not Rails.logger.nil? Rails.logger.add(severity, "[Insight]: " + ) end logfile.puts() end |
#logfile ⇒ Object
29 30 31 32 33 |
# File 'lib/insight/logger.rb', line 29 def logfile @logfile ||= File::open(@log_path, "a+") rescue $stderr end |
#unknown ⇒ Object
40 |
# File 'lib/insight/logger.rb', line 40 def unknown; log(UNKNOWN, yield) end |
#warn ⇒ Object
37 |
# File 'lib/insight/logger.rb', line 37 def warn; log(WARN, yield) end |