Create an emergency log handler to avoid white screens of death.

@return \Psr\Log\LoggerInterface
358394
protected function createEmergencyLogger()
    {
        return new Logger(
            new Monolog(
                'zilf', $this->prepareHandlers(
                    [new StreamHandler(
                        Zilf::$app->runtimePath() . '/logs/zilf.log', $this->level(['level' => 'debug'])
                    )]
                )
            )
        );
    }
346881
public function createHandlerByConfig(): \SessionHandlerInterface
    {
        if (!isset($this->getConfig()['driver'])) {
            throw new \InvalidArgumentException('Session driver required');
        }
        $handler = $this->getHandler($this->getConfig()['driver']);
        $handler instanceof LifetimeInterface && $handler->setLifetime($this->getConfig()['lifetime']);
        return $handler;
    }
459206
private function createLogger(): LoggerInterface
    {
        $container = $this->iocContainer();
        if (empty($container) || !$container->has(LogsInterface::class)) {
            return new NullLogger();
        }

        //We are using class name as log channel (name) by default
        return $container->get(LogsInterface::class)->getLogger(static::class);
    }
180503
public function handleFatalError()
    {
        $this->reservedMemory = null;

        $lastError = error_get_last();

        if ($lastError && \in_array($lastError['type'], self::$fatalErrors, true)) {
            $this->logger->log(
                $this->fatalLevel ?? LogLevel::ALERT,
                'Fatal Error (' . self::codeToString($lastError['type']) . '): ' . $lastError['message'],
                [
                    'code' => $lastError['type'],
                    'message' => $lastError['message'],
                    'file' => $lastError['file'],
                    'line' => $lastError['line']
                ]
            );

            if (method_exists($this->logger, 'flush')) {
                $this->logger->flush();
            }

            if ($this->logger instanceof Logger) {
                foreach ($this->logger->getHandlers() as $handler) {
                    if ($handler instanceof AbstractHandler) {
                        $handler->close();
                    }
                }
            }
        }
    }
774149
protected function getMonologHandler()
    {
        return (new StreamHandler($this->path('storage', 'logs/netforce.log'), Logger::DEBUG))->setFormatter(new LineFormatter(null, null, true, true));
    }
414741
public function createLogger()
    {
        $log = new Writer(new Monolog($this->channel()));

        $this->configureHandler($log);

        return $log;
    }
804352
public function showLogView()
    {
        $this->subMenu['log']['active'] = true;

        $log = Log::getLogger();

        $logContents = '';

        collect($log->getHandlers())->reject(function ($handler) {
            return $handler instanceof SyslogHandler;
        })->each(function ($handler) use (&$logContents, $log) {
            if (file_exists($path = $log->getHandlers()[0]->getUrl())) {
                $logContents = file_get_contents($path);
            }
        });

        return View::make('dashboard.settings.log')->withLog($logContents)->withSubMenu($this->subMenu);
    }
703768
public function forDebug()
    {
        return tap(new PrettyPageHandler, function ($handler) {
            $handler->handleUnconditionally(true);

            $this->registerApplicationPaths($handler)
                 ->registerBlacklist($handler)
                 ->registerEditor($handler);
        });
    }
67417
private function createLogger()
    {
        if ($this->silent) {
            $logger = new SilentLogger();
            self::$msgOutputLevel = Project::MSG_WARN;
        } elseif ($this->loggerClassname !== null) {
            self::import($this->loggerClassname);
            // get class name part
            $classname = self::import($this->loggerClassname);
            $logger = new $classname();
            if (!($logger instanceof BuildLogger)) {
                throw new BuildException($classname . ' does not implement the BuildLogger interface.');
            }
        } else {
            $logger = new DefaultLogger();
        }
        $logger->setMessageOutputLevel(self::$msgOutputLevel);
        $logger->setOutputStream(self::$out);
        $logger->setErrorStream(self::$err);
        $logger->setEmacsMode($this->emacsMode);

        return $logger;
    }
391175
public function emergency(
        $msg,
        array $args = array(),
        \Exception $exception = null
    ) {
        return $this->log(\Plop\EMERGENCY, $msg, $args, $exception);
    }
1047711
protected function createCrontab()
    {
        $tasks = $this->formatTasks();
        $missions = array();
        foreach ($tasks as $task) {
            if ($task['out'] instanceof LoggerInterface) {
                $out = $task['out'];
            } else {
                $out = MissionLoggerFactory::create($task['out']);
            }
            if ($task['err'] instanceof LoggerInterface) {
                $err = $task['err'];
            } else {
                $err = MissionLoggerFactory::create($task['err']);
            }

            $mission = new Mission(
                $task['name'],
                $task['cmd'],
                $task['time'],
                $out,
                $err,
                $task['user'],
                $task['group']
            );
            $missions[] = $mission;
        }

        return new Crontab($this->logger, $missions);
    }
