<commit_before><?php

namespace Friendica\Factory;

use Friendica\Core\Config\Configuration;
use Friendica\Core\Logger;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Logger\FriendicaDevelopHandler;
use Friendica\Util\Logger\Introspection;
use Friendica\Util\Logger\SyslogLogger;
use Friendica\Util\Logger\VoidLogger;
use Friendica\Util\Logger\WorkerLogger;
use Friendica\Util\Profiler;
use Monolog;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
 * A logger factory
 *
 * Currently only Monolog is supported
 */
class LoggerFactory
{
	/**
	 * A list of classes, which shouldn't get logged
	 * @var array
	 */
	private static $ignoreClassList = [
		Logger::class,
		Profiler::class,
		WorkerLogger::class
	];

	/**
	 * Creates a new PSR-3 compliant logger instances
	 *
	 * @param string        $channel The channel of the logger instance
	 * @param Configuration $config  The config
	 *
	 * @return LoggerInterface The PSR-3 compliant logger instance
	 * @throws InternalServerErrorException
	 */
	public static function create($channel, Configuration $config)
	{
		if (empty($config->get('system', 'debugging', false))) {
			return new VoidLogger();
		}

		$introspector = new Introspection(LogLevel::DEBUG, self::$ignoreClassList);
		switch ($config->get('system', 'logger_adapter', 'monolog')) {
			case 'syslog':
				$level = $config->get('system', 'loglevel');

				$logger = new SyslogLogger($channel, $introspector, $level);
				break;
			case 'monolog':
			default:
				$loggerTimeZone = new \DateTimeZone('UTC');
				Monolog\Logger::setTimezone($loggerTimeZone);

				$logger = new Monolog\Logger($channel);
				$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
				$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
				$logger->pushProcessor(new Monolog\Processor\UidProcessor());
				$logger->pushProcessor($introspector);<commit_msg>Logger - Forgot Logger::init() with VoidLogger<commit_after><?php

namespace Friendica\Factory;

use Friendica\Core\Config\Configuration;
use Friendica\Core\Logger;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Logger\FriendicaDevelopHandler;
use Friendica\Util\Logger\Introspection;
use Friendica\Util\Logger\SyslogLogger;
use Friendica\Util\Logger\VoidLogger;
use Friendica\Util\Logger\WorkerLogger;
use Friendica\Util\Profiler;
use Monolog;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
 * A logger factory
 *
 * Currently only Monolog is supported
 */
class LoggerFactory
{
	/**
	 * A list of classes, which shouldn't get logged
	 * @var array
	 */
	private static $ignoreClassList = [
		Logger::class,
		Profiler::class,
		WorkerLogger::class
	];

	/**
	 * Creates a new PSR-3 compliant logger instances
	 *
	 * @param string        $channel The channel of the logger instance
	 * @param Configuration $config  The config
	 *
	 * @return LoggerInterface The PSR-3 compliant logger instance
	 * @throws InternalServerErrorException
	 */
	public static function create($channel, Configuration $config)
	{
		if (empty($config->get('system', 'debugging', false))) {
			$logger = new VoidLogger();
			Logger::init($logger);
			return $logger;
		}

		$introspector = new Introspection(LogLevel::DEBUG, self::$ignoreClassList);
		switch ($config->get('system', 'logger_adapter', 'monolog')) {
			case 'syslog':
				$level = $config->get('system', 'loglevel');

				$logger = new SyslogLogger($channel, $introspector, $level);
				break;
			case 'monolog':
			default:
				$loggerTimeZone = new \DateTimeZone('UTC');
				Monolog\Logger::setTimezone($loggerTimeZone);

				$logger = new Monolog\Logger($channel);
				$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
				$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
				$logger->pushProcessor(new Monolog\Processor\UidProcessor());
				$logger->pushProcessor($introspector);
{'fraction_non_alphanumeric': 0.12693184697238408, 'fraction_numerical': 0.0010134279199391944, 'mean_word_length': 4.848888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3925402', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1146, 'n_words': 270}