dongwei3172 2014-10-23 05:39
浏览 31
已采纳

PHP错误日志+向日志条目添加会话值

This is most likely a silly question so I have no issues with it being closed etc.

I'm debugging PHP error logs and it would be of great advantage if I could see the user that created the specific error.

The userid is keep in the session.

Is it possible to customize PHP error logs to include a session value for debugging?

thx

  • 写回答

1条回答 默认 最新

  • dousong4777 2014-10-23 05:44
    关注

    Of course it is possible, I don't see why not:

    try {
      //some code
    } catch (Exception $e) {
        session_start();
        $log = 'Caught exception: '.  $e->getMessage(). "
    ";
        $log .= 'By user = '.$_SESSION['user_id']. "
    ";
        error_log($log);
    }
    

    To change error messages into Exception use this code:

    <?php
    function exception_error_handler($errno, $errstr, $errfile, $errline ) {
        throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
    set_error_handler("exception_error_handler");
    
    /* Trigger exception */
    strpos();
    ?>
    

    ErrorException

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog