Log exception.

@param \Exception  $e      Exception.
@param string|null $action Failed action short description.
@param mixed       $level  Log level (default to LogLevel::ERROR).

@since 1.1 Default log level is LogLevel::ERROR
@since 1.0
968005
protected function logException(\Exception $e, $action = null, $level = LogLevel::ERROR)
    {
        $message = $action
            ? sprintf('%s failed: %s', $action, $e->getMessage())
            : sprintf('%s: %s', get_class($e), $e->getMessage());
        $this->getLogger()->log($level, $message, ['backtrace' => $e->getTraceAsString()]);
    }
1369924
public function handle(string $level, string $log): bool
    {
        if (!is_resource($this->resource)) {
            $status = $this->open();
            if (!$status) {
                throw new \Exception(
                    sprintf('Failed to open a resource "%s"', $this->getOptionOrDefault('path'))
                );
            }
        }
        return fwrite($this->resource, $log) !== false;
    }
602031
public function logError(MvcEvent $e)
    {
        /** @var \Exception $exception */
        $exception = $e->getResult()->exception;

        if (!$exception) {
            return;
        }

        $extra = [
            'file'  => $exception->getFile(),
            'line'  => $exception->getLine(),
            'trace' => $exception->getTrace()
        ];

        if ($exception instanceof ErrorException) {
            /** @var ErrorException $exception */
            $extra['severity'] = $exception->getSeverity();
        }

        $this->logger->err($exception->getMessage(), $extra);
    }
1281260
private static function log(string $message, int $level) {
        \Logger::configure(self::getConfiguration());
        $logger = \Logger::getRootLogger();
        $logger->setLevel(self::getLoggerLevel());

        switch ($level) {
            case Logger::DEBUG:
                $logger->debug($message);
                break;
            case Logger::INFO:
                $logger->info($message);
                break;
            case Logger::WARN:
                $logger->warn($message);
                break;
            case Logger::ERROR:
                $logger->error($message);
                break;
            case Logger::FATAL:
                $logger->fatal($message);
                break;
            case Logger::TRACE:
                $logger->trace($message);
                break;
            default:
        }
    }
456858
public function log($message, $level = 0) {
        foreach ($this->_loggers as $logger) {
            try {
                $logger->logMessage($message, $level);
            } catch (LoggerException $e) {
                throw $e;
            }
        }
    }
960404
public function logCriticalException(\Exception $e)
    {
        if ($this->getServerContext()->hasLogger(LoggerUtils::SYSTEM)) {
            $this->getServerContext()->getLogger(LoggerUtils::SYSTEM)->critical($e->__toString());
        }
    }
1109695
public function log($line, $level = 1)
    {
        // Check if logging is enabled
        if (!$this->_loggingEnabled)
            return false;

        // Check if the level is within the required level
        if (!$this->_isLoggingSet($level))
            return false;

        $dateTime = date("H:i:s", time());
        $line = "{$dateTime} [ICEPAY]: {$line}" . PHP_EOL;

        // Log to Screen
        if ($this->_logToScreen)
            echo "{$line} <br />";

        // Log to Hooked Class
        if ($this->_logToHook && $this->_logHookClass && $this->_logHookFunc) {
            $function = $this->_logHookFunc;
            $this->_logHookClass->$function($line);
        }


        // Log to Default File
        if ($this->_logToFile) {
            $file = $this->_loggingDirectory . DS . $this->_loggingFile;

            try {
                $fp = fopen($file, "a");
                fwrite($fp, $line);
                fclose($fp);
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            };
        }
    }
1278300
private function logError($throwable, $level)
    {
        $class = get_class($throwable);
        $code = 0;
        $type = $class;

        if ($throwable instanceof ErrorException) {
            $code = $throwable->getSeverity();
            $type = ErrorHandler::getErrorType($code);
        }

        // Unpack throwables
        $throwables = $this->unpackThrowables($throwable);

        $context = [
            'errorCode' => $code,
            'errorType' => $type,
            'errorClass' => $class,
            'errorStacktrace' => $this->formatStacktraceForExceptions($throwables),
        ];

        $this->log($level, $throwable->getMessage(), $context);
    }
