在 symfony2 中实现日志系统 [英] implementin log system in symfony2
问题描述
我想将一个日志文件集成到我用 symfony2 制作的网站.我的意思是我想保存用户的每一个动作:点击按钮,将请求保存到数据库这可能吗?
I want to integrate a log file to my website which I made with symfony2. I mean I want to save every action of the user :clicks button, saving requests to database Is that possible?
有人对此有什么想法吗?
Does anybody have an idea about that?
推荐答案
登录 Symfony 2
是的,这实际上是在文档中描述的:
Logging in Symfony 2
Yes, this is actually described in the documentation:
其中一个例子包括:
要记录消息,只需从容器中获取记录器服务您的控制器:
To log a message simply get the logger service from the container in your controller:
public function indexAction()
{
$logger = $this->get('logger');
$logger->info('I just got the logger');
$logger->err('An error occurred');
// ...
}
只需创建一个从客户端单独调用的 AJAX 操作(如果这是您想要的),或者在您的 AJAX 调用周围创建一个包装器"(如果这是您想要的).这一切都取决于你真正想要什么.祝你好运!
Just create an AJAX action called separately from client side (if this is what you wanted), or create a "wrapper" around your AJAX calls (if this is what you wanted instead). It all depends on what you really want. Good luck!
Monolog
在这里也有单独的文档:
The Monolog
has also separate documentation here:
您可能感兴趣的处理程序是:StreamHandler
(将记录记录到任何 PHP 流中,将其用于日志文件")和/或 RotatingFileHandler
("将记录记录到一个文件并每天创建一个日志文件.它还会删除早于 $maxFiles
的文件.您应该使用 logrotate
不过,对于高调的设置,这只是一种快速而肮脏的解决方案").
The handlers that you may be interested in are: StreamHandler
("Logs records into any PHP stream, use this for log files") and/or RotatingFileHandler
("Logs records to a file and creates one logfile per day. It will also delete files older than $maxFiles
. You should use logrotate
for high profile setups though, this is just meant as a quick and dirty solution").
这篇关于在 symfony2 中实现日志系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!