diff --git a/monolog/README.md b/monolog/README.md new file mode 100644 index 00000000..efb7959a --- /dev/null +++ b/monolog/README.md @@ -0,0 +1,4 @@ +# Monolog Addon + +A Logging framework with lots of additions (see [Monolog](https://github.com/Seldaek/monolog/)). +There are just Friendica additions inside the src directory. diff --git a/monolog/monolog.php b/monolog/monolog.php index b13efff9..f194aac4 100644 --- a/monolog/monolog.php +++ b/monolog/monolog.php @@ -1,7 +1,7 @@ introspection = $introspection; + $this->config = $config; + } + + /** + * Creates and returns a PSR-3 Logger instance. + * + * Calling this method multiple times with the same parameters SHOULD return the same object. + * + * @param \Psr\Log\LogLevel::* $logLevel The log level + * @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel + */ + public function createLogger(string $logLevel, string $logChannel): LoggerInterface { $loggerTimeZone = new \DateTimeZone('UTC'); - $logger = new Logger($this->channel); + $logger = new Logger($logChannel); $logger->setTimezone($loggerTimeZone); $logger->pushProcessor(new PsrLogMessageProcessor()); $logger->pushProcessor(new ProcessIdProcessor()); $logger->pushProcessor(new UidProcessor()); $logger->pushProcessor(new IntrospectionProcessor($this->introspection, LogLevel::DEBUG)); - $logfile = $config->get('system', 'logfile'); + $logfile = $this->config->get('system', 'logfile'); // just add a stream in case it's either writable or not file if (is_writable($logfile)) { - $loglevel = $loglevel ?? static::mapLegacyConfigDebugLevel($config->get('system', 'loglevel')); - $loglevel = Logger::toMonologLevel($loglevel); + $logLevel = Logger::toMonologLevel($logLevel); // fallback to notice if an invalid loglevel is set - if (!is_int($loglevel)) { - $loglevel = LogLevel::NOTICE; + if (!is_int($logLevel)) { + $logLevel = LogLevel::NOTICE; } - $fileHandler = new StreamHandler($logfile, $loglevel); + $fileHandler = new StreamHandler($logfile, $logLevel); $formatter = new LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n"); $fileHandler->setFormatter($formatter); diff --git a/monolog/static/dependencies.config.php b/monolog/static/dependencies.config.php index e3066594..75ea8df7 100644 --- a/monolog/static/dependencies.config.php +++ b/monolog/static/dependencies.config.php @@ -20,10 +20,7 @@ */ return [ - \Monolog\Logger::class => [ - 'instanceOf' => \Friendica\Addon\monolog\src\Factory\Monolog::class, - 'call' => [ - ['create', [], \Dice\Dice::CHAIN_CALL], - ], + \Friendica\Core\Logger\Factory\LoggerFactory::class => [ + 'instanceOf' => \Friendica\Addon\monolog\src\Factory\MonologFactory::class, ], ]; diff --git a/monolog/static/strategies.config.php b/monolog/static/strategies.config.php deleted file mode 100644 index 87153839..00000000 --- a/monolog/static/strategies.config.php +++ /dev/null @@ -1,26 +0,0 @@ -. - * - */ - -return [ - \Psr\Log\LoggerInterface::class => [ - \Monolog\Logger::class => ['monolog'], - ], -];