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 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态