logPrefix = $logPrefix; return $this; } public function withActivityLogExceptions(array $activityLogExceptions): self { $this->activityLogExceptions = $activityLogExceptions; return $this; } public function log(\Throwable $e, ?string $message = null, array $data = [], string $severity = ActivityLog::SEVERITY_ERROR): void { if (isLocalDevelopment()) { throw $e; } // chyby, ktere maji jit do activity logu if ($this->isActivityLogException($e)) { if ($e instanceof CustomDataExceptionInterface) { $data = array_merge($data, $e->getData()); } $this->activity( $message ?: "Během synchronizace vznikla chyba: {$e->getMessage()}", $data, $severity ); return; } // Lock wait timeout a deadlock nechci logovat if ($e instanceof LockWaitTimeoutException || $e instanceof DeadlockException) { return; } // ostatni chyby do Sentry $this->sentryLogger->captureException($e, $data); } public function activity(string $message, array $data, string $severity = ActivityLog::SEVERITY_ERROR): int { return addActivityLog($severity, ActivityLog::TYPE_SYNC, $this->getMessageWithPrefix($message), $data); } public function kibana(string $message, array $data): void { $this->logger->notice( $this->getMessageWithPrefix($message), $data ); } private function getMessageWithPrefix(string $message): string { if (!$this->logPrefix) { return $message; } return "[{$this->logPrefix}] {$message}"; } private function isActivityLogException(\Throwable $e): bool { foreach ($this->activityLogExceptions as $class) { if (is_a($e, $class)) { return true; } } return false; } }