class Fluent::SyslogTlsOutput
Constants
- DEFAULT_FORMAT_TYPE
- SYSLOG_HEADERS
Allow to map keys from record to syslog message headers
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_syslog_tls.rb, line 49 def initialize super require 'syslog_tls/logger' @loggers = {} end
Public Instance Methods
configure(conf)
click to toggle source
This method is called before starting.
Calls superclass method
# File lib/fluent/plugin/out_syslog_tls.rb, line 61 def configure(conf) super @host = conf['host'] @port = conf['port'] @token = conf['token'] @hostname = conf['hostname'] || Socket.gethostname.split('.').first # Determine mapping of record keys to syslog keys @mappings = {} SYSLOG_HEADERS.each do |key_name| conf_key = "#{key_name}_key" @mappings[key_name] = conf[conf_key] if conf.key?(conf_key) end @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) end
emit(tag, es, chain)
click to toggle source
# File lib/fluent/plugin/out_syslog_tls.rb, line 105 def emit(tag, es, chain) chain.next es.each do |time, record| record.each_pair do |_, v| v.force_encoding('utf-8') if v.is_a?(String) end # Check if severity has been provided in record otherwise use INFO # by default. severity = if @mappings.key?(:severity) record[@mappings[:severity]] || 'INFO' else 'INFO' end # Send message to Syslog begin logger(tag).log(severity, format(tag, time, record), time: Time.at(time)) do |header| # Map syslog headers from record @mappings.each do |name, record_key| header.send("#{name}=", record[record_key]) unless record[record_key].nil? end end rescue => e log.error e.to_s end end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_syslog_tls.rb, line 101 def format(tag, time, record) @formatter.format(tag, time, record) end
logger(tag)
click to toggle source
Get logger for given tag
# File lib/fluent/plugin/out_syslog_tls.rb, line 80 def logger(tag) # Try to reuse existing logger @loggers[tag] ||= new_logger(tag) # Create new logger if old one is closed if @loggers[tag].closed? @loggers[tag] = new_logger(tag) end @loggers[tag] end
new_logger(tag)
click to toggle source
# File lib/fluent/plugin/out_syslog_tls.rb, line 92 def new_logger(tag) transport = ::SyslogTls::SSLTransport.new(host, port, ca_cert: ca_cert, cert: cert, key: key, max_retries: 3) logger = ::SyslogTls::Logger.new(transport, token) logger.facility(facility) logger.hostname(hostname) logger.app_name(tag) logger end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_syslog_tls.rb, line 55 def shutdown super @loggers.values.each(&:close) end