Class: Raykit::Logging

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogging

Returns a new instance of Logging.



14
15
16
17
18
# File 'lib/raykit/logging.rb', line 14

def initialize
  @enabled = true
  @loggers = {}
  @severity = ::Logger::Severity::WARN
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



8
9
10
# File 'lib/raykit/logging.rb', line 8

def enabled
  @enabled
end

#loggersObject

Returns the value of attribute loggers.



8
9
10
# File 'lib/raykit/logging.rb', line 8

def loggers
  @loggers
end

#severityObject

Logger::Severity DEBUG,ERROR,FATAL,INFO,UNKOWN,WARN defaults to WARN



12
13
14
# File 'lib/raykit/logging.rb', line 12

def severity
  @severity
end

Instance Method Details

#get_logger(context) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/raykit/logging.rb', line 27

def get_logger(context)
  unless loggers.key?(context)
    Dir.chdir(Environment.get_dev_dir("log")) do
      # start the log over whenever the log exceeds 100 megabytes in size
      loggers[context] = Logger.new("#{context}.log", 0, 100 * 1024 * 1024)
    end
  end
  loggers[context]
end

#log(context, level, message) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/raykit/logging.rb', line 37

def log(context, level, message)
  if @enabled
    logger = get_logger(context)
    case level
    when Logger::Severity::DEBUG
      logger.debug(message)
    when Logger::Severity::INFO
      logger.info(message)
    when Logger::Severity::WARN
      logger.warn(message)
    when Logger::Severity::ERROR
      logger.error(message)
    when Logger::Severity::FATAL
      logger.fatal(message)
    else
      logger.unknown(message)
    end
  end
end

#set_severity_as_string(severity) ⇒ Object



20
21
22
23
24
25
# File 'lib/raykit/logging.rb', line 20

def set_severity_as_string(severity)
  @severity = ::Logger::Severity::DEBUG if severity == "debug"
  @severity = ::Logger::Severity::INFO if severity == "info"
  @severity = ::Logger::Severity::WARN if severity == "warn"
  @severity = ::Logger::Severity::ERROR if severity == "error"
end