Last active
September 21, 2017 00:01
-
-
Save binarylogic/f662e2635ffda0e43e751d543799d334 to your computer and use it in GitHub Desktop.
Timber Auth Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| # Make sure this is called *after* you authenticate users | |
| around_filter :set_user_context | |
| private | |
| def set_user_context(&block) | |
| if !current_user.nil? | |
| # Ensure the attributes are mapped properly here | |
| user_context = Timber::Contexts::User.new(id: current_user.id, email: current_user.email, name: current_user.full_name) | |
| Timber.with_context(user_context, &block) | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mrsweaters this is actually the correct syntax. Notice how I pass
&blockdown. This is important because it ensures all of your logs get the user context. I've updated the example as well as our docs: https://timber.io/docs/languages/ruby/configuration/capture-user-contextThanks for your help!