Class: TcpSyslog
- Inherits:
-
ActiveSupport::BufferedLogger
- Object
- ActiveSupport::BufferedLogger
- TcpSyslog
- Includes:
- Logger::Severity
- Defined in:
- lib/tcp_syslog.rb
Overview
Parts taken frm SyslogLogger gem and ActiveSupport
Constant Summary collapse
- LOGGER_MAP =
Maps Logger warning types to syslog(3) warning types.
{ :unknown => Syslog::LOG_ALERT, :fatal => Syslog::LOG_CRIT, :error => Syslog::LOG_ERR, :warn => Syslog::LOG_WARNING, :info => Syslog::LOG_INFO, :debug => Syslog::LOG_DEBUG }
- LOGGER_LEVEL_MAP =
Maps Logger log levels to their values so we can silence.
{}
- LEVEL_LOGGER_MAP =
Maps Logger log level values to syslog log levels.
{}
Instance Attribute Summary collapse
-
#auto_flushing ⇒ Object
readonly
Log level for Logger compatibility.
-
#facility ⇒ Object
readonly
Log level for Logger compatibility.
-
#host ⇒ Object
readonly
Log level for Logger compatibility.
-
#port ⇒ Object
readonly
Log level for Logger compatibility.
-
#progname ⇒ Object
readonly
Log level for Logger compatibility.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
In Logger, this dumps the raw message; the closest equivalent would be Logger::UNKNOWN.
-
#add(severity, message, progname = nil, &block) ⇒ Object
Almost duplicates Logger#add.
- #close ⇒ Object
-
#flush ⇒ Object
Flush buffered logs to Syslog.
-
#initialize(options = {}) ⇒ TcpSyslog
constructor
Usage : *
options
: A hash with the following options **host
: defaults to ‘localhost’ **port
: defaults to ‘514’ **facility
: defaults to user **progname
: defaults to ‘rails’ **auto_flushing
: number of messages to buffer before flushing **ssl
: defaults to nil *** cert : “/path/to/cert” *** key : “/path/to/key” *** +ca_file : “/path/to/ca_file”. - #socket ⇒ Object
- #ssl? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ TcpSyslog
Usage :
-
options
: A hash with the following options
** host
: defaults to ‘localhost’ ** port
: defaults to ‘514’ ** facility
: defaults to user ** progname
: defaults to ‘rails’ ** auto_flushing
: number of messages to buffer before flushing ** ssl
: defaults to nil *** cert : “/path/to/cert” *** key : “/path/to/key” *** +ca_file : “/path/to/ca_file”
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/tcp_syslog.rb', line 77 def initialize( = {}) @level = LOGGER_LEVEL_MAP[[:level]] || Logger::DEBUG @host = [:host] || 'localhost' @port = [:port] || '514' @facility = [:facility] || Syslog::LOG_USER @progname = [:progname] || 'rails' @buffer = Hash.new { |h,k| h[k] = [] } @socket = {} @auto_flushing = [:auto_flushing] || 1 @local_ip = local_ip @remove_ansi_colors = [:remove_ansi_colors] || true @ssl = [:ssl] return if defined? SYSLOG self.class.const_set :SYSLOG, true end |
Instance Attribute Details
#auto_flushing ⇒ Object (readonly)
Log level for Logger compatibility.
95 96 97 |
# File 'lib/tcp_syslog.rb', line 95 def auto_flushing @auto_flushing end |
#facility ⇒ Object (readonly)
Log level for Logger compatibility.
95 96 97 |
# File 'lib/tcp_syslog.rb', line 95 def facility @facility end |
#host ⇒ Object (readonly)
Log level for Logger compatibility.
95 96 97 |
# File 'lib/tcp_syslog.rb', line 95 def host @host end |
#port ⇒ Object (readonly)
Log level for Logger compatibility.
95 96 97 |
# File 'lib/tcp_syslog.rb', line 95 def port @port end |
#progname ⇒ Object (readonly)
Log level for Logger compatibility.
95 96 97 |
# File 'lib/tcp_syslog.rb', line 95 def progname @progname end |
Instance Method Details
#<<(message) ⇒ Object
In Logger, this dumps the raw message; the closest equivalent would be Logger::UNKNOWN
110 111 112 |
# File 'lib/tcp_syslog.rb', line 110 def <<() add(Logger::UNKNOWN, ) end |
#add(severity, message, progname = nil, &block) ⇒ Object
Almost duplicates Logger#add.
99 100 101 102 103 104 105 106 |
# File 'lib/tcp_syslog.rb', line 99 def add(severity, , progname = nil, &block) severity ||= Logger::UNKNOWN return if @level > severity = clean( || block.call) buffer << {:severity => severity, :body => clean()} auto_flush end |
#close ⇒ Object
114 115 116 117 118 |
# File 'lib/tcp_syslog.rb', line 114 def close flush socket.close @socket[Thread.current] = nil end |
#flush ⇒ Object
Flush buffered logs to Syslog
121 122 123 124 125 126 |
# File 'lib/tcp_syslog.rb', line 121 def flush buffer.each do || log([:severity], [:body]) end clear_buffer end |
#socket ⇒ Object
128 129 130 |
# File 'lib/tcp_syslog.rb', line 128 def socket @socket[Thread.current] ||= new_socket end |
#ssl? ⇒ Boolean
132 133 134 |
# File 'lib/tcp_syslog.rb', line 132 def ssl? !@ssl.nil? end |