Class: AIA::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/aia/logging.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_file_path) ⇒ Logging

Returns a new instance of Logging.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aia/logging.rb', line 8

def initialize(log_file_path)
  @logger = if log_file_path
              Logger.new(
                log_file_path,  # path/to/file
                'weekly',       # rotation interval
                'a'             # append to existing file
              )
            else
              # SMELL: Looks like you get logging whether you want it or not
              # TODO: when path is nil create a fake logger
              #       that does nothing
              Logger.new(STDOUT) # Fall back to standard output if path is nil or invalid
            end

  configure_logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/aia/logging.rb', line 6

def logger
  @logger
end

Instance Method Details

#debug(msg) ⇒ Object



44
# File 'lib/aia/logging.rb', line 44

def debug(msg)    = logger.debug(msg)

#error(msg) ⇒ Object



47
# File 'lib/aia/logging.rb', line 47

def error(msg)    = logger.error(msg)

#fatal(msg) ⇒ Object



48
# File 'lib/aia/logging.rb', line 48

def fatal(msg)    = logger.fatal(msg)

#info(msg) ⇒ Object



45
# File 'lib/aia/logging.rb', line 45

def info(msg)     = logger.info(msg)

#prompt_result(prompt, result) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aia/logging.rb', line 25

def prompt_result(prompt, result)
  logger.info( <<~EOS
    PROMPT ID #{prompt.id}
    PATH:     #{prompt.path}
    KEYWORDS: #{prompt.keywords.join(', ')}
      
      #{prompt.to_s}

    RESULT:
    #{result}


  EOS
  )
rescue StandardError => e
  logger.error("Failed to log the result. Error: #{e.message}")
end

#warn(msg) ⇒ Object



46
# File 'lib/aia/logging.rb', line 46

def warn(msg)     = logger.warn(msg)