小智 10
是的,你可以创建一个监听器来记录routes.php中的所有内容
Event::listen('laravel.log', function($type,$message)
{
$log = new Log();
$log->message = $message;
$log->type = $type;
$log->update;
});
Run Code Online (Sandbox Code Playgroud)
或者,如果您只想记录错误400和500 Larvavel,在Routes.php文件中有一个侦听错误404和500的Log事件,您可以在此事件侦听器中编写自己的代码.假设您有一个名为Log的模型,
Event::listen('404', function()
{
$error = "404: " . URL::full();
Log::error($error);
$update = new Log();
$update->error = $error;
$update->update;
return Response::error('404');
});
Event::listen('500', function()
{
Log::error($error);
$update = new Log();
$update->error = $error;
$update->update;
return Response::error('500');
});
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,如果您进一步阅读标题,Monolog本身支持写入Redis,MongoDB和CouchDB.这三个都支持相当重写(在Redis的情况下非常重写)用例.MySQL不在那里,因为登录到MySQL并不是世界上最好的主意.
如果你真的想这样做,你可以检查创建自己的处理程序的文档,这解释了如何创建和使用PDO处理程序写入SQL数据库:https://github.com/Seldaek/monolog/blob /master/doc/extending.md - 我仍然认为这是一个坏主意,但也许用例保证它.
| 归档时间: |
|
| 查看次数: |
7487 次 |
| 最近记录: |