Module: Satori::RTM::Logger

Included in:
Client, WebSocket
Defined in:
lib/satori-rtm-sdk/logger.rb

Overview

Logger for Satori RTM SDK

Constant Summary collapse

ENV_FLAG =
'DEBUG_SATORI_SDK'.freeze

Class Method Summary collapse

Class Method Details

.create_logger(level, output = $stderr) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/satori-rtm-sdk/logger.rb', line 10

def create_logger(level, output = $stderr)
  logger = ::Logger.new(output)
  logger.level = level
  logger.progname = 'satori-rtm-sdk'
  logger.formatter = lambda do |severity, datetime, progname, msg|
    formatted_message = case msg
                        when String
                          msg
                        when Exception
                          format "%s (%s)\n%s",
                                 msg.message, msg.class, (msg.backtrace || []).join("\n")
                        else
                          msg.inspect
                        end
    format "%s [%5s] - %s: %s\n",
           datetime.strftime('%H:%M:%S.%L'),
           severity,
           progname,
           formatted_message
  end
  logger
end

.default_levelKeyword

Returns the default logger level

Returns:

  • (Keyword)

    default logger level



60
61
62
# File 'lib/satori-rtm-sdk/logger.rb', line 60

def default_level
  ENV.key?(ENV_FLAG) ? ::Logger::DEBUG : ::Logger::WARN
end

.included(klass) ⇒ Object



64
65
66
# File 'lib/satori-rtm-sdk/logger.rb', line 64

def included(klass)
  klass.__send__ :include, InstanceMethods
end

.logger::Logger

Returns current logger

Returns:

  • (::Logger)

    logger



53
54
55
# File 'lib/satori-rtm-sdk/logger.rb', line 53

def logger
  @global_logger ||= use_std_logger
end

.use_logger(value) ⇒ void

This method returns an undefined value.

Sets a logger for all Satori RTM SDK classes.

Parameters:

  • value (::Logger)

    logger



46
47
48
# File 'lib/satori-rtm-sdk/logger.rb', line 46

def use_logger(value)
  @global_logger = value
end

.use_std_logger(level = default_level, output = $stderr) ⇒ void

This method returns an undefined value.

Sets a standard logger for all Satori RTM SDK classes.

Parameters:

  • level (Keyword) (defaults to: default_level)

    logger log level

  • output (IO) (defaults to: $stderr)

    logger output



38
39
40
# File 'lib/satori-rtm-sdk/logger.rb', line 38

def use_std_logger(level = default_level, output = $stderr)
  use_logger create_logger(level, output)
end