Skip to content

Commit

Permalink
out_file uses localtime by default
Browse files Browse the repository at this point in the history
  • Loading branch information
frsyuki committed Sep 21, 2011
1 parent 5cd2a01 commit 81462cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
12 changes: 9 additions & 3 deletions lib/fluent/output.rb
Expand Up @@ -269,6 +269,8 @@ def initialize
@buffer_type = 'memory'
end

attr_accessor :buffer_type

def configure(conf)
if buffer_type = conf['buffer_type']
@buffer_type = buffer_type
Expand Down Expand Up @@ -351,17 +353,21 @@ def initialize
super
@time_format = '%Y%m%d'
@time_wait = 10*60 # TODO default value
@localtime = false
@ignore_old = false
@localtime = true
@buffer_type = 'file' # overwrite default buffer_type
#@ignore_old = false # TODO
# TODO @flush_interval = 60 # overwrite default flush_interval
end

attr_accessor :time_format, :time_wait, :localtime

def configure(conf)
super

# TODO timezone
if conf['localtime']
if conf['utc']
@localtime = false
elsif conf['localtime']
@localtime = true
end

Expand Down
22 changes: 13 additions & 9 deletions lib/fluent/plugin/out_file.rb
Expand Up @@ -19,7 +19,7 @@ module Fluent


class FileOutput < TimeSlicedOutput
Plugin.register_output('file2', self)
Plugin.register_output('file', self)

SUPPORTED_COMPRESS = {
:gz => :gz,
Expand All @@ -28,6 +28,7 @@ class FileOutput < TimeSlicedOutput

def initialize
require 'zlib'
require 'time'
super
@path = nil
@compress = nil
Expand Down Expand Up @@ -62,17 +63,20 @@ def configure(conf)
end
@compress = c
end

if @localtime
@formatter = Proc.new {|tag,event|
"#{Time.at(event.time).iso8601}\t#{tag}\t#{event.record.to_json}\n"
}
else
@formatter = Proc.new {|tag,event|
"#{Time.at(event.time).utc.iso8601}\t#{tag}\t#{event.record.to_json}\n"
}
end
end

def format(tag, event)
# TODO foramt
#msg = e.record.map {|k,v|
# k = "\"#{k}\"" if k.include?(' ')
# v = "\"#{v}\"" if v.include?(' ')
# "#{k}=#{v}"
#}.join(' ')
msg = event.record.to_json
"#{Time.at(event.time).to_s} #{tag}: #{msg}\n"
@formatter.call(tag, event)
end

def write(chunk)
Expand Down

0 comments on commit 81462cf

Please sign in to comment.