Class: LogStash::Outputs::OSS::FileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/oss/file_generator.rb

Defined Under Namespace

Modules: SecureRandom

Constant Summary collapse

FILE_MODE =
"a"
STRFTIME =
"%Y-%m-%dT%H.%M"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, encoding, temporary_directory) ⇒ FileGenerator

‘prefix`/logstash.oss.random-uuid.LogStash::Outputs::OSS::FileGenerator.%Y-%m-%dT%H%Y-%m-%dT%H.%M.part-#index.#extension



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/outputs/oss/file_generator.rb', line 17

def initialize(prefix, encoding, temporary_directory)
  @index = 0
  @prefix = prefix
  # gzip or plain
  @encoding = encoding
  # temporary directory to save temporary file before upload to OSS
  @temporary_directory = temporary_directory

  @lock = Mutex.new

  rotate
end

Instance Attribute Details

#current_fileObject

Returns the value of attribute current_file.



14
15
16
# File 'lib/logstash/outputs/oss/file_generator.rb', line 14

def current_file
  @current_file
end

#encodingObject

Returns the value of attribute encoding.



14
15
16
# File 'lib/logstash/outputs/oss/file_generator.rb', line 14

def encoding
  @encoding
end

#indexObject

Returns the value of attribute index.



14
15
16
# File 'lib/logstash/outputs/oss/file_generator.rb', line 14

def index
  @index
end

#prefixObject

Returns the value of attribute prefix.



14
15
16
# File 'lib/logstash/outputs/oss/file_generator.rb', line 14

def prefix
  @prefix
end

#temporary_directoryObject

Returns the value of attribute temporary_directory.



14
15
16
# File 'lib/logstash/outputs/oss/file_generator.rb', line 14

def temporary_directory
  @temporary_directory
end

Instance Method Details

#extensionObject



42
43
44
# File 'lib/logstash/outputs/oss/file_generator.rb', line 42

def extension
  @encoding == "gzip" ? "gz" : "data"
end

#gzip?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/logstash/outputs/oss/file_generator.rb', line 46

def gzip?
  @encoding == "gzip"
end

#rotateObject



30
31
32
33
34
# File 'lib/logstash/outputs/oss/file_generator.rb', line 30

def rotate
  @current_file = create_file
  @index += 1
  @current_file
end

#with_lockObject



36
37
38
39
40
# File 'lib/logstash/outputs/oss/file_generator.rb', line 36

def with_lock
  @lock.synchronize do
    yield self
  end
end