-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enable log rotate for log #1235
Conversation
1542544
to
20978f2
Compare
4ac2847
to
723e0a5
Compare
$log = Fluent::Log.new(logger, @opts) | ||
$log.enable_color(false) if @path | ||
$log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG | ||
end | ||
|
||
def stdout? | ||
@io == STDOUT | ||
$log.out == STDOUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$log
might be replaced with other values by code outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using @io
should be kept to use here and #reopen!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there fixes for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I forgot it.
I updated @io
to @logdev
. Because the name of @io
instance variable is changed here (https://github.com/fluent/fluentd/pull/1235/files#diff-dbe0e1ec4079138e48ca6a4d7c7248f9R316).
end | ||
|
||
def reopen! | ||
if @path && @path != "-" | ||
@io.reopen(@path, "a") | ||
$log.out.reopen(@path, "a") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some review comments.
And, please add a test to confirm that logger actually generates numbers of files specified by options (and older files will be deleted).
@@ -295,42 +299,48 @@ def self.load_config(path, params = {}) | |||
end | |||
|
|||
class LoggerInitializer | |||
def initialize(path, level, chuser, chgroup, opts) | |||
def initialize(path, level, chuser, chgroup, log_rotate_age, log_rotate_size, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use keyword arguments to add options..
opts[:log_rotate_age] = age | ||
else | ||
begin | ||
opts[:log_rotate_age] = Integer(age) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any reason to use Integer()
instead of to_i
?
IMO to_i
is widely used and normal for most ruby programmer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have a reason to use Integer()
here.
I want to raise an error when it was passed a value which can't be changed to an integer.
p 'a'.to_i # => 0
p Integer('a') # raise TypeError
@@ -81,6 +81,23 @@ | |||
opts[:log_path] = s | |||
} | |||
|
|||
op.on('--log-rotate-age AGE', 'generations to keep rotated log files') {|age| | |||
rotate_ages = %w(daily weekly monthly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use constant.
else | ||
begin | ||
opts[:log_rotate_age] = Integer(age) | ||
rescue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use rescue
with error class name (TypeError?).
rotate_size: [1, 100, 0, '0'], | ||
) | ||
def test_log_with_logdevio(expected) | ||
old = ENV['TZ'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use with_timezone
test helper method defined in lib/fluent/test/helpers.rb
instead of doing by itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated a code and reply a comment.
Plz re-review when you have time.
opts[:log_rotate_age] = age | ||
else | ||
begin | ||
opts[:log_rotate_age] = Integer(age) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have a reason to use Integer()
here.
I want to raise an error when it was passed a value which can't be changed to an integer.
p 'a'.to_i # => 0
p Integer('a') # raise TypeError
end | ||
} | ||
|
||
op.on('--log-rotate-size SIZE', 'sets the size to rotate log files') {|s| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BYTES
is better to show the value is an integer, not "size" (in fluentd's configuration file, e.g., 256k, 8m).
$log = Fluent::Log.new(logger, @opts) | ||
$log.enable_color(false) if @path | ||
$log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG | ||
end | ||
|
||
def stdout? | ||
@io == STDOUT | ||
$log.out == STDOUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there fixes for this?
end | ||
end | ||
|
||
def test_log_rotates_specifed_size_with_logdevio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should check '.1' file is NOT created, as a test for rotate_age
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added. 7bf4ab4
282d19d
to
48f3cc0
Compare
84572a0
to
33ca208
Compare
33ca208
to
b5513d1
Compare
Okay, LGTM. Thank you! |
This PR closes #1231.