特定控制器的不同日志文件

时间:2021-04-06 22:01:40

I currently have a controller were I would like to keep track of logging in a separate log file, like: tracker.log. I currently get about 100,000 hits a day with this, and I would like to separate the log from all the other controllers so I can easily debug those as well as the tracker.

I couldn't find anything for the Rails::Initializer, that would extend specifically for a controller.

I know it will be something along the lines of:

我目前有一个控制器,我想跟踪一个单独的日志文件,如:tracker.log。我目前每天获得大约100,000次点击,我想将日志与所有其他控制器分开,这样我就可以轻松地调试这些以及跟踪器。我找不到Rails :: Initializer的任何内容,它将专门为控制器扩展。我知道这将是:

config.log_path = 'log/tracker.log'

Although you can't re-run the Rails initializer mid load, right?

虽然你不能重新运行Rails初始化器中负载,对吗?

2 个解决方案

#1


You just need to create your own instance of the Logger class (which is used by Rails to generate log files) and pass it a File instance as an argument.

您只需要创建自己的Logger类实例(Rails用它来生成日志文件)并将其作为参数传递给它。

#2


AFAIK rails can't maintain two separate log file simultaneously. I'd recommend doing your own logging in the controller in question.

AFAIK rails无法同时维护两个单独的日志文件。我建议您在相关控制器中进行自己的日志记录。

In similar situations I've used log4r. It's very easy to get started.

在类似的情况下,我使用了log4r。入门非常容易。

#1


You just need to create your own instance of the Logger class (which is used by Rails to generate log files) and pass it a File instance as an argument.

您只需要创建自己的Logger类实例(Rails用它来生成日志文件)并将其作为参数传递给它。

#2


AFAIK rails can't maintain two separate log file simultaneously. I'd recommend doing your own logging in the controller in question.

AFAIK rails无法同时维护两个单独的日志文件。我建议您在相关控制器中进行自己的日志记录。

In similar situations I've used log4r. It's very easy to get started.

在类似的情况下,我使用了log4r。入门非常容易。