ruby-on-rails - 使用关注点的 Rails 自定义记录器不起作用
问题描述
我有一个看起来像这样的logger_module.rb
文件app/lib/concerns/
module Concerns
module LoggerModule
def logger(text, logs)
log_into_file(text, logs)
log_into_kibana(text)
# By calling his method, it will log into both Kibana and File
end
def log_into_kibana(text)
tagged_logger ||= Logger.new("log/#{Rails.env}.log")
tagged_logger.info "[#{self.class}] #{text}"
end
def log_into_file(text, logs)
logs << "#{text}"
end
end
end
我正在使用这个 Concerns 将任何内容记录到文件中(可以作为.log
文件下载)和 Kibana(用于跟踪/搜索日志)
- Rails
production.log
映射到 Kibana,因此所有内容production.log
都显示在 Kibana 中。
我正在使用这样的日志记录方法
class ActivateAccount
include Concerns::LoggerModule
def perform(logs)
logger("Processing total of #{accounts.count} accounts", logs)
# or
log_into_kibana("Processing total of #{accounts.count} accounts")
# or
log_into_file("Processing total of #{accounts.count} accounts", logs)
end
end
请注意,这logs
是一个来自另一个 RequestWorker 类的空数组。
我遇到的问题是,当我在本地运行它时它起作用了(我可以在其中看到它,development.log
如果production.log
我这样做Logger.new("log/production.log")
了,但在生产中,没有任何记录。只有阵列logs
在工作。
有人能帮助我吗?我花了将近一个月的时间试图弄清楚这一点。
解决方案
推荐阅读
- regex - 如何使用每个文件中的特定字符串重命名文件?
- python-3.x - 在python中逐块从url读取一个大的hdf5文件
- asp.net - 避免在 ASP.Net Core 5 中重定向到 HTTPS
- c++ - ncurses curs_set(0) 在 vscode 集成终端中不起作用
- python - 如何将列表中的单独项目组合在一起?
- python-3.x - 服务器不支持 STARTTLS 扩展
- oracle - ORA-00959: 命令提示符中不存在表空间 'EXAMPLE'
- haskell - 为什么将我的 FRP 实施更改为更具反应性的滞后?
- javascript - 如何阻止 React 按钮同步渲染?
- sql - 来自不同列的 SQL datediff