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

Smash: Call to_log if it exists #16

Merged
merged 1 commit into from
May 12, 2016

Conversation

Attamusc
Copy link

@Attamusc Attamusc commented May 6, 2016

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.

@Attamusc Attamusc force-pushed the feature/sumo-special-format branch from 5e7048c to 66ef7ed Compare May 6, 2016 19:07
end
end

::Hash.include(HashExtensions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're bonkers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LIVE ON THE END

Copy link
Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh it's fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it... :)

Copy link
Contributor

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?

Copy link
Author

@Attamusc Attamusc May 12, 2016

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh that makes sense

@chr0n1x
Copy link
Member

chr0n1x commented May 6, 2016

👍

@bryanlatten
Copy link

@nBerg ping

@nBerg
Copy link
Contributor

nBerg commented May 12, 2016

👍

@chr0n1x chr0n1x merged commit 3c40662 into behance:master May 12, 2016
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

Successfully merging this pull request may close these issues.

4 participants