Class: MCollective::Logger::File_logger
- Defined in:
- lib/mcollective/logger/file_logger.rb
Overview
Impliments a file based logger using the standard ruby logger class
To configure you should set:
- config.logfile
- config.keeplogs defaults to 2097152
- config.max_log_size defaults to 5
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #log(level, from, msg) ⇒ Object
- #reopen ⇒ Object
-
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #start ⇒ Object
- #valid_levels ⇒ Object
Methods inherited from Base
#cycle_level, #initialize, #set_level
Constructor Details
This class inherits a constructor from MCollective::Logger::Base
Instance Method Details
#log(level, from, msg) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/mcollective/logger/file_logger.rb', line 37 def log(level, from, msg) @logger.add(map_level(level)) { "#{from} #{msg}" } rescue # if this fails we probably cant show the user output at all, # STDERR it as last resort warn("#{level}: #{msg}") end |
#reopen ⇒ Object
45 46 47 48 49 50 |
# File 'lib/mcollective/logger/file_logger.rb', line 45 def reopen level = @logger.level @logger.close start @logger.level = level end |
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName
22 23 24 25 26 27 |
# File 'lib/mcollective/logger/file_logger.rb', line 22 def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName @logger.level = map_level(level) rescue Exception => e # rubocop:disable Lint/RescueException @logger.level = ::Logger::DEBUG log(:error, "", "Could not set logging to #{level} using debug instead: #{e.class} #{e}") end |
#start ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/mcollective/logger/file_logger.rb', line 13 def start config = Config.instance @logger = ::Logger.new(config.logfile, config.keeplogs, config.max_log_size) @logger.formatter = ::Logger::Formatter.new set_level(config.loglevel.to_sym) end |
#valid_levels ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mcollective/logger/file_logger.rb', line 29 def valid_levels {:info => ::Logger::INFO, :warn => ::Logger::WARN, :debug => ::Logger::DEBUG, :fatal => ::Logger::FATAL, :error => ::Logger::ERROR} end |