429358
public function logException(\Exception $e)
    {
        $error = $e->getMessage() . $e->getTraceAsString();
        return $this->logEmergency($error);
    }
188695
public function log($level, $message, array $context = [])
    {
        $exception = isset($context['exception']) ? $context['exception'] : null;
        $microTime = microtime(true);
        $micro = sprintf("%06d", ($microTime - floor($microTime)) * 1000000);
        $logTime = (new \DateTime(date('Y-m-d H:i:s.' . $micro, $microTime)))->format('Y-m-d H:i:s.u');
        error_log(
            '[' . $logTime . '] '
            .$message.($exception ? ' {Exception: '.$exception->getMessage().'}' : '')."\n",
            3,
            $this->file,
            null
        );
    }
1028509
protected void logError(Exception e, boolean logToErrorChannel) {

        if (logToErrorChannel) {
            LOG.error(e.getLocalizedMessage(), e);
        } else {
            LOG.info(e.getLocalizedMessage(), e);
        }
        // if an error was logged make sure that the flag to schedule a reload is reset
        setReloadScheduled(false);
    }
485445
public function exception($e)
    {
        $logLevel = \Psr\Log\LogLevel::CRITICAL;
        if ($e instanceof \Sabre\DAV\Exception) {
            // If it's a standard sabre/dav exception, it means we have a http
            // status code available.
            $code = $e->getHTTPCode();

            if ($code >= 400 && $code < 500) {
                // user error
                $logLevel = \Psr\Log\LogLevel::INFO;
            } else {
                // Server-side error. We mark it's as an error, but it's not
                // critical.
                $logLevel = \Psr\Log\LogLevel::ERROR;
            }
        }

        $this->server->getLogger()->log(
            $logLevel,
            'Uncaught exception',
            [
                'exception' => $e,
            ]
        );
    }
1013494
public function log($level, $message, array $context = [])
    {
        if (is_string($level)) {
            if (!array_key_exists($level, $this->levels)) {
                throw new \Exception("Log level {$level} is not valid. Please use syslog levels instead", 500);
            } else {
                $level = $this->levels[$level];
            }
        }
        if (array_key_exists('exception', $context)) {
            if ($context['exception'] instanceof \Exception) {
                $exc = $context['exception'];
                $message .= " Exception: {$exc->getMessage()}";
                unset($context['exception']);
            } else {
                unset($context['exception']);
            }
        }
        $level = $this->s_levels[$level];

        return  $this->interpolate($message, $context, $level);
    }
927209
protected function log($message, $level = Logger::DEBUG)
    {
        try {
            $this->logger->addRecord($level, $message, $this->getContext());
        } catch (\Exception $e) {

        }
    }
971010
protected static function exception(Exception $e)
	{
		$logLevel = self::config('cache.exception.log', FALSE);
		if (FALSE !== $logLevel) {
			Kohana_Exception::log($e, $logLevel);
		}

		if (self::config('cache.exception.throw', FALSE)) {
			throw $e;
		};
	}
632449
public static function onFailure(\Exception $e, \Resque_Job $job)
    {
        /** @var JobBase $failedJob */
        $failedJob = $job->getInstance();
        $failedJob->errorLog('Caught exception in '. get_called_class() . ': ' . $e->getMessage());
        $failedJob->getStat()->increment($failedJob->getStatFailureIncrementKey());
        throw $e;
    }
51082
public function report( Exception $e )
	{
		if ( !$this->shouldReport( $e ) )
			return;

		try
		{
			$logger = Framework::log();
		}
		catch ( Exception $ex )
		{
			throw $e; // throw the original Exception
		}

		$logger->error( $e );


		$level = $this->getLevel( $e );
		$id = UniversalBuilder::resolveClass( ExceptionIdentifier::class )->identify( $e );

		$logger->{$level}( $e, ['identification' => ['id' => $id]] );
	}