Class: LogStash::Outputs::Gcs::PathFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/gcs/path_factory.rb

Overview

PathFactory creates paths for rotating files.

Instance Method Summary collapse

Constructor Details

#initialize(directory, prefix, include_host, date_pattern, include_part, include_uuid, is_gzipped) ⇒ PathFactory

Returns a new instance of PathFactory.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/logstash/outputs/gcs/path_factory.rb', line 9

def initialize(directory, prefix, include_host, date_pattern, include_part, include_uuid, is_gzipped)
  @path_lock = Mutex.new

  pattern = prefix
  pattern += '_%{host}' if include_host
  pattern += '_%{date}'
  @base_pattern = pattern

  pattern += '.part%{partf}' if include_part
  pattern += '.%{uuid}' if include_uuid
  pattern += '.log'
  pattern += '.gz' if is_gzipped
  @pattern = pattern

  @prefix = prefix
  @directory = directory
  @date_pattern = date_pattern

  @part_number = starting_part
  @current = template_variables
end

Instance Method Details

#current_path(vars = nil) ⇒ Object

Returns the full path to the current file including parent directory.



53
54
55
56
57
58
# File 'lib/logstash/outputs/gcs/path_factory.rb', line 53

def current_path(vars=nil)
  @path_lock.synchronize {
    filename = @pattern % (vars || @current)
    ::File.join(@directory, filename)
  }
end

#rotate_path!Object

Rotates the path to the next one in sequence. If the path has a part number and the base path (date/hostname) haven’t changed the part number is incremented. Returns the path that was rotated out



34
35
36
37
38
39
40
41
42
43
# File 'lib/logstash/outputs/gcs/path_factory.rb', line 34

def rotate_path!
  last_path = current_path

  @path_lock.synchronize {
    @part_number = (next_base == current_base) ? @part_number + 1 : 0
    @current = template_variables
  }

  last_path
end

#should_rotate?Boolean

Checks if the file is ready to rotate because the timestamp changed.

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/logstash/outputs/gcs/path_factory.rb', line 46

def should_rotate?
  @path_lock.synchronize {
    next_base != current_base
  }
end