Class: SeleniumStatistics::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logger::Severity
Defined in:
lib/selenium_statistics/logger.rb

Overview

Examples:

Enable full logging

SeleniumStatistics.logger.level = :debug

Log to file

SeleniumStatistics.logger.output = 'watir.log'

Use logger manually

SeleniumStatistics.logger.info('This is info message')
SeleniumStatistics.logger.warn('This is warning message')

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



30
31
32
# File 'lib/selenium_statistics/logger.rb', line 30

def initialize
  @logger = create_logger($stdout)
end

Instance Method Details

#deprecate(old, new) ⇒ Object

Marks code as deprecated with replacement.

Parameters:

  • old (String)
  • new (String)


92
93
94
# File 'lib/selenium_statistics/logger.rb', line 92

def deprecate(old, new)
  warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
end

#ioObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns IO object used by logger internally.

Normally, we would have never needed it, but we want to use it as IO object for all child processes to ensure their output is redirected there.

It is only used in debug level, in other cases output is suppressed.



82
83
84
# File 'lib/selenium_statistics/logger.rb', line 82

def io
  @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
end

#level=(severity) ⇒ Object

For Ruby < 2.3 compatibility Based on github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/selenium_statistics/logger.rb', line 48

def level=(severity)
  if severity.is_a?(Integer)
    @logger.level = severity
  else
    case severity.to_s.downcase
    when 'debug'.freeze
      @logger.level = DEBUG
    when 'info'.freeze
      @logger.level = INFO
    when 'warn'.freeze
      @logger.level = WARN
    when 'error'.freeze
      @logger.level = ERROR
    when 'fatal'.freeze
      @logger.level = FATAL
    when 'unknown'.freeze
      @logger.level = UNKNOWN
    else
      raise ArgumentError, "invalid log level: #{severity}"
    end
  end
end

#output=(io) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/selenium_statistics/logger.rb', line 34

def output=(io)
  # `Logger#reopen` was added in Ruby 2.3
  if @logger.respond_to?(:reopen)
    @logger.reopen(io)
  else
    @logger = create_logger(io)
  end
end