Class: StackifyRubyAPM::LogDevice Private
- Inherits:
-
Logger::LogDevice
- Object
- Logger::LogDevice
- StackifyRubyAPM::LogDevice
- 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
- #add_log_header(file) ⇒ Object private
-
#create_logfile(filename) ⇒ Object
private
Override create_logfile of core LogDevice class where we set File.chmod to 0o777.
-
#shift_log_age ⇒ Object
private
rubocop:disable Style/RescueModifier rubocop:disable Lint/RescueWithoutErrorClass Newly created file example <file>-2.log is the latest appended log.
-
#shift_log_period(period_end) ⇒ Object
private
This is the monkeypatch of core Logger method where reformats the file name when creating the file log.
- #write(message) ⇒ Object private
- #write_without_apm ⇒ Object private
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.
22 23 24 |
# File 'lib/stackify_apm/logger/log_device.rb', line 22 def add_log_header(file) # Make it only empty. end |
#create_logfile(filename) ⇒ 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.
Override create_logfile of core LogDevice class where we set File.chmod to 0o777
84 85 86 87 88 |
# File 'lib/stackify_apm/logger/log_device.rb', line 84 def create_logfile(filename) logdev = super File.chmod(0o777, filename) logdev end |
#shift_log_age ⇒ 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.
rubocop:disable Style/RescueModifier rubocop:disable Lint/RescueWithoutErrorClass Newly created file example <file>-2.log is the latest appended log
31 32 33 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 |
# File 'lib/stackify_apm/logger/log_device.rb', line 31 def shift_log_age # set a temporary filename that doesn't have the increment prefix and .log format. temp_filename = @filename.to_s.sub(/\-(d*\.?\d*).log/, '') # set a temporary file increment while stripping the current filename and retain the number txttemp_fileincrement = @filename.to_s.sub(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) 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/stackify_apm/logger/log_device.rb', line 63 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) 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 |
# File 'lib/stackify_apm/logger/log_device.rb', line 12 def write() if @filename if FileTest.exist?(@filename) else @dev = create_logfile(@filename) end end write_without_apm() end |
#write_without_apm ⇒ 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.
11 |
# File 'lib/stackify_apm/logger/log_device.rb', line 11 alias_method 'write_without_apm', 'write' |