Module: Exceptional::Log
- Included in:
- Exceptional
- Defined in:
- lib/exceptional/log.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
- #log!(msg, level = 'info') ⇒ Object
- #setup_log(log_dir, log_level = Logger::INFO) ⇒ Object
- #to_stderr(msg) ⇒ Object
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
6 7 8 |
# File 'lib/exceptional/log.rb', line 6 def log @log end |
Instance Method Details
#log!(msg, level = 'info') ⇒ Object
29 30 31 32 |
# File 'lib/exceptional/log.rb', line 29 def log!(msg, level = 'info') to_log level, msg to_stderr msg end |
#setup_log(log_dir, log_level = Logger::INFO) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/exceptional/log.rb', line 8 def setup_log(log_dir, log_level = Logger::INFO) begin Dir.mkdir(log_dir) unless File.directory?(log_dir) log_path = File.join(log_dir, "/exceptional.log") log = Logger.new log_path log.level = log_level allowed_log_levels = ['debug', 'info', 'warn', 'error', 'fatal'] if log_level && allowed_log_levels.include?(log_level) log.level = eval("Logger::#{log_level.upcase}") end @log = log rescue Exception => e raise Exceptional::Config::ConfigurationException.new("Unable to create log file #{log_path} #{e.message}") end end |
#to_stderr(msg) ⇒ Object
34 35 36 |
# File 'lib/exceptional/log.rb', line 34 def to_stderr(msg) STDERR.puts (msg) end |