Class: Fluent::Logger::FluentLogger
- Inherits:
-
LoggerBase
- Object
- LoggerBase
- Fluent::Logger::FluentLogger
- Extended by:
- Finalizable
- Defined in:
- lib/fluent/logger/fluent_logger.rb
Defined Under Namespace
Modules: Finalizable
Constant Summary collapse
- BUFFER_LIMIT =
8*1024*1024
- RECONNECT_WAIT =
0.5
- RECONNECT_WAIT_INCR_RATE =
1.5
- RECONNECT_WAIT_MAX =
60
- RECONNECT_WAIT_MAX_COUNT =
(1..100).inject(RECONNECT_WAIT_MAX / RECONNECT_WAIT) {|r,i| break i + 1 if r < RECONNECT_WAIT_INCR_RATE r / RECONNECT_WAIT_INCR_RATE }
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #close ⇒ Object
- #connect? ⇒ Boolean
- #finalize ⇒ Object
-
#initialize(tag_prefix, *args) ⇒ FluentLogger
constructor
A new instance of FluentLogger.
- #post(tag, map, time = nil) ⇒ Object
Methods included from Finalizable
Methods inherited from LoggerBase
Constructor Details
#initialize(tag_prefix, *args) ⇒ FluentLogger
Returns a new instance of FluentLogger.
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 85 86 87 88 89 90 91 92 |
# File 'lib/fluent/logger/fluent_logger.rb', line 58 def initialize(tag_prefix, *args) super() = { :host => 'localhost', :port => 24224 } case args.first when String, Symbol # backward compatible [:host] = args[0] [:port] = args[1] if args[1] when Hash .update args.first end @tag_prefix = tag_prefix @host = [:host] @port = [:port] @mon = Monitor.new @pending = nil @connect_error_history = [] @limit = [:buffer_limit] || BUFFER_LIMIT @logger = [:logger] || ::Logger.new(STDERR) begin connect! rescue @logger.error "Failed to connect fluentd: #{$!}" @logger.error "Connection will be retried." end end |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
94 95 96 |
# File 'lib/fluent/logger/fluent_logger.rb', line 94 def limit @limit end |
#logger ⇒ Object
Returns the value of attribute logger.
94 95 96 |
# File 'lib/fluent/logger/fluent_logger.rb', line 94 def logger @logger end |
Instance Method Details
#close ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fluent/logger/fluent_logger.rb', line 102 def close @mon.synchronize { if @pending begin send_data(@pending) rescue @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}") end end @con.close if connect? @con = nil @pending = nil } self end |
#connect? ⇒ Boolean
118 119 120 |
# File 'lib/fluent/logger/fluent_logger.rb', line 118 def connect? !!@con end |
#finalize ⇒ Object
122 123 124 |
# File 'lib/fluent/logger/fluent_logger.rb', line 122 def finalize close end |
#post(tag, map, time = nil) ⇒ Object
96 97 98 99 100 |
# File 'lib/fluent/logger/fluent_logger.rb', line 96 def post(tag, map, time=nil) time ||= Time.now tag = "#{@tag_prefix}.#{tag}" if @tag_prefix write [tag, time.to_i, map] end |