Module: Uberinstaller::Loggable
- Included in:
- Commander, Exception::Exception, Installer, PackageManager::Base, Parser, Platform, Runner
- Defined in:
- lib/uberinstaller/logger.rb
Overview
Handle application log
Class Attribute Summary collapse
-
.level ⇒ Object
Log output level.
-
.log_path ⇒ Object
Path in which log files are saved ( default STDOUT ).
Class Method Summary collapse
-
.configure_logger_for(classname) ⇒ Object
Create and configure a logger for the specified Class.
-
.logger_for(classname) ⇒ Object
Return the logger for a specific Class.
Instance Method Summary collapse
-
#logger ⇒ Object
Global, memoized, lazy initialized instance of a logger.
Class Attribute Details
.level ⇒ Object
Log output level. Can be one of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR ( default Logger::ERROR )
35 36 37 |
# File 'lib/uberinstaller/logger.rb', line 35 def level @level end |
.log_path ⇒ Object
Path in which log files are saved ( default STDOUT )
35 |
# File 'lib/uberinstaller/logger.rb', line 35 attr_accessor :level, :log_path |
Class Method Details
.configure_logger_for(classname) ⇒ Object
Create and configure a logger for the specified Class
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/uberinstaller/logger.rb', line 49 def configure_logger_for(classname) # handle case in which log path does not exists begin logger = Logger.new(@log_path) rescue Errno::ENOENT FileUtils.mkdir_p File.dirname @log_path retry end logger.progname = classname logger.level = @level logger.formatter = proc { |severity, datetime, progname, msg| case severity when 'DEBUG' spaciator = " *" after_space = "" colored = "white" extra = "" when 'INFO' spaciator = " **" after_space = " " colored = "" extra = "" when 'WARN' spaciator = " ***" after_space = " " colored = "yellow" extra = "" when 'ERROR' spaciator = " ****" after_space = "" colored = "red" extra = "" when 'FATAL' spaciator = "*****" after_space = "" colored = "red" extra = "bold" else spaciator = " " after_space = "" colored = "" extra = "" end formatted_output = " #{spaciator} [#{severity}]#{after_space} [#{datetime}] -- #{msg} { #{progname} }\n" if @log_path == STDOUT or @log_path == STDERR if colored.empty? formatted_output else if extra.empty? formatted_output.send(colored) else formatted_output.send(colored).send(extra) end end else formatted_output end } logger end |
.logger_for(classname) ⇒ Object
Return the logger for a specific Class. If the instance is not found, creates it.
41 42 43 |
# File 'lib/uberinstaller/logger.rb', line 41 def logger_for(classname) @loggers[classname] ||= configure_logger_for(classname) end |
Instance Method Details
#logger ⇒ Object
Global, memoized, lazy initialized instance of a logger
This is the magical bit that gets mixed into your classes. Respond to Logger function.
25 26 27 28 |
# File 'lib/uberinstaller/logger.rb', line 25 def logger classname = (self.is_a? Module) ? self : self.class.name @logger ||= Loggable.logger_for(classname) end |