Class: Imap::Backup::Logger
- Inherits:
-
Object
- Object
- Imap::Backup::Logger
- Includes:
- Singleton
- Defined in:
- lib/imap/backup/logger.rb
Overview
Wraps the standard logger, providing configuration and sanitization
Instance Attribute Summary collapse
-
#logger ⇒ Logger
readonly
The configured Logger.
Class Method Summary collapse
- .count(verbose) ⇒ Object
-
.logger ⇒ Imap::Backup::Logger
The singleton instance of this class.
-
.sanitize_stderr(&block) ⇒ void
Wraps a block, filtering output to standard error, hidng passwords and outputs the results to standard out.
-
.setup_logging(options = {}) ⇒ Hash
The options without the :quiet and :verbose keys.
Instance Method Summary collapse
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
72 73 74 75 |
# File 'lib/imap/backup/logger.rb', line 72 def initialize @logger = ::Logger.new($stdout) $stdout.sync = true end |
Instance Attribute Details
#logger ⇒ Logger (readonly)
Returns the configured Logger.
70 71 72 |
# File 'lib/imap/backup/logger.rb', line 70 def logger @logger end |
Class Method Details
.count(verbose) ⇒ Object
65 66 67 |
# File 'lib/imap/backup/logger.rb', line 65 def self.count(verbose) verbose.reduce(1) { |acc, v| acc + (v ? 1 : -1) } end |
.logger ⇒ Imap::Backup::Logger
Returns the singleton instance of this class.
15 16 17 |
# File 'lib/imap/backup/logger.rb', line 15 def self.logger Logger.instance.logger end |
.sanitize_stderr(&block) ⇒ void
This method returns an undefined value.
Wraps a block, filtering output to standard error, hidng passwords and outputs the results to standard out
54 55 56 57 58 59 60 61 62 |
# File 'lib/imap/backup/logger.rb', line 54 def self.sanitize_stderr(&block) sanitizer = Text::Sanitizer.new($stdout) previous_stderr = $stderr $stderr = sanitizer block.call ensure sanitizer.flush $stderr = previous_stderr end |
.setup_logging(options = {}) ⇒ Hash
Returns the options without the :quiet and :verbose keys.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/imap/backup/logger.rb', line 30 def self.setup_logging( = {}) copy = .clone quiet = copy.delete(:quiet) verbose = copy.delete(:verbose) || [] verbose_count = count(verbose) level = case when quiet ::Logger::Severity::UNKNOWN when verbose_count >= 2 ::Logger::Severity::DEBUG else ::Logger::Severity::INFO end logger.level = level Net::IMAP.debug = (verbose_count >= 3) copy end |