Carries out all actions necessary to prepare the logging backend, such as opening
the log file or opening a database connection.

@return void
@throws CouldNotOpenResourceException
@api
960466
public function open()
    {
        $this->severityLabels = [
            LOG_EMERG   => 'EMERGENCY',
            LOG_ALERT   => 'ALERT    ',
            LOG_CRIT    => 'CRITICAL ',
            LOG_ERR     => 'ERROR    ',
            LOG_WARNING => 'WARNING  ',
            LOG_NOTICE  => 'NOTICE   ',
            LOG_INFO    => 'INFO     ',
            LOG_DEBUG   => 'DEBUG    ',
        ];

        if (file_exists($this->logFileUrl) && $this->maximumLogFileSize > 0 && filesize($this->logFileUrl) > $this->maximumLogFileSize) {
            $this->rotateLogFile();
        }

        if (file_exists($this->logFileUrl)) {
            $this->fileHandle = fopen($this->logFileUrl, 'ab');
        } else {
            $logPath = dirname($this->logFileUrl);
            if (!file_exists($logPath) || (!is_dir($logPath) && !is_link($logPath))) {
                if ($this->createParentDirectories === false) {
                    throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access because the parent directory does not exist.', 1243931200);
                }
                Files::createDirectoryRecursively($logPath);
            }

            $this->fileHandle = fopen($this->logFileUrl, 'ab');
            if ($this->fileHandle === false) {
                throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1243588980);
            }

            $streamMeta = stream_get_meta_data($this->fileHandle);
            if ($streamMeta['wrapper_type'] === 'plainfile') {
                fclose($this->fileHandle);
                chmod($this->logFileUrl, 0666);
                $this->fileHandle = fopen($this->logFileUrl, 'ab');
            }
        }
        if ($this->fileHandle === false) {
            throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1229448440);
        }
    }
702824
protected function prepare() : void
    {
        if ($this->prepared) {
            return;
        }

        if ($this->cacheEnabled && file_exists($this->cacheFile)) {
            $this->loadFromCache();
            $this->prepared = true;
            return;
        }

        $routeCollector = new RouteCollector();
        $routeDefinitionCallback = $this->routeDefinitionCallback;
        $routeDefinitionCallback($routeCollector);

        $data = $routeCollector->generateRoutesData(
            new StdParser(),
            new DataGeneratorGroupCountBased()
        );
        $this->routes = $data['routes'];
        $this->dispatchData = $data['dispatch_data'];

        if ($this->cacheEnabled) {
            $this->saveToCache($data);
        }

        $this->prepared = true;
    }
330258
protected function initResourceDir()
    {
        $this->resourceDir = [];

        $this->addResourceDir($this->getBBDir().'/Resources');

        if (is_dir($this->getBaseRepository().'/Resources')) {
            $this->addResourceDir($this->getBaseRepository().'/Resources');
        }

        if (is_dir($this->getBaseRepository().'/Ressources')) {
            $this->addResourceDir($this->getBaseRepository().'/Ressources');
        }

        if ($this->hasContext()) {
            if (is_dir($this->getRepository().'/Resources')) {
                $this->addResourceDir($this->getRepository().'/Resources');
            }

            if (is_dir($this->getRepository().'/Resources')) {
                $this->addResourceDir($this->getRepository().'/Resources');
            }
        }

        array_map(['BackBee\Utils\File\File', 'resolveFilepath'], $this->resourceDir);
    }
262398
public function setup_actions() {
		if ( ! $this->is_logger_active() ) {
			return;
		}
		$action_key = $this->product->get_key() . '_log_activity';
		if ( ! wp_next_scheduled( $action_key ) ) {
			wp_schedule_single_event( time() + ( rand( 1, 24 ) * 3600 ), $action_key );
		}
		add_action( $action_key, array( $this, 'send_log' ) );

	}
1067816
public function openLog() {
        if ($this->file) {

            $logDir = dirname($this->file);
            if (!is_dir($logDir) || !file_exists($logDir)) {
                @mkdir($logDir, 0755, true);
            }

            if (!file_exists($this->file)) {
                $touched = touch($this->file);
                if (!$touched) {
                    throw new \Exception("Unable to open log file '{$this->file}', could not create");
                }
            }

            if (!is_writable($this->file)) {
                throw new \Exception("Unable to open log file '{$this->file}', not writable");
            }
            $this->fr = fopen($this->file, 'a');
        }
    }
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;
    }
543434
protected function applyOpenBaseDirSetting() {
		if($this->openBaseDirs) {
			$value = implode(PATH_SEPARATOR, $this->openBaseDirs);
			if(ini_get('open_basedir') != $value) {
				$this->forcePhpConsoleClassesAutoLoad();
				if(ini_set('open_basedir', $value) === false) {
					throw new \Exception('Unable to set "open_basedir" php.ini setting');
				}
			}
		}
	}
98505
private function onReadable()
    {
        $data = @\stream_get_contents($this->socket, $this->options->getChunkSize());
        if ($data !== false && $data !== "") {
            $this->timeoutCache->renew($this->id);
            $this->parse($data);
            return;
        }

        if (!\is_resource($this->socket) || @\feof($this->socket)) {
            $this->close();
        }
    }
766060
private function open()
    {
        if (null === ($this->handle = fopen($this->file, 'rb'))) {
            $this->handle = null;

            throw new RuntimeException(
                sprintf(
                    'The file "%s" could not be opened for reading.',
                    $this->file
                )
            );
        }
    }
