Class: Raykit::Logging
- Inherits:
-
Object
- Object
- Raykit::Logging
- Defined in:
- lib/raykit/logging.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#loggers ⇒ Object
Returns the value of attribute loggers.
-
#severity ⇒ Object
Logger::Severity DEBUG,ERROR,FATAL,INFO,UNKOWN,WARN defaults to WARN.
Instance Method Summary collapse
- #get_logger(context) ⇒ Object
-
#initialize ⇒ Logging
constructor
A new instance of Logging.
- #log(context, level, message) ⇒ Object
- #set_severity_as_string(severity) ⇒ Object
Constructor Details
#initialize ⇒ Logging
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
#enabled ⇒ Object
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/raykit/logging.rb', line 8 def enabled @enabled end |
#loggers ⇒ Object
Returns the value of attribute loggers.
8 9 10 |
# File 'lib/raykit/logging.rb', line 8 def loggers @loggers end |
#severity ⇒ Object
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, ) if @enabled logger = get_logger(context) case level when Logger::Severity::DEBUG logger.debug() when Logger::Severity::INFO logger.info() when Logger::Severity::WARN logger.warn() when Logger::Severity::ERROR logger.error() when Logger::Severity::FATAL logger.fatal() else logger.unknown() 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 |