From 7f7e574d26fe94050cae3db9fea9506762965ea1 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 23 Feb 2017 13:35:49 -0600 Subject: [PATCH] Update examples --- lib/timber/contexts/user.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/timber/contexts/user.rb b/lib/timber/contexts/user.rb index d1a5eb81..cb0120c8 100644 --- a/lib/timber/contexts/user.rb +++ b/lib/timber/contexts/user.rb @@ -8,14 +8,27 @@ module Contexts # Note: Timber will attempt to automatically add this if you add a #current_user # method to your controllers. Most authentication solutions do this for you automatically. # - # Example: - # + # @example Basic example # user_context = Timber::Contexts::User.new(id: "abc1234", name: "Ben Johnson") # Timber::CurrentContext.with(user_context) do # # Logging will automatically include this context # logger.info("This is a log message") # end # + # @example Rails example + # class ApplicationController < ActionController::Base + # around_filter :capture_user_context + # private + # def capture_user_context + # if current_user + # user_context = Timber::Contexts::User.new(id: current_user.id, + # name: current_user.name, email: current_user.email) + # Timber::CurrentContext.with(user_context) { yield } + # else + # yield + # end + # end + # end class User < Context @keyspace = :user