lib/karafka/instrumentation/logger.rb in karafka-1.4.4 vs lib/karafka/instrumentation/logger.rb in karafka-1.4.5

- old
+ new

@@ -18,11 +18,10 @@ # Creates a new instance of logger ensuring that it has a place to write to # @param _args Any arguments that we don't care about but that are needed in order to # make this logger compatible with the default Ruby one def initialize(*_args) - ensure_dir_exists super(target) self.level = ENV_MAP[Karafka.env] || ENV_MAP['default'] end private @@ -31,28 +30,25 @@ # to which we will be writing logs # We use this approach to log stuff to file and to the $stdout at the same time def target Karafka::Helpers::MultiDelegator .delegate(:write, :close) - .to($stdout, file) + .to(*[$stdout, file].compact) end - # Makes sure the log directory exists as long as we can write to it - def ensure_dir_exists - FileUtils.mkdir_p(File.dirname(log_path)) - rescue Errno::EACCES, Errno::EROFS - nil - end - # @return [Pathname] Path to a file to which we should log def log_path @log_path ||= Karafka::App.root.join("log/#{Karafka.env}.log") end # @return [File] file to which we want to write our logs # @note File is being opened in append mode ('a') def file + FileUtils.mkdir_p(File.dirname(log_path)) + @file ||= File.open(log_path, 'a') + rescue Errno::EACCES, Errno::EROFS + nil end end end end