Class: StackifyRubyAPM::LogDevice Private

Inherits:
Logger::LogDevice
  • Object
show all
Defined in:
lib/stackify_apm/logger/log_device.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#add_log_header(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/stackify_apm/logger/log_device.rb', line 25

def add_log_header(file)
  # Make it only empty.
end

#shift_log_ageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Style/RescueModifier rubocop:disable Lint/RescueWithoutErrorClass Newly created file example <file>-2.log is the latest appended log



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stackify_apm/logger/log_device.rb', line 34

def shift_log_age
  # set a temporary filename that doesn't have the increment prefix and .log format.
  temp_filename = @filename.gsub(/\-(d*\.?\d*).log/, '')
  # set a temporary file increment while stripping the current filename and retain the number
  txttemp_fileincrement = @filename.gsub(temp_filename, '').delete('^0-9')
  # convert the string value to integer
  current_fileprefix = txttemp_fileincrement.to_i
  # assign as filename counter
  filename_counter = current_fileprefix
  if FileTest.exist?(@filename)
    filename_counter = current_fileprefix + 1
  else
    ctr_flagger = 0
    # a loop that check if the number of filenames if exists or not
    1.upto(current_fileprefix) do |i|
      temp_oldfile = "#{temp_filename}-#{i}.log"
      ctr_flagger += 1 if FileTest.exist?(temp_oldfile)
    end
    # if the counter is 0 then set the filename counter to 1
    filename_counter = 1 if ctr_flagger < 0
  end

  @dev.close rescue nil

  temp_newfilename = "#{temp_filename}-#{filename_counter}.log"
  @filename = temp_newfilename
  @dev = create_logfile(@filename)
  File.chmod(0o777, @filename)

  true
end

#shift_log_period(period_end) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is the monkeypatch of core Logger method where reformats the file name when creating the file log.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stackify_apm/logger/log_device.rb', line 67

def shift_log_period(period_end)
  suffix = period_end.strftime(@shift_period_suffix)
  age_file = "#{@filename}.#{suffix}"
  if FileTest.exist?(age_file)
    # try to avoid filename crash caused by Timestamp change.
    idx = 1
    # .99 can be overridden; avoid too much file search with 'loop do'
    while idx < 100
      idx += 1
      age_file = "#{@filename}-#{idx}.#{suffix}"
      break unless FileTest.exist?(age_file)
    end
  end
  @dev.close rescue nil
  File.rename(@filename.to_s, age_file)
  @dev = create_logfile(@filename)
  File.chmod(0o777, @filename)

  true
end

#write(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/stackify_apm/logger/log_device.rb', line 12

def write(message)
  if @filename
    if FileTest.exist?(@filename)
    else
      @dev = create_logfile(@filename)
      File.chmod(0o777, @filename)

      return @dev
    end
  end
  write_without_apm(message)
end

#write_without_apmObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
# File 'lib/stackify_apm/logger/log_device.rb', line 11

alias_method 'write_without_apm', 'write'