lib/kiev/base.rb in kiev-4.7.0 vs lib/kiev/base.rb in kiev-4.8.0

- old
+ new

@@ -11,39 +11,44 @@ require_relative "version" require_relative "config" require_relative "util" require_relative "subrequest_helper" require_relative "hanami" +require "forwardable" +require "logger" module Kiev class << self + extend Forwardable + + def_delegators :config, + :logger, + :filtered_params, + :ignored_params, + :log_level, + :enable_filter_for_log_levels + EMPTY_OBJ = {}.freeze def configure yield(Config.instance) end - def logger - Config.instance.logger + def config + Config.instance end - def filtered_params - Config.instance.filtered_params + def event(log_name, data = EMPTY_OBJ, severity = log_level) + logger.log(severity, logged_data(data), log_name) end - def ignored_params - Config.instance.ignored_params + Config.instance.supported_log_levels.each_pair do |key, value| + define_method(key) do |log_name, data = EMPTY_OBJ| + event(log_name, data, value) + end end - def event(log_name, data = EMPTY_OBJ) - logger.log( - ::Logger::Severity::INFO, - ParamFilter.filter(data, filtered_params, ignored_params), - log_name - ) - end - def []=(name, value) RequestStore.store[:payload] ||= {} RequestStore.store[:payload][name] = value end @@ -61,7 +66,15 @@ def request_id RequestStore.store[:tracking_id] end alias_method :tracking_id, :request_id + + private + + def logged_data(data) + return data unless enable_filter_for_log_levels.include?(log_level) + + ParamFilter.filter(data, filtered_params, ignored_params) + end end end