Class: UsageTracker::Log
- Inherits:
-
Object
- Object
- UsageTracker::Log
- Defined in:
- lib/usage_tracker/log.rb
Constant Summary collapse
- Levels =
{ :fatal => Logger::FATAL, :erorr => Logger::ERROR, :warn => Logger::WARN, :info => Logger::INFO, :debug => Logger::DEBUG }
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #level=(level) ⇒ Object
- #open ⇒ Object
- #rotate ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
20 21 22 |
# File 'lib/usage_tracker/log.rb', line 20 def initialize open end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/usage_tracker/log.rb', line 14 def path @path end |
Instance Method Details
#close ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/usage_tracker/log.rb', line 41 def close return unless @logger @logger.info 'Log closed' @logger.close @logger = nil end |
#level=(level) ⇒ Object
54 55 56 57 58 |
# File 'lib/usage_tracker/log.rb', line 54 def level=(level) level = level.to_sym raise "Invalid log level" unless Levels.keys.include?(level) @logger.level = Levels[level] end |
#open ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/usage_tracker/log.rb', line 32 def open @logger = Logger.new(path.to_s) @logger.formatter = Logger::Formatter.new @logger.info 'Log opened' rescue raise Error, "Cannot open log file #{path}" end |
#rotate ⇒ Object
49 50 51 52 |
# File 'lib/usage_tracker/log.rb', line 49 def rotate close open end |