Skip to content

Instantly share code, notes, and snippets.

@foxracle
Created August 14, 2013 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxracle/6230145 to your computer and use it in GitHub Desktop.
Save foxracle/6230145 to your computer and use it in GitHub Desktop.
use local time instead of UTC format when insert into mongoDB
require 'fluent/plugin/out_mongo'
module Fluent
class MongoTimezoneOutput < MongoOutput
Plugin.register_output('mongo_timezone', self)
# offset to UTC (in hour)
config_param :utcoffset, :integer, :default => 0
def collect_records(chunk)
records = []
chunk.msgpack_each { |time, record|
# add utcoffset to timestamp of UTC to pretend to act as your timezone
record[@time_key] = Time.at(time || record[@time_key]) + @utcoffset * 3600 if @include_time_key
records << record
}
records
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment