logger = new Logger(\config('id')); $this->levels = [ 'debug' => $this->logger::DEBUG, 'info' => $this->logger::INFO, 'notice' => $this->logger::NOTICE, 'warning' => $this->logger::WARNING, 'error' => $this->logger::ERROR, 'critical' => $this->logger::CRITICAL, 'alert' => $this->logger::ALERT, 'emergency' => $this->logger::EMERGENCY, ]; } /** * @param $message * @param string $model * @return bool */ public function failure($message, string $model = 'app'): bool { if ($message instanceof \Exception) { $this->errors[$model] = $message->getMessage(); } else { $this->errors[$model] = $message; } $this->error(throwable($message), []); return false; } /** * @param string $name * @param array $arguments * @return void * @throws ReflectionException */ public function __call(string $name, array $arguments) { try { if (method_exists($this->logger, $name)) { $this->createHandler($name)->$name(...$arguments); } else if (method_exists($this, $name)) { $this->{$name}(...$arguments); } } catch (\Throwable $exception) { echo $exception->getMessage() . PHP_EOL; } } /** * @param string $name * @return Logger */ protected function createHandler(string $name): Logger { if (!$this->logger->isHandling($this->levels[$name])) { $this->logger->pushHandler(new StreamHandler(APP_PATH . 'storage/logs/' . $name . '/' . date('Y-m-d') . '.log', $this->levels[$name])); } return $this->logger; } /** * @param string $model * @return mixed */ public function getLastError(string $model = 'app'): mixed { return $this->errors[$model] ?? 'Unknown error.'; } }