lib/td/logger/td_logger.rb in td-logger-0.3.16 vs lib/td/logger/td_logger.rb in td-logger-0.3.17
- old
+ new
@@ -1,29 +1,10 @@
module TreasureData
module Logger
class TreasureDataLogger < Fluent::Logger::LoggerBase
- module Finalizable
- require 'delegate'
- def new(*args, &block)
- obj = allocate
- obj.instance_eval { initialize(*args, &block) }
- dc = DelegateClass(obj.class).new(obj)
- ObjectSpace.define_finalizer(obj, finalizer(obj))
- dc
- end
-
- def finalizer(obj)
- fin = obj.method(:finalize)
- proc {|id|
- fin.call
- }
- end
- end
- extend Finalizable
-
def initialize(tag_prefix, options={})
defaults = {
:auto_create_table => false,
}
options = defaults.merge!(options)
@@ -76,10 +57,14 @@
@error_count = 0
# start thread when the first post() is called for
# Unicorn and Passenger.
@upload_thread = nil
+
+ # The calling order of finalizer registered by define_finalizer is indeterminate,
+ # so we should use at_exit instead for memory safety.
+ at_exit { close }
end
attr_accessor :logger
def close
@@ -340,13 +325,9 @@
@client.create_database(db)
@client.create_log_table(db, table)
end
retry
end
- end
-
- def finalize
- close
end
require 'thread' # ConditionVariable
if ConditionVariable.new.method(:wait).arity == 1
# "WARNING: Running on Ruby 1.8. Ruby 1.9 is recommended."