Logs given throwable object (exception, error) in log output file

@param \Throwable $throwable
6894
public function log(\Throwable $throwable): void
    {
        $date = (new \DateTime())->format('Y-m-d H:i:s');
        $log = "[$date] {$throwable->getMessage()} at line {$throwable->getLine()} in {$throwable->getFile()}" . PHP_EOL;
        $dirname = dirname($this->logPath);

        if (!is_dir($dirname)) {
            mkdir($dirname, 0755);
        }

        $handle = fopen($this->logPath, 'a');
        fwrite($handle, $log);
        fclose($handle);
    }
1218992
protected function echoExceptionCli(\Throwable $exception)
    {
        $response = new CliResponse();

        $exceptionMessage = $this->renderSingleExceptionCli($exception);
        $exceptionMessage = $this->renderNestedExceptonsCli($exception, $exceptionMessage);

        if ($exception instanceof FlowException) {
            $exceptionMessage .= PHP_EOL . 'Open <b>Data/Logs/Exceptions/' . $exception->getReferenceCode() . '.txt</b> for a full stack trace.' . PHP_EOL;
        }

        $response->setContent($exceptionMessage);
        $response->send();
        exit(1);
    }
395753
public static function exceptionHandler(\Throwable $exception, bool $exit = true): void
    {
        if (!self::$reserved && $exit) {
            return;
        }
        self::$reserved = null;

        Helpers::improveException($exception);
        self::removeOutputBuffers(true);

        if (self::isProductionMode()) {
            try {
                self::log($exception, self::getExceptionLevel($exception));
            } catch (\Throwable $e) {
            }

            $message = 'ERROR: application encountered an error and can not continue. '
                . (isset($e) ? "Unable to log error.\n" : "Error was logged.\n");

            if (PHP_SAPI === 'cli') {
                \fwrite(STDERR, $message);
            } else {
                echo $message;
            }
        } else {
            $level = self::getExceptionLevel($exception);
            self::chromeLog($exception, $level);

            try {
                $file = self::log($exception, $level);

                echo "$exception\n" . ($file ? "(stored in $file)\n" : '');
                if ($file && PHP_SAPI === 'cli') {
                    if (self::$browser) {
                        \exec(self::$browser . ' ' . \escapeshellarg($file));
                    } elseif (DIRECTORY_SEPARATOR === '\\') {
                        \exec(\escapeshellarg($file));
                    } elseif (strtoupper(PHP_OS) === 'DARWIN') {
                        \exec('open ' . \escapeshellarg($file));
                    }
                }
            } catch (\Throwable $e) {
                echo "$exception\nUnable to log error: {$e->getMessage()}\n";
            }
        }

        if ($exit) {
            exit(255);
        }
    }
603988
private function renderThrowableStack(Throwable $throwable, int $number = 0): void
    {
        $this->io->writeln(sprintf(' #%d:', $number));
        $throwableClass = get_class($throwable);
        $this->io->writeln(sprintf('  - <comment>exception:</comment> %s', $throwableClass));
        $this->io->writeln(sprintf('  - <comment>file:</comment> <info>%s</info>', $throwable->getFile()));
        $this->io->writeln(sprintf('  - <comment>line:</comment> %d', $throwable->getLine()));
        $this->io->writeln(sprintf('  - <comment>message:</comment> %s', $throwable->getMessage()));

        $previous = $throwable->getPrevious();

        if ($previous !== null) {
            $this->renderThrowableStack($previous, $number + 1);
        }
    }
136426
public function notifyException($throwable, callable $callback = null)
    {
        $report = Report::fromPHPThrowable($this->config, $throwable);

        $this->notify($report, $callback);
    }
1039036
private function logException(Throwable $exception, ContainerInterface $container, string $message): void
    {
        if ($container->has(LoggerInterface::class) === true) {
            /** @var LoggerInterface $logger */
            $logger = $container->get(LoggerInterface::class);

            // The sad truth is that when you have a problem logging might not be available (e.g. no permissions
            // to write on a disk). We can't do much with it and can only hope that the error information will be
            // delivered to the user other way.
            try {
                $logger->critical($message, ['exception' => $exception]);
            } catch (Exception $secondException) {
            }
        }
    }
806846
public function fatal($message, $throwable = null) {
		$this->log(\n2n\log4php\LoggerLevel::getLevelFatal(), $message, $throwable);
	}
958107
protected function handleThrowable(
        Throwable $throwable,
        ?PsrContainerInterface $container
    ): ThrowableResponseInterface {
        if ($container !== null && $container->has(ThrowableHandlerInterface::class) === true) {
            /** @var ThrowableHandlerInterface $handler */
            /** @noinspection PhpUnhandledExceptionInspection */
            $handler  = $container->get(ThrowableHandlerInterface::class);
            $response = $handler->createResponse($throwable, $container);
        } else {
            $response = $this->createDefaultThrowableResponse($throwable);
        }

        return $response;
    }
910771
public function handle(\Throwable $throwable)
    {
        try {
            $response = $this->doHandler($throwable);
        } catch (\Throwable $e) {
            $response = $this->handleThrowtable($e);
        }

        return $response;
    }
634859
public function onExceptionHandle(\Throwable $e)
    {
        try {
            if ($e->getPrevious()) {
                $ce = $e->getPrevious();
                $errMsg = dump($ce, false, true);
            } else {
                $errMsg = dump($e, false, true);
                $ce = $e;
            }

            $this->getContext()->getLog()->error($errMsg);
            $this->outputJson(parent::$stdClass, 'Internal Server Error', 500);
        } catch (\Throwable $ne) {
            getInstance()->log->error('previous exception ' . dump($ce, false, true));
            getInstance()->log->error('handle exception ' . dump($ne, false, true));
        }
    }
949621
public function handler(\Throwable $t) {
        //Write to log
        $this->toLog($t);

        if (!in_array(strtolower(Assist::getAppEnv()), ['dev', 'development', 'local'])) {
          //Write to log
          $this->toLog($t);

          //Write a user friendly message to output
          $msg = Assist::loadCoreView('whoops');

          return $this->toUserOutput($msg);
        }

        return $this->toOutput($t);
    }
1187360
public function createThrew(Throwable $exception): ThrewEvent
    {
        return new ThrewEvent(
            $this->sequencer->next(),
            $this->clock->time(),
            $exception
        );
    }
788284
public static function exceptionHandler(\Throwable $e) {
		$code = $e->getCode();
		if (get_class($e) == 'Object\Error\UserException') {
			$code = -1;
		}
		self::$errors[] = [
			'errno' => $code,
			'error' => [$e->getMessage()],
			'file' => $e->getFile(),
			'line' => $e->getLine(),
			'code' => self::getCode($e->getFile(), $e->getLine()),
			'backtrace' => self::debugBacktraceString($e->getTrace())
		];
		self::$flag_exception = true;
		exit;
	}
764606
public function setPHPThrowable($throwable)
    {
        if (!$throwable instanceof Throwable && !$throwable instanceof Exception) {
            throw new InvalidArgumentException('The throwable must implement Throwable or extend Exception.');
        }

        $this->setName(get_class($throwable))
             ->setMessage($throwable->getMessage())
             ->setStacktrace(Stacktrace::fromBacktrace($this->config, $throwable->getTrace(), $throwable->getFile(), $throwable->getLine()));

        if (method_exists($throwable, 'getPrevious')) {
            $this->setPrevious($throwable->getPrevious());
        }

        return $this;
    }
1325383
public function log(\n2n\log4php\LoggerLevel $level, $message, $throwable = null) {
		if($this->isEnabledFor($level)) {
			$event = new \n2n\log4php\logging\LoggingEvent($this->fqcn, $this, $level, $message, null, $throwable);
			$this->callAppenders($event);
		}
		
		// Forward the event upstream if additivity is turned on
		if(isset($this->parent) && $this->getAdditivity()) {
			
			// Use the event if already created
			if (isset($event)) {
				$this->parent->logEvent($event);
			} else {
				$this->parent->log($level, $message, $throwable);
			}
		}
	}
669507
public static function exceptionHandler(\Throwable $throwable)
    {
        self::showError($throwable);

        Log::error((string)$throwable);
    }
392234
public function handleException(\Throwable $throwable)
    {
        // Captured an application-level exception.
        try {
            // Log the exception.
            Logger::get()->exception($throwable);
            // Try to display a user-friendly message.
            $responder = new Responders\Http\Error;
            $responder->setThrowable($throwable);
            $responder->getResponse()->issue();
            // Stop the application, as it did not handle the exception
            // properly.
            die(-1);
        } catch (\Exception $innerException) {
            $this->fail($innerException);
        }
    }