Class: Imap::Backup::Logger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/imap/backup/logger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.


42
43
44
45
# File 'lib/imap/backup/logger.rb', line 42

def initialize
  @logger = ::Logger.new($stdout)
  $stdout.sync = true
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.


40
41
42
# File 'lib/imap/backup/logger.rb', line 40

def logger
  @logger
end

Class Method Details

.loggerObject


11
12
13
# File 'lib/imap/backup/logger.rb', line 11

def self.logger
  Logger.instance.logger
end

.sanitize_stderrObject


30
31
32
33
34
35
36
37
38
# File 'lib/imap/backup/logger.rb', line 30

def self.sanitize_stderr
  sanitizer = Sanitizer.new($stdout)
  previous_stderr = $stderr
  $stderr = sanitizer
  yield
ensure
  sanitizer.flush
  $stderr = previous_stderr
end

.setup_logging(options = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/imap/backup/logger.rb', line 15

def self.setup_logging(options = {})
  level =
    case
    when options[:quiet]
      ::Logger::Severity::UNKNOWN
    when options[:verbose]
      ::Logger::Severity::DEBUG
    else
      ::Logger::Severity::INFO
    end
  logger.level = level
  debug = level == ::Logger::Severity::DEBUG
  Net::IMAP.debug = debug
end