Giter Site home page Giter Site logo

Add current_user support about lograge HOT 8 CLOSED

roidrage avatar roidrage commented on July 24, 2024 2
Add current_user support

from lograge.

Comments (8)

freegenie avatar freegenie commented on July 24, 2024 5

I've been looking for a solution to this issue because that would be tremendously useful. You can use a Rails' hook method in Instrumentation called append_info_to_payload. Just override that in your ApplicationController:

def append_info_to_payload(payload)
    super
    payload[:uid] = current_user.id if logged_in? 
end

Then you can use:

config.lograge.custom_options = lambda do |event|
    { :uid => event.payload[:uid] }
end

from lograge.

coreymartella avatar coreymartella commented on July 24, 2024 1

@nathany I'm going thru this issue myself. The main thing I'm noticing is that lograge's payload would only apply to things it is subscribed to (namely process_action.action_controller).

However if you have any generic logging happening elsewhere the application you want the tags attached to you will still need to use the tags (i.e a log even happening within model code where you want the current user_id included in the log method w/o knowing at the model level what it is.

But if you just want it for the general "request completed" lograge will do the trick

from lograge.

fabn avatar fabn commented on July 24, 2024 1

+1000 for this feature builtin in lograge.

from lograge.

sairam avatar sairam commented on July 24, 2024 1

@tongboy instead of current_user.nil? - you should use user_signed_in?

from lograge.

roidrage avatar roidrage commented on July 24, 2024

I've started working on a branch that brings support for tagged logging to lograge, which would be much more fitting in this case, as it'd utilize something Rails already has support for.

from lograge.

nathany avatar nathany commented on July 24, 2024

We are using config.log_tags in Rails to add the user_id. If we switch to lograge, should we use custom_options instead?

from lograge.

nathany avatar nathany commented on July 24, 2024

After switching to append_info_to_payload, I'm actually likely it better than what we were doing with config.log_tags before setting up lograge (grabbing the session id and doing a separate lookup).

from lograge.

JeremiahChurch avatar JeremiahChurch commented on July 24, 2024

just want to say freegenie's option from '12 still works great in Rails 4.2 / Ruby 2.2

for Devise there are a few ways to check for logged in - I went with

def append_info_to_payload(payload)
    super
    payload[:uid] = current_user.id unless current_user.nil?
end

from lograge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.