lib/twiglet/logger.rb in twiglet-3.4.9 vs lib/twiglet/logger.rb in twiglet-3.5.0

- old
+ new

@@ -14,11 +14,10 @@ def initialize( service_name, **args ) @service_name = service_name - default_properties = args.delete(:default_properties) || {} @args = args now = args.fetch(:now, -> { Time.now.utc }) output = args.fetch(:output, $stdout) level = args.fetch(:level, DEBUG) @@ -29,11 +28,12 @@ @validator = Validator.new(validation_schema) formatter = Twiglet::Formatter.new( service_name, - default_properties: default_properties, + default_properties: args.fetch(:default_properties, {}), + context_provider: args[:context_provider], now: now, validator: @validator ) super(output, formatter: formatter, level: level) end @@ -56,12 +56,19 @@ super(message, &block) end def with(default_properties) - Logger.new( + self.class.new( @service_name, **@args.merge(default_properties: default_properties) + ) + end + + def context_provider(&blk) + self.class.new( + @service_name, + **@args.merge(context_provider: blk) ) end alias_method :warning, :warn alias_method :critical, :fatal