Class: Progstr::LoggerDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/progstr/logger_device.rb

Constant Summary collapse

LEVELS_MAP =
{
  "INFO" => :info,
  "WARN" => :warning,
  "ERROR" => :error,
  "FATAL" => :fatal
}

Instance Method Summary collapse

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

#closeObject



19
20
# File 'lib/progstr/logger_device.rb', line 19

def close
end

#formatterObject



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

#write(message) ⇒ Object



13
14
15
16
17
# File 'lib/progstr/logger_device.rb', line 13

def write(message)
  if !message.nil?
    Progstr::Client::send(message)
  end
end