dtgta48604 2013-09-09 20:59
浏览 39
已采纳

Laravel 4 - 记录事件监听器

I'm quite new to laravel 4, and I want to log to files inside storage/logs when a user attempt to connect to my application.

I have added inside routes.php this:

Event::listen('auth.attempt', function() {
    echo 'attempting to logging in';
});

I know that Laravel 4 includes monolog which is a PHP logging framework , but I dont know if it's the easiest way to log here.

I can declare a filter that I add to the before of my route, but this solution isn't very elegant.

  • 写回答

1条回答 默认 最新

  • dsdxlibt98300 2013-09-09 22:35
    关注

    Go with monolog, it is widely used and a great library. It can be configured in many different ways and implements the PSR-3 logging interface. See http://laravel.com/docs/errors#logging and http://github.com/Seldaek/monolog‎.

    Most simple logging command:

    Log::info('This is some useful information.');
    

    If you want to directly interface with monolog:

    $monolog = Log::getMonolog();
    

    By using the standard laravel facade for monolog it will automatically log it into a new file with the current date.

    Regarding your initial query about the easiest method, I feel compelled to say this is the easiest one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用