1333691
protected static function handleError()
	{
		if(self::$errorHandler === NULL)
		{
			self::$errorHandler = function ($type, $message, $file, $line) {
				throw new \RuntimeException($message);
			};
		}
		
		return self::$errorHandler;
	}
101082
public function getLog()
    {
        if (null == $this->log) {
            $handler    = new StreamHandler($this->_getLogFileName(), Logger::INFO);
            $this->log  = new Logger('VagrantTransient');
            $this->log->pushHandler($handler);
        }
        return $this->log;
    }
1006689
public function getLogger()
    {
        if ($this->logger === null) {
            if ($this->configuration->get('silent')) {
                $this->logger = new Logger\NullLogger();
            } else {
                $loggerClass = $this->configuration->get('logger') ?: '\\Pinocchio\\Logger\\StandardLogger';
                $loggerOpts  = $this->configuration->get('logger_opts') ?: array();

                $this->logger = new $loggerClass($loggerOpts);
            }
        }

        return $this->logger;
    }
234258
public static function shutdownHandler()
    {
        if ($err = error_get_last()) {
            switch ($err['type']) {
                case E_ERROR:
                case E_PARSE:
                case E_COMPILE_ERROR:
                case E_CORE_ERROR:
                    $service = self::$psrLogger
                        ->getMetadataProvider()
                        ->serviceId();
                    $version = self::$psrLogger
                        ->getMetadataProvider()
                        ->versionId();
                    $message = sprintf(
                        '%s: %s in %s on line %d',
                        self::getErrorPrefix($err['type']),
                        $err['message'],
                        $err['file'],
                        $err['line']
                    );
                    $context = [
                        'context' => [
                            'reportLocation' => [
                                'filePath' => $err['file'],
                                'lineNumber' => $err['line'],
                                'functionName' =>
                                    self::getFunctionNameForReport(),
                            ]
                        ],
                        'serviceContext' => [
                            'service' => $service,
                            'version' => $version
                        ]
                    ];
                    if (self::$psrLogger) {
                        self::$psrLogger->log(
                            self::getErrorLevelString($err['type']),
                            $message,
                            $context
                        );
                    }
                    break;
            }
        }
    }
41210
private function setLogger() {

        $config = $this->getConfig();

        if($config->offsetExists('errors') === true && $config->errors === true) {
            $this->logger = new FileAdapter($this->getConfig()->errorLog);
        }

        return $this;
    }
909357
public static function registerErrorHandler()
    {
        if (MELIOR_CONTEXT === 'Production') {
            ini_set('display_errors', 0);
            ini_set('display_startup_errors', 0);
            error_reporting(E_ERROR);
        } else {
            ini_set('display_errors', 1);
            ini_set('display_startup_errors', 1);
            error_reporting(E_ALL);
        }

        $whoops = new Whoops();

        $handler = new PrettyPageHandler();

        $handler->addDataTableCallback('Additional Exception Data', function (\Whoops\Exception\Inspector $inspector) {
            $exception = $inspector->getException();
            $reflector = new \ReflectionClass($exception);

            if ($reflector->isSubclassOf(ContextualException::class)) {
                return $exception->getContext();
            }

            return [];
        });

        $handler->setPageTitle('Whoops! An error occurred.');
        $handler->setApplicationRootPath(
            array_key_exists('MELIOR_DEBUG_BASEPATH', $_SERVER) ?
            $_SERVER['MELIOR_DEBUG_BASEPATH'] :
            MELIOR_BASE
        );

        if (array_key_exists('MELIOR_DEBUG_EDITOR', $_SERVER)) {
            $handler->setEditor($_SERVER['MELIOR_DEBUG_EDITOR']);
        }

        $resourcePath = (new PathHelper())->buildAssetPath('');
        if (file_exists($resourcePath) && is_dir($resourcePath)) {
            $handler->addResourcePath($resourcePath);
            $handler->addCustomCss('Styles/error-page.css');
        }

        $whoops->pushHandler($handler);

        if (WhoopsUtil::isAjaxRequest()) {
            $whoops->pushHandler(new JsonResponseHandler());
        }

        if (WhoopsUtil::isCommandLine()) {
            $whoops->pushHandler(new PlainTextHandler());
        }

        $whoops->register();
    }