Class: Progstr::LoggerDevice
- Inherits:
-
Object
- Object
- Progstr::LoggerDevice
- Defined in:
- lib/progstr/logger_device.rb
Constant Summary collapse
- LEVELS_MAP =
{ "INFO" => :info, "WARN" => :warning, "ERROR" => :error, "FATAL" => :fatal }
Instance Method Summary collapse
- #close ⇒ Object
- #formatter ⇒ Object
-
#initialize(source = nil) ⇒ LoggerDevice
constructor
A new instance of LoggerDevice.
- #resolve_level(severity) ⇒ Object
- #resolve_source(progname) ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize(source = nil) ⇒ LoggerDevice
Returns a new instance of LoggerDevice.
9 10 11 |
# File 'lib/progstr/logger_device.rb', line 9 def initialize(source = nil) @source = source || "Unknown" end |
Instance Method Details
#close ⇒ Object
19 20 |
# File 'lib/progstr/logger_device.rb', line 19 def close end |
#formatter ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/progstr/logger_device.rb', line 22 def formatter proc do |severity, datetime, progname, msg| level = resolve_level(severity) unless level.nil? Progstr::LogMessage.new :text => msg, :level => resolve_level(severity), :time => datetime, :source => resolve_source(progname) else nil end end end |
#resolve_level(severity) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/progstr/logger_device.rb', line 36 def resolve_level(severity) level = LEVELS_MAP[severity] if level.nil? && Progstr.log_debug_events level = :info end level end |
#resolve_source(progname) ⇒ Object
44 45 46 |
# File 'lib/progstr/logger_device.rb', line 44 def resolve_source(progname) progname || @source end |