class Truemail::Logger

Attributes

event[R]
file[R]
stdout[R]

Public Class Methods

new(event, error_stdout, log_absolute_path) click to toggle source
# File lib/truemail/logger.rb, line 9
def initialize(event, error_stdout, log_absolute_path)
  @event = event
  @stdout = error_stdout
  @file = log_absolute_path
end

Public Instance Methods

push(validator_instance) click to toggle source
# File lib/truemail/logger.rb, line 15
def push(validator_instance)
  current_event = Truemail::Log::Event.new(event, validator_instance)
  return unless current_event.valid?
  create_logs(current_event.log_level, Truemail::Log::Serializer::ValidatorText.call(validator_instance))
end

Private Instance Methods

create_logs(log_level, serialized_object) click to toggle source
# File lib/truemail/logger.rb, line 30
def create_logs(log_level, serialized_object)
  %i[stdout file].each do |output_type|
    next unless public_send(output_type)
    ::Logger.new(output_type.eql?(:stdout) ? $stdout : init_log_file).add(log_level) { serialized_object }
  end
end
init_log_file() click to toggle source
# File lib/truemail/logger.rb, line 23
def init_log_file
  output_file = Pathname(file)
  return output_file if output_file.exist?
  output_file.parent.mkpath && ::FileUtils.touch(output_file)
  output_file
end