lib/phobos.rb in phobos-1.5.0 vs lib/phobos.rb in phobos-1.6.0
- old
+ new
@@ -33,14 +33,20 @@
def configure(configuration)
ENV['RAILS_ENV'] = ENV['RACK_ENV'] ||= 'development'
@config = DeepStruct.new(fetch_settings(configuration))
@config.class.send(:define_method, :producer_hash) { Phobos.config.producer&.to_hash }
@config.class.send(:define_method, :consumer_hash) { Phobos.config.consumer&.to_hash }
+ @config.listeners ||= []
configure_logger
logger.info { Hash(message: 'Phobos configured', env: ENV['RACK_ENV']) }
end
+ def add_listeners(listeners_configuration)
+ listeners_config = DeepStruct.new(fetch_settings(listeners_configuration))
+ @config.listeners += listeners_config.listeners
+ end
+
def create_kafka_client
Kafka.new(config.kafka.to_hash.merge(logger: @ruby_kafka_logger))
end
def create_exponential_backoff(backoff_config = nil)
@@ -52,19 +58,25 @@
def configure_logger
log_file = config.logger.file
ruby_kafka = config.logger.ruby_kafka
date_pattern = '%Y-%m-%dT%H:%M:%S:%L%zZ'
- file_layout = Logging.layouts.json(date_pattern: date_pattern)
- stdout_layout = Logging.layouts.pattern(date_pattern: date_pattern)
+ json_layout = Logging.layouts.json(date_pattern: date_pattern)
+
+ stdout_layout = if config.logger.stdout_json == true
+ json_layout
+ else
+ Logging.layouts.pattern(date_pattern: date_pattern)
+ end
+
appenders = [Logging.appenders.stdout(layout: stdout_layout)]
Logging.backtrace(true)
Logging.logger.root.level = silence_log ? :fatal : config.logger.level
if log_file
FileUtils.mkdir_p(File.dirname(log_file))
- appenders << Logging.appenders.file(log_file, layout: file_layout)
+ appenders << Logging.appenders.file(log_file, layout: json_layout)
end
@ruby_kafka_logger = nil
if ruby_kafka