-
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
Cannot make to rotate log file of fluentd application on windows #2446
Comments
Hmm... Does windows have different permission for file creation and file rename? |
rename requires delete permission. Could you check the permission? |
Thank you for your response. I have checked file's ("C:\opt\td-agent\log") permissions and it has Full Control permissions including Delete. |
I've tried to set Full Control permissions for Everyone on C:\opt folder, but log rotation still does not work |
I'm facing the same issue with Windows 7 |
@cosmo0920 If you have a time, could you check this? fluentd log depends on serverengine. |
Yep, I'll check this. I guess that Windows API complains that opened files cannot delete from other process or same process. |
I checked the serverengine and Ruby logger library code. I found that Ruby logger does not use
I guess that it's a bug for Ruby logger library. |
Awesome! On windows, logger should set |
Yes! |
Unfourtantly, it isn't helping to add File::SHARE_DELETE in logger.rb def open_logfile(filename)
begin
open(filename, (File::WRONLY | File::APPEND | File::SHARE_DELETE))
rescue Errno::ENOENT
create_logfile(filename)
end
end def create_logfile(filename)
begin
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL | File::SHARE_DELETE)) |
Oops. Windows also complains lack of Permission in |
Simple script does not complains permission denied.... require "logger"
logger = Logger.new('test.log', 5, 30*1024)
loop do
logger.error "lost connection"
logger.debug "got new connection"
end It seems that the above script is working as expected. |
Try this one instead
A logger is created 3 times with same file name in the supervisor module |
Quoting from the Release notes |
@Ntzafrir and I managed to isolate the problem, the problem is actually in fluentd code. In the code there are 3 places where the same log is being initialized:
As a workaround in our production system, we separated the logs to 3 different files via the following method:
in fluentd.rb:
That way most of the logs lines which are written by the worker are still written to td-agent.log and the rotation is able to perform. |
I've reported this in Ruby language bug tracker. |
From the ticket, this issue seems to be Fluentd (or ServerEngine) logging strategy issue. Then, we should do the following:
Which is the better solution for this? |
I see... former seems to easy to implement because we can use SERVERENGINE_WORKER_ID to seperate log files. |
How about this patch? diff --git a/lib/fluent/command/fluentd.rb b/lib/fluent/command/fluentd.rb
index 93e2c35c..53883946 100644
--- a/lib/fluent/command/fluentd.rb
+++ b/lib/fluent/command/fluentd.rb
@@ -311,6 +311,12 @@ exit 0 if early_exit
require 'fluent/supervisor'
if opts[:supervise]
+ if Fluent.windows?
+ require 'pathname'
+
+ log_path = Pathname(opts[:log_path]).sub_ext("-supervisor#{Pathname(opts[:log_path]).extname}").to_s
+ opts[:log_path] = log_path
+ end
Fluent::Supervisor.new(opts).run_supervisor
else
if opts[:standalone_worker] && opts[:workers] && opts[:workers] > 1
diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb
index 44715b55..35f443f0 100644
--- a/lib/fluent/supervisor.rb
+++ b/lib/fluent/supervisor.rb
@@ -354,13 +354,21 @@ module Fluent
@log_rotate_size = log_rotate_size
end
+ def worker_id_suffixed_path(worker_id, path)
+ require 'pathname'
+
+ Pathname(path).sub_ext("-#{worker_id}#{Pathname(path).extname}").to_s
+ end
+
def init(process_type, worker_id)
@opts[:process_type] = process_type
@opts[:worker_id] = worker_id
if @path && @path != "-"
@logdev = if @log_rotate_age || @log_rotate_size
- Fluent::LogDeviceIO.new(@path, shift_age: @log_rotate_age, shift_size: @log_rotate_size)
+ Fluent::LogDeviceIO.new(Fluent.windows? ?
+ worker_id_suffixed_path(worker_id, @path) : @path,
+ shift_age: @log_rotate_age, shift_size: @log_rotate_size)
else
File.open(@path, "a")
end ResultThe above patch works as bellow:
|
Support logrotate on Windows correctly. Fix #2446
Support logrotate on Windows correctly. Fix #2446 Signed-off-by: Masahiro Nakagawa <[email protected]>
fluentd or td-agent version.
td-agent-3.4.1-0-x64
Environment information:
Operating system:
Microsoft Windows 10 Enterprise 1703
BuildNumber: 15063
Version: 10.0.15063
OSArchitecture: 64-bit
Kernel version:
Your configuration
C:\opt\td-agent\c
Your problem explanation. If you have an error logs, write it together.
Hello! I cannot make to rotate logs file of fluentd application. I use the following command under administrator user to launch program:
But when file C:\opt\td-agent\log reaches the limit of 1000000 bytes, I get messages:
The text was updated successfully, but these errors were encountered: