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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