Class: VGH::Logging
- Inherits:
-
Object
- Object
- VGH::Logging
- Defined in:
- lib/vgh/logging.rb
Overview
Instance Method Summary collapse
-
#defaults ⇒ Object
Defaults.
-
#initialize ⇒ Logging
constructor
Check log file existence.
-
#log ⇒ Object
Global, memoized, lazy initialized instance of a logger.
-
#log_file ⇒ Object
Opens the log file.
-
#validate_log_directory ⇒ Object
Creates a log directory and file if it does not already exist.
Constructor Details
#initialize ⇒ Logging
Check log file existence
36 37 38 39 |
# File 'lib/vgh/logging.rb', line 36 def initialize defaults validate_log_directory end |
Instance Method Details
#defaults ⇒ Object
Defaults
30 31 32 33 |
# File 'lib/vgh/logging.rb', line 30 def defaults @path = '/var/log/vgh.log' @level = Logger::INFO end |
#log ⇒ Object
Global, memoized, lazy initialized instance of a logger
57 58 59 60 61 62 63 |
# File 'lib/vgh/logging.rb', line 57 def log # Logger @log ||= Logger.new(log_file) @log.level = @level @log.datetime_format = "%Y-%m-%d %H:%M " # simplify time output @log end |
#log_file ⇒ Object
Opens the log file
48 49 50 51 52 53 54 |
# File 'lib/vgh/logging.rb', line 48 def log_file begin File.open(@path, File::WRONLY | File::APPEND | File::CREAT) rescue STDOUT end end |
#validate_log_directory ⇒ Object
Creates a log directory and file if it does not already exist
42 43 44 45 |
# File 'lib/vgh/logging.rb', line 42 def validate_log_directory dir = File.dirname(@path) Dir.mkdir(dir) unless File.exists?(dir) end |