Class: Marvin::Logger
- Inherits:
-
Object
- Object
- Marvin::Logger
- Defined in:
- lib/marvin/logger.rb
Constant Summary collapse
- LEVELS =
{ :fatal => 7, :error => 6, :warn => 4, :info => 3, :debug => 0 }
- PREFIXES =
{}
- COLOURS =
{ :fatal => 31, # red :error => 33, # yellow :warn => 35, # magenta :info => 32, # green :debug => 34 # white }
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#level ⇒ Object
Returns the value of attribute level.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
- #close! ⇒ Object
- #debug_exception(exception) ⇒ Object
-
#initialize(path, level = :info, verbose = false) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(path, level = :info, verbose = false) ⇒ Logger
Returns a new instance of Logger.
43 44 45 46 47 |
# File 'lib/marvin/logger.rb', line 43 def initialize(path, level = :info, verbose = false) self.level = level.to_sym self.verbose = verbose self.file = File.open(path, "a+") end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
41 42 43 |
# File 'lib/marvin/logger.rb', line 41 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
41 42 43 |
# File 'lib/marvin/logger.rb', line 41 def level @level end |
#verbose ⇒ Object
Returns the value of attribute verbose.
41 42 43 |
# File 'lib/marvin/logger.rb', line 41 def verbose @verbose end |
Class Method Details
.method_missing(name, *args, &blk) ⇒ Object
13 14 15 16 |
# File 'lib/marvin/logger.rb', line 13 def method_missing(name, *args, &blk) self.setup # Ensure the logger is setup self.logger.send(name, *args, &blk) end |
.setup ⇒ Object
8 9 10 11 |
# File 'lib/marvin/logger.rb', line 8 def setup log_path = Marvin::Settings.root / "log/#{Marvin::Settings.environment}.log" self.logger ||= new(log_path, Marvin::Settings.log_level, Marvin::Settings.verbose) end |
Instance Method Details
#close! ⇒ Object
49 50 51 |
# File 'lib/marvin/logger.rb', line 49 def close! self.file.close end |
#debug_exception(exception) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/marvin/logger.rb', line 64 def debug_exception(exception) error "Exception: #{exception}" exception.backtrace.each do |l| error ">> #{l}" end end |