1057875
protected function prepareResources()
    {
        $config = realpath(__DIR__.'/../config/config.php');

        $this->mergeConfigFrom($config, 'cartalyst.alerts');

        $this->publishes([
            $config => config_path('cartalyst.alerts.php'),
        ], 'config');
    }
320844
protected function handleSolrUnavailable()
    {
        if ($this->typoScriptConfiguration->getLoggingExceptions()) {
            /** @var SolrLogManager $logger */
            $logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
            $logger->log(SolrLogManager::ERROR, 'Solr server is not available');
        }
    }
884210
public function prePersist()
    {
        if (!$this->getCreatedAt()) {
            $this->setCreatedAt(new \DateTime());
        }

        if (!$this->getUpdatedAt()) {
            $this->setUpdatedAt(new \DateTime());
        }
    }
730291
protected static function startForcedLog()
    {
        Pool::createPool();

        // Output destination: file
        static::$pool->config
            ->settings[Fallback::SETTING_DESTINATION]
            ->setSource('forced logging')
            ->setValue(Fallback::VALUE_FILE);

        // Do not care about ajax requests.
        static::$pool->config
            ->settings[Fallback::SETTING_DETECT_AJAX]
            ->setSource('forced logging')
            ->setValue(false);

        // Reload the disabled settings with the new ajax setting.
         static::$pool->config
            ->loadConfigValue(Fallback::SETTING_DISABLED);
    }
1119601
protected function onInit()
    {
        $host = Util::get($this->params, "host", "");//host\instanceName
        $username = Util::get($this->params, "username", "");
        $password = Util::get($this->params, "password", "");
        $dbname = Util::get($this->params, "dbname", "");
        $connString = "host=$host dbname=$dbname user=$username password=$password";
        
        $key = md5($connString);

        if (isset(PostgreSQLDataSource::$connections[$key])) {
            $this->connection = PostgreSQLDataSource::$connections[$key];
        } else {
            $conn = pg_connect($connString);
            if ($conn) {
                $this->connection = $conn;
            } else {
                throw new \Exception("Could not connect to database");
            }
            PostgreSQLDataSource::$connections[$key] = $this->connection;
        }
        
    }
45551
public function logger() : void
  {
    LogHandler::$disk = DEPConfig::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR;
    LogHandler::$name = config('app.logger.name');
    LogHandler::$log  = config('app.logger.log');
    LogHandler::$env  = config('app.env');

    LogHandler::event(function($env, $level, $message, $array) {
      Events::trigger('output.log', [$env, $level, $message, $array]);
    });
  }
423080
protected function prepare()
    {
        // Log
        $this->log('Initializing started ', $this->loglevel);

        ///// Validating the required parameters /////

        if (!in_array($this->type, self::$types)) {
            throw new BuildException('Type must be one of \'file\', \'dir\' or \'both\'.');
        }

        // Executable
        if ($this->commandline->getExecutable() === null) {
            $this->throwBuildException('Please provide "executable" information');
        }

        // Retrieving the current working directory
        $this->currentdirectory = getcwd();

        // Directory (in which the command should be executed)
        if ($this->dir !== null) {
            // Try expanding (any) symbolic links
            if (!$this->dir->getCanonicalFile()->isDirectory()) {
                $this->throwBuildException("'" . $this->dir . "' is not a valid directory");
            }

            // Change working directory
            $dirchangestatus = @chdir($this->dir->getPath());

            // Log
            $this->log(
                'Working directory change ' . ($dirchangestatus ? 'successful' : 'failed') . ' to ' . $this->dir->getPath(),
                $this->loglevel
            );
        }

        ///// Preparing the task environment /////

        // Getting current operationg system
        $this->currentos = Phing::getProperty('os.name');

        // Log
        $this->log('Operating System identified : ' . $this->currentos, $this->loglevel);

        // Getting the O.S. type identifier
        // Validating the 'filesystem' for determining the OS type [UNIX, WINNT and WIN32]
        // (Another usage could be with 'os.name' for determination)
        if ('WIN' === strtoupper(substr(Phing::getProperty('host.fstype'), 0, 3))) {
            $this->osvariant = 'WIN'; // Probable Windows flavour
        } else {
            $this->osvariant = 'LIN'; // Probable GNU/Linux flavour
        }

        // Log
        $this->log('Operating System variant identified : ' . $this->osvariant, $this->loglevel);

        if (count($this->filesets) === 0 && count($this->filelists) === 0 && count($this->getDirSets()) === 0) {
            throw new BuildException(
                "no resources specified",
                $this->getLocation()
            );
        }
        if ($this->targetFilePos !== null && $this->mapperElement === null) {
            throw new BuildException(
                "targetfile specified without mapper",
                $this->getLocation()
            );
        }
        if ($this->destDir !== null && $this->mapperElement === null) {
            throw new BuildException(
                "dest specified without mapper",
                $this->getLocation()
            );
        }

        if ($this->mapperElement !== null) {
            $this->mapper = $this->mapperElement->getImplementation();
            $this->log('Mapper identified : ' . get_class($this->mapper), $this->loglevel);
        }

        $this->commandline->setEscape($this->escape);

        // Log
        $this->log('Initializing completed ', $this->loglevel);
    }
754142
private function preprocess()
    {
        $this->do_action('afw_options_pre_process');
        Notifier::reset();
        State::set('errors', array());
        $this->update();
        $this->do_action('afw_options_post_process');
    }