Back to CMSApplication class

Method setupLogging

private void
setupLogging
()
Setup logging functionality.
Returns
  • void
Since
  • 4.0.0

Method setupLogging - Source code

/**
 * Setup logging functionality.
 *
 * @return void
 *
 * @since   4.0.0
 */
private function setupLogging() : void
{
    // Add InMemory logger that will collect all log entries to allow to display them later by extensions
    if ($this->get('debug')) {
        Log::addLogger(['logger' => 'inmemory']);
    }
    // Log the deprecated API.
    if ($this->get('log_deprecated')) {
        Log::addLogger(['text_file' => 'deprecated.php'], Log::ALL, ['deprecated']);
    }
    // We only log errors unless Site Debug is enabled
    $logLevels = Log::ERROR | Log::CRITICAL | Log::ALERT | Log::EMERGENCY;
    if ($this->get('debug')) {
        $logLevels = Log::ALL;
    }
    Log::addLogger(['text_file' => 'joomla_core_errors.php'], $logLevels, ['system']);
    // Log everything (except deprecated APIs, these are logged separately with the option above).
    if ($this->get('log_everything')) {
        Log::addLogger(['text_file' => 'everything.php'], Log::ALL, ['deprecated', 'deprecation-notes', 'databasequery'], true);
    }
    if ($this->get('log_categories')) {
        $priority = 0;
        foreach ($this->get('log_priorities', ['all']) as $p) {
            $const = '\\Joomla\\CMS\\Log\\Log::' . strtoupper($p);
            if (defined($const)) {
                $priority |= constant($const);
            }
        }
        // Split into an array at any character other than alphabet, numbers, _, ., or -
        $categories = preg_split('/[^\\w.-]+/', $this->get('log_categories', ''), -1, PREG_SPLIT_NO_EMPTY);
        $mode = (bool) $this->get('log_category_mode', false);
        if (!$categories) {
            return;
        }
        Log::addLogger(['text_file' => 'custom-logging.php'], $priority, $categories, $mode);
    }
}