-
Notifications
You must be signed in to change notification settings - Fork 5
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
Smash: Call to_log
if it exists
#16
Conversation
5e7048c
to
66ef7ed
Compare
end | ||
end | ||
|
||
::Hash.include(HashExtensions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're bonkers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIVE ON THE END
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seriously though, I don't have to do this. I can just like...make another branch in the conditional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh it's fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still dont get what it gets us though? what else would respond to this except for Hashes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything. Any class that implements to_log
allows for a special format. For example, say we have a user that has sensitive data that we want to pull out. Instead of writing something like
logger.info(message: "Some test", user: @user.as_json(except: [:first_name, :last_name, :other_sensitive_data]))
everytime we want to log it, we can do
class User
def to_log
as_json(except: [:first_name, :last_name, :other_sensitive_data])
end
end
....
logger.info(message: "Some text", user: @user)
and consolidate that knowledge to one spot without consumers (at the logger.info
level) having to know about what to sanitize, or that to_log
even exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh that makes sense
👍 |
@nBerg ping |
👍 |
This allows us to pass arbitrary objects into the logger and define what they should look like without requiring the caller of the log method to manually specify inclusions/exclusions.