简体   繁体   English

如何在Rails日志中包含devise用户名(使用graylog2)

[英]How can I include devise usernames on rails logs (using graylog2)

Is there a way to include the logged in user in rails logs? 有没有办法将登录的用户包括在rails日志中? I am using devise and graylog2, the latter of which I assume is inconsequential to the answer. 我正在使用devise和graylog2,我认为后者与答案无关紧要。

Devise provides a current_user helper in the controller which can be used to access the currently signed-in user. Devise 在控制器中提供了current_user 帮助器 ,可用于访问当前登录的用户。

Assuming the user model has a name attribute, you can do the following: 假设用户模型具有name属性,则可以执行以下操作:

::Rails.logger.info "The currently logged-in user is #{current_user.name}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM