Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging modifies the original hash #71

Open
1 task
moltenice opened this issue Oct 11, 2022 · 0 comments
Open
1 task

Logging modifies the original hash #71

moltenice opened this issue Oct 11, 2022 · 0 comments

Comments

@moltenice
Copy link
Contributor

moltenice commented Oct 11, 2022

What

Logging modifies the original hash passed into it.

irb(main):001:0> require 'twiglet/logger'
=> true
irb(main):002:0> require_relative '../app/logging'
=> true
irb(main):003:0> logger = Logging.logger
=> #<Twiglet::Logger:0x000000012b22c118 @service_name="abc", @args={}, @validator=#<Twiglet::Validator:0x000000012b227f50 @schema={"type"=>"object", "required"=>["message"], "properties"=>{"m...
irb(main):004:0> hash = { "message": "hi" }
=> {:message=>"hi"}
irb(main):005:0> hash
=> {:message=>"hi"}
irb(main):006:0> hash["foo"] = "bar"
=> "bar"
irb(main):007:0> hash
=> {:message=>"hi", "foo"=>"bar"}
irb(main):008:0> logger.warn hash
{"ecs":{"version":"1.5.0"},"@timestamp":"2022-10-11T15:20:11.354Z","service":{"name":"abc"},"log":{"level":"warn"},"message":"hi","foo":"bar"}
=> true
irb(main):009:0> hash
=> {:message=>"hi", :foo=>"bar"}
irb(main):010:0> 

Why

So that Twiglet doesn't modify things passed to it as no one would expect a logger to have such a side effect.

How

Replicate the code from the "What" section above. Try and see why it causes that. Fix it.

ACs

  • Twiglet doesn't modify the hash passed into it anymore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant