class LogStash::Outputs::Qingstor::TemporaryFileFactory
Constants
- FILE_MODE
- GZIP_ENCODING
- GZIP_EXTENSION
- STRFTIME
- TXT_EXTENSION
Attributes
counter[RW]
current[RW]
encoding[RW]
prefix[RW]
tmpdir[RW]
Public Class Methods
new(prefix, tags, encoding, tmpdir)
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 22 def initialize(prefix, tags, encoding, tmpdir) @counter = 0 @prefix = prefix @tags = tags @encoding = encoding @tmpdir = tmpdir @lock = Mutex.new rotate! end
Public Instance Methods
rotate!()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 33 def rotate! @lock.synchronize do @current = new_file increment_counter @current end end
Private Instance Methods
current_time()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 55 def current_time Time.new.strftime(STRFTIME) end
extension()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 43 def extension gzip? ? GZIP_EXTENSION : TXT_EXTENSION end
generate_name()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 59 def generate_name filename = "ls.qingstor.#{current_time}.#{SecureRandom.uuid}" if !tags.empty? "#{filename}.tag_#{tags.join('.')}.part#{counter}.#{extension}" else "#{filename}.part#{counter}.#{extension}" end end
gzip?()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 47 def gzip? encoding == GZIP_ENCODING end
increment_counter()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 51 def increment_counter @counter += 1 end
new_file()
click to toggle source
# File lib/logstash/outputs/qingstor/temporary_file_factory.rb, line 69 def new_file name = generate_name path = @tmpdir # ::File.join(@tmpdir, uuid) key = ::File.join(@prefix, name) FileUtils.mkdir_p(::File.join(path, @prefix)) io = if gzip? IOWrappedGzip.new(::File.open(::File.join(path, key), FILE_MODE)) else ::File.open(::File.join(path, key), FILE_MODE) end TemporaryFile.new(key, io, path) end