Class: LogStasher::Device::Syslog

Inherits:
Object
  • Object
show all
Includes:
LogStasher::Device
Defined in:
lib/logstasher/device/syslog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogStasher::Device

factory, stringify_keys

Constructor Details

#initialize(options = {}) ⇒ Syslog

Returns a new instance of Syslog.



13
14
15
16
17
18
# File 'lib/logstasher/device/syslog.rb', line 13

def initialize(options = {})
  raw_options = default_options.merge(stringify_keys(options))

  @options = parse_options(raw_options)
  open_syslog
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/logstasher/device/syslog.rb', line 11

def options
  @options
end

Instance Method Details

#closeObject



20
21
22
# File 'lib/logstasher/device/syslog.rb', line 20

def close
  ::Syslog.close rescue nil
end

#closed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/logstasher/device/syslog.rb', line 24

def closed?
  !::Syslog.opened?
end

#facilityObject



28
29
30
# File 'lib/logstasher/device/syslog.rb', line 28

def facility
  options['facility']
end

#flagsObject



32
33
34
# File 'lib/logstasher/device/syslog.rb', line 32

def flags
  options['flags']
end

#identityObject



36
37
38
# File 'lib/logstasher/device/syslog.rb', line 36

def identity
  options['identity']
end

#priorityObject



40
41
42
# File 'lib/logstasher/device/syslog.rb', line 40

def priority
  options['priority']
end

#write(log) ⇒ Object



44
45
46
47
48
49
# File 'lib/logstasher/device/syslog.rb', line 44

def write(log)
  fail ::RuntimeError, 'Syslog has been closed.' if closed?
  fail ::RuntimeError, 'Syslog re-configured unexpectedly.' if syslog_config_changed?

  ::Syslog.log(priority, '%s', log)
end