Class: FlumeLogger
- Inherits:
-
Logger
- Object
- Logger
- FlumeLogger
- Defined in:
- lib/flume-logger/logger.rb,
lib/flume-logger/version.rb
Defined Under Namespace
Classes: Eventserver
Constant Summary collapse
- HOST =
::Socket.gethostname
- PRIORITY =
{ "FATAL" => 0, "ERROR" => 1, "WARN" => 2, "INFO" => 3, "DEBUG" => 4, "TRACE" => 5 }
- VERSION =
"0.1.5"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
- #format_message(severity, time, progname, message) ⇒ Object
-
#initialize(host, port, flume_type = :ng, headers = {}) ⇒ FlumeLogger
constructor
A new instance of FlumeLogger.
Constructor Details
#initialize(host, port, flume_type = :ng, headers = {}) ⇒ FlumeLogger
Returns a new instance of FlumeLogger.
15 16 17 18 19 |
# File 'lib/flume-logger/logger.rb', line 15 def initialize(host, port, flume_type=:ng, headers={}) super(::FlumeLogger::Eventserver.new(host, port, flume_type)) @type = flume_type @headers = headers end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/flume-logger/logger.rb', line 3 def client @client end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flume-logger/logger.rb', line 21 def add(severity, = nil, progname = nil, &block) severity ||= UNKNOWN if severity < @level return true end progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end @logdev.write( (format_severity(severity), Time.now, progname, )) true end |
#format_message(severity, time, progname, message) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/flume-logger/logger.rb', line 40 def (severity, time, progname, ) data = body = case data when Hash @headers = data.clone if @headers.has_key?('message') @headers.delete('message') end data['message'] || "No 'message' in Hash" when String data end if progname @headers['application'] = progname end @headers['host'] ||= HOST event = case @type when :ng $:.push File.("../flume-ng", __FILE__) require 'thrift_source_protocol' @headers['pri'] = severity evt = ThriftFlumeEvent.new() evt.headers = @headers evt.body = body evt when :og $:.push File.("../flume-og", __FILE__) require 'thrift_flume_event_server' evt = ThriftFlumeEvent.new() evt. = time.to_f.to_i * 1000 evt.priority = PRIORITY[severity] evt.body = body evt.host = @headers['host'] evt.nanos = time.usec * 1000 @headers.delete('host') evt.fields = @headers evt end event end |