Module: Poke::API::Logging

Included in:
Auth::GOOGLE, Auth::PTC, Auth::Ticket, Client, RequestBuilder, Response, Signature
Defined in:
lib/poke-api/logging.rb

Constant Summary collapse

@@loggers =
{}
@@log_level =
:INFO
@@formatter =
proc do |severity, datetime, progname, msg|
  sev_color = ['INFO', 'DEBUG', 'ANY'].include?(severity) ? "\e[32m" : "\e[31m"
   "[\e[36m%s\e[0m]: #{sev_color}%-5s\e[0m > \e[33m%-25s\e[0m --: %s\n" \
    % [datetime.iso8601, severity, progname, msg]
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.formatter=(formatter) ⇒ Object



28
29
30
# File 'lib/poke-api/logging.rb', line 28

def self.formatter=(formatter)
  @@formatter = formatter
end

.log_level=(level) ⇒ Object



24
25
26
# File 'lib/poke-api/logging.rb', line 24

def self.log_level=(level)
  @@log_level = level
end

Instance Method Details

#loggerObject



16
17
18
19
20
21
22
# File 'lib/poke-api/logging.rb', line 16

def logger
  @@loggers[self.class.name] ||= Logger.new(STDOUT).tap do |logger| 
    logger.progname = self.class.name == 'Module' ? self.name : self.class.name
    logger.level = Logger.const_get(@@log_level)
    logger.formatter = @@formatter
  end
end