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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器