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

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