Comments (8)
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.
@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.
+1000 for this feature builtin in lograge.
from lograge.
@tongboy instead of current_user.nil? - you should use user_signed_in?
from lograge.
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.
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.
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.
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)
- No logs shown in CloudWatch when lograge is enabled (Rails/ECS/Fargate) HOT 1
- Why are we striping params for redirect url?
- [Question] Project status HOT 2
- Monkey patching of Rails::Rack::Logger#call_app loses request.action_dispatch instrumentation HOT 1
- [Question] Logstash-event loaded from gh
- How to add extra log payload in action cable?
- Rails support HOT 1
- Should we demote some of our formatters to "contrib"?
- Unable to Filter ActionCable Params HOT 2
- exception cannot show on rescue_from custom handler exception HOT 1
- custom_payload is "persisted' (or per se kept) between 2 requests HOT 4
- Request: new gem release HOT 5
- Any thoughts on supporting `Turbo::StreamsChannel`? HOT 1
- Sinatra support? HOT 1
- Simpler way to remove all log subscribers. HOT 3
- Redirect in routes not handled by lograge
- Confused about what Rails logging is eliminated HOT 1
- ActionView logs not completely suppressed with Rails 7.1+
- TypeError: no implicit conversion of String into Integer when adding lograge to Rails project with Rack 3.0.9 and Puma 6.4.2 HOT 3
- Suggestion from Rails regarding better patching mechanism
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lograge.