Class: Fluent::Supervisor::LoggerInitializer
- Inherits:
-
Object
- Object
- Fluent::Supervisor::LoggerInitializer
- Defined in:
- lib/fluent/supervisor.rb
Instance Method Summary collapse
- #apply_options(format: nil, time_format: nil, log_dir_perm: nil, ignore_repeated_log_interval: nil, ignore_same_log_interval: nil) ⇒ Object
- #init(process_type, worker_id) ⇒ Object
-
#initialize(path, level, chuser, chgroup, opts, log_rotate_age: nil, log_rotate_size: nil) ⇒ LoggerInitializer
constructor
A new instance of LoggerInitializer.
- #level=(level) ⇒ Object
- #reopen! ⇒ Object
- #stdout? ⇒ Boolean
- #worker_id_suffixed_path(worker_id, path) ⇒ Object
Constructor Details
#initialize(path, level, chuser, chgroup, opts, log_rotate_age: nil, log_rotate_size: nil) ⇒ LoggerInitializer
Returns a new instance of LoggerInitializer.
478 479 480 481 482 483 484 485 486 |
# File 'lib/fluent/supervisor.rb', line 478 def initialize(path, level, chuser, chgroup, opts, log_rotate_age: nil, log_rotate_size: nil) @path = path @level = level @chuser = chuser @chgroup = chgroup @opts = opts @log_rotate_age = log_rotate_age @log_rotate_size = log_rotate_size end |
Instance Method Details
#apply_options(format: nil, time_format: nil, log_dir_perm: nil, ignore_repeated_log_interval: nil, ignore_same_log_interval: nil) ⇒ Object
541 542 543 544 545 546 547 548 549 550 |
# File 'lib/fluent/supervisor.rb', line 541 def (format: nil, time_format: nil, log_dir_perm: nil, ignore_repeated_log_interval: nil, ignore_same_log_interval: nil) $log.format = format if format $log.time_format = time_format if time_format $log.ignore_repeated_log_interval = ignore_repeated_log_interval if ignore_repeated_log_interval $log.ignore_same_log_interval = ignore_same_log_interval if ignore_same_log_interval if @path && log_dir_perm File.chmod(log_dir_perm || Fluent::DEFAULT_DIR_PERMISSION, File.dirname(@path)) end end |
#init(process_type, worker_id) ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/fluent/supervisor.rb', line 494 def init(process_type, worker_id) @opts[:process_type] = process_type @opts[:worker_id] = worker_id if @path && @path != "-" unless File.exist?(@path) FileUtils.mkdir_p(File.dirname(@path)) end @logdev = if @log_rotate_age || @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 if @chuser || @chgroup chuid = @chuser ? ServerEngine::Privilege.get_etc_passwd(@chuser).uid : nil chgid = @chgroup ? ServerEngine::Privilege.get_etc_group(@chgroup).gid : nil File.chown(chuid, chgid, @path) end else @logdev = STDOUT end dl_opts = {} # subtract 1 to match serverengine daemon logger side logging severity. dl_opts[:log_level] = @level - 1 dl_opts[:log_rotate_age] = @log_rotate_age if @log_rotate_age dl_opts[:log_rotate_size] = @log_rotate_size if @log_rotate_size logger = ServerEngine::DaemonLogger.new(@logdev, dl_opts) $log = Fluent::Log.new(logger, @opts) $log.enable_color(false) if @path $log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG end |
#level=(level) ⇒ Object
552 553 554 555 |
# File 'lib/fluent/supervisor.rb', line 552 def level=(level) @level = level $log.level = level end |
#reopen! ⇒ Object
534 535 536 537 538 539 |
# File 'lib/fluent/supervisor.rb', line 534 def reopen! if @path && @path != "-" @logdev.reopen(@path, "a") end self end |
#stdout? ⇒ Boolean
530 531 532 |
# File 'lib/fluent/supervisor.rb', line 530 def stdout? @logdev == STDOUT end |
#worker_id_suffixed_path(worker_id, path) ⇒ Object
488 489 490 491 492 |
# File 'lib/fluent/supervisor.rb', line 488 def worker_id_suffixed_path(worker_id, path) require 'pathname' Pathname(path).sub_ext("-#{worker_id}#{Pathname(path).extname}").to_s end |