]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Logger/Type/WorkerLogger.php
Move Monolog to Addons
[friendica.git] / src / Core / Logger / Type / WorkerLogger.php
index fcbe1280133cd6f8d5883ba754396d25572a8239..5d03db9498ee8874b2f2ba18f8fbca309ec9d1a7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -31,6 +31,9 @@ use Psr\Log\LoggerInterface;
  */
 class WorkerLogger implements LoggerInterface
 {
+       /** @var int Length of the unique worker id */
+       const WORKER_ID_LENGTH = 7;
+
        /**
         * @var LoggerInterface The original Logger instance
         */
@@ -48,17 +51,14 @@ class WorkerLogger implements LoggerInterface
 
        /**
         * @param LoggerInterface $logger       The logger for worker entries
-        * @param string          $functionName The current function name of the worker
-        * @param int             $idLength     The length of the generated worker ID
         *
         * @throws LoggerException
         */
-       public function __construct(LoggerInterface $logger, string $functionName = '', int $idLength = 7)
+       public function __construct(LoggerInterface $logger)
        {
-               $this->logger       = $logger;
-               $this->functionName = $functionName;
+               $this->logger = $logger;
                try {
-                       $this->workerId = Strings::getRandomHex($idLength);
+                       $this->workerId = Strings::getRandomHex(self::WORKER_ID_LENGTH);
                } catch (\Exception $exception) {
                        throw new LoggerException('Cannot generate random Hex.', $exception);
                }
@@ -68,10 +68,17 @@ class WorkerLogger implements LoggerInterface
         * Sets the function name for additional logging
         *
         * @param string $functionName
+        *
+        * @throws LoggerException
         */
        public function setFunctionName(string $functionName)
        {
                $this->functionName = $functionName;
+               try {
+                       $this->workerId = Strings::getRandomHex(self::WORKER_ID_LENGTH);
+               } catch (\Exception $exception) {
+                       throw new LoggerException('Cannot generate random Hex.', $exception);
+               }
        }
 
        /**