Module: Rogu

Extended by:
Rogu
Included in:
Rogu
Defined in:
lib/rogu.rb,
lib/rogu/version.rb,
lib/rogu/concern/logging.rb

Defined Under Namespace

Modules: Concern

Constant Summary collapse

GLOBAL_LOGGER =
Concurrent::AtomicReference.new(create_logger(Logger::WARN))
VERSION =
'0.0.1'

Instance Method Summary collapse

Instance Method Details

#create_logger(level = Logger::FATAL, output = $stderr) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rogu.rb', line 9

def create_logger(level = Logger::FATAL, output = $stderr)
  lambda do |severity, progname, message = nil, &block|
    return false if severity < level

    message = block ? block.call : message
    formatted_message = case message
                        when String
                          message
                        when Exception
                          format "%s (%s)\n%s",
                                 message.message,
                                 message.class,
                                 (message.backtrace || []).join("\n")
                        else
                          message.inspect
                        end

    output.print format "%5s -- %s: %s\n",
                        Logger::SEV_LABEL[severity],
                        progname,
                        formatted_message
    true
  end
end

#loggerObject



41
42
43
# File 'lib/rogu.rb', line 41

def logger
  GLOBAL_LOGGER.value
end

#logger=(log) ⇒ Object



45
46
47
# File 'lib/rogu.rb', line 45

def logger=(log)
  GLOBAL_LOGGER.value = log
end

#use_logger(level = Logger::FATAL, output = $stderr) ⇒ Object

Use logger created by #create_logger to log messages.



35
36
37
# File 'lib/rogu.rb', line 35

def use_logger(level = Logger::FATAL, output = $stderr)
  Rogu.logger = create_logger(level, output)
end