class Karafka::Instrumentation::Logger
Default logger for Event Delegator @note It uses ::Logger features - providing basic logging
Constants
- ENV_MAP
Map containing information about log level for given environment
Public Class Methods
new(*_args)
click to toggle source
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
Calls superclass method
# File lib/karafka/instrumentation/logger.rb, line 22 def initialize(*_args) ensure_dir_exists super(target) self.level = ENV_MAP[Karafka.env] || ENV_MAP['default'] end
Private Instance Methods
ensure_dir_exists()
click to toggle source
Makes sure the log directory exists as long as we can write to it
# File lib/karafka/instrumentation/logger.rb, line 40 def ensure_dir_exists FileUtils.mkdir_p(File.dirname(log_path)) rescue Errno::EACCES nil end
file()
click to toggle source
@return [File] file to which we want to write our logs @note File is being opened in append mode ('a')
# File lib/karafka/instrumentation/logger.rb, line 53 def file @file ||= File.open(log_path, 'a') end
log_path()
click to toggle source
@return [Pathname] Path to a file to which we should log
# File lib/karafka/instrumentation/logger.rb, line 47 def log_path @log_path ||= Karafka::App.root.join("log/#{Karafka.env}.log") end
target()
click to toggle source
@return [Karafka::Helpers::MultiDelegator] multi delegator instance
to which we will be writing logs
We use this approach to log stuff to file and to the $stdout at the same time
# File lib/karafka/instrumentation/logger.rb, line 33 def target Karafka::Helpers::MultiDelegator .delegate(:write, :close) .to($stdout, file) end