我在Ruby Rails环境中使用lograge。 我正在使用以下内容在我的config / initializer / lograge.rb
中启用日志记录Rails.application.configure do
config.lograge.enabled = true
config.lograge.base_controller_class = 'ActionController::API' # Yes, its API-only project
config.lograge.formatter = Lograge::Formatters::Json.new
config.log_level = :debug
end
当我使用登录
logger.info("PROG_NAME"){"Actual log message"}
结果是
Actual log message
{"method":"GET","path":"/entity","format":"*/*","controller":"LogController","action":"simple","status":204,"duration":0.3,"view":0.0}
我可以将实际的日志消息作为JSON中的字段获取吗?因此,我已经设置了JSON格式配置。
就像
{"message": "Actual log message", "method":"GET", "path":"/entity", "format":"*/*", "controller":"LogController", "action":"simple", "status":204, "duration":0.3, "view":0.0}