From 2af3e4051071a42a513b0d98f0f7e952a44a61ab Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 2 May 2023 18:28:02 +0400 Subject: [PATCH] Improve logging --- lib/diversipub/main.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/diversipub/main.rb b/lib/diversipub/main.rb index 6a6ac14..797aae4 100644 --- a/lib/diversipub/main.rb +++ b/lib/diversipub/main.rb @@ -65,10 +65,10 @@ module Diversipub def webrick_options @webrick_options ||= { - AccessLog: [], + AccessLog: webrick_access_log, BindAddress: 'localhost', DocumentRoot: nil, - Logger: Logger.new(File.open('/dev/null', 'w')), + Logger: web_logger, Port: 8080, }.freeze end @@ -80,5 +80,17 @@ module Diversipub def sinatra_app @sinatra_app ||= SinatraApp.new self end + + def webrick_access_log + @webrick_access_log ||= [ + [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT], + ].freeze + end + + def web_logger + @web_logger ||= Logger.new(stderr).tap do |web_logger| + web_logger.level = Logger::INFO + end + end end end