Skip to content

Commit

Permalink
Apply format and time_format to serverengne logger
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <ganmacs@gmail.com>
  • Loading branch information
ganmacs committed Feb 3, 2020
1 parent 22e889e commit 22d20eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def self.load_config(path, params = {})
)
# this #init sets initialized logger to $log
logger_initializer.init(:supervisor, 0)
logger_initializer.apply_options(format: params['log_format'], time_format: params['log_time_format'])
logger = $log

command_sender = Fluent.windows? ? "pipe" : "signal"
Expand Down Expand Up @@ -691,6 +692,8 @@ def supervise
'rpc_endpoint' => @system_config.rpc_endpoint,
'enable_get_dump' => @system_config.enable_get_dump,
'counter_server' => @system_config.counter_server,
'log_format' => @system_config.log.format,
'log_time_format' => @system_config.log.time_format,
}

se = ServerEngine.create(ServerModule, WorkerModule){
Expand Down
27 changes: 27 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ def test_load_config
Timecop.return
end

def test_load_config_for_logger
tmp_dir = "#{TMP_DIR}/dir/test_load_config_log.conf"
conf_info_str = %[
<system>
<log>
format json
time_format %FT%T.%L%z
</log>
</system>
]
write_config tmp_dir, conf_info_str
params = {
'use_v1_config' => true,
'conf_encoding' => 'utf8',
'log_level' => Fluent::Log::LEVEL_INFO,
'log_path' => 'test/tmp/supervisor/log',

'workers' => 1,
'log_format' => :json,
'log_time_format' => '%FT%T.%L%z',
}

r = Fluent::Supervisor.load_config(tmp_dir, params)
p :json, r[:logger].format
p '%FT%T.%L%z', r[:logger].time_format
end

def test_load_config_for_daemonize
tmp_dir = "#{TMP_DIR}/dir/test_load_config.conf"
conf_info_str = %[
Expand Down

0 comments on commit 22d20eb

Please sign in to comment.