How i can add prefix for error report file name located in /var/report/?

Like : prefix_979188230854

Any suggestions please?


Magento 2’s default error handler can be found in {project root}\vendor\magento\framework\App\ErrorHandler.php. You can extend this error handler with your own logic to customize the behavior.

namespace Magento\Framework\App;
class ErrorHandler{
    protected $errorPhrases = [
        E_ERROR => 'Error',
        E_WARNING => 'Warning',
        E_PARSE => 'Parse Error',
        E_NOTICE => 'Notice',
        E_CORE_ERROR => 'Core Error',
        E_CORE_WARNING => 'Core Warning',
        E_COMPILE_ERROR => 'Compile Error',
        E_COMPILE_WARNING => 'Compile Warning',
        E_USER_ERROR => 'User Error',
        E_USER_WARNING => 'User Warning',
        E_USER_NOTICE => 'User Notice',
        E_STRICT => 'Strict Notice',
        E_RECOVERABLE_ERROR => 'Recoverable Error',
        E_DEPRECATED => 'Deprecated Functionality',
        E_USER_DEPRECATED => 'User Deprecated Functionality',

    public function handler($errorNo, $errorStr, $errorFile, $errorLine)
        if (strpos($errorStr, 'DateTimeZone::__construct') !== false) {
        // there's no way to distinguish between caught system exceptions and warnings
        return false;

    $errorNo = $errorNo & error_reporting();
    if ($errorNo == 0) {
        return false;

    $msg = isset($this->errorPhrases[$errorNo]) ?
        $this->errorPhrases[$errorNo] : "Unknown error ({$errorNo})";
    $msg .= ": {$errorStr} in {$errorFile} on line {$errorLine}";
    throw new \Exception($msg);

To customize the log format, just make modifications in the $msg of the handler function. You can find this function under the ErrorHandler class.

$msg = isset($this->errorPhrases[$errorNo]) ?
        $this->errorPhrases[$errorNo] : "Unknown error ({$errorNo})";
$msg .= ": {$errorStr} in {$errorFile} on line {$errorLine}";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.