Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix in get_current_sequence_number() #21

Open
carldenis opened this issue Oct 24, 2013 · 0 comments
Open

Bugfix in get_current_sequence_number() #21

carldenis opened this issue Oct 24, 2013 · 0 comments

Comments

@carldenis
Copy link

get_current_sequence_number() returns an invalid valid value if there is a file for which #{@core_file_name} ends with a digit and a second one being a prefix of the first.

For two log files named /my/path/file42.log and /my/path/file.log we will first create a /my/path/file42000001.log /my/path/file000001.log and later return 42000001 as the current maximum sequence number for file.log .

makeNewFilename will fail on line 137 with negative argument exception
padded_seq_no = "0" * (6 - @current_sequence_number.to_s.length) + @current_sequence_number.to_s

Thus, the regex is get_current_sequence_number() should be replaced with the more restrictive one from purge_log_files().

diff --git a/lib/log4r/outputter/rollingfileoutputter.rb b/lib/log4r/outputter/rollingfileoutputter.rb
index d8ecf0c..4cdd071 100644
--- a/lib/log4r/outputter/rollingfileoutputter.rb
+++ b/lib/log4r/outputter/rollingfileoutputter.rb
@@ -111,7 +111,7 @@ module Log4r
     def get_current_sequence_number()
       max_seq_no = 0
       Dir.foreach(@log_dir) do |child|
-        if child =~ /^#{@core_file_name}(\d+)#{@file_extension}$/
+        if child =~ /^#{@core_file_name}([0-9][0-9][0-9][0-9][0-9][0-9])#{@file_extension}$/
           seq_no = $1.to_i
           if (seq_no > max_seq_no)
             max_seq_no = seq_no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant