private function logLogin(bool $error_username = false, bool $error_password = false, bool $ban = true)
    {
        $text = sprintf('Login for user "%s"', $this->username);
        $state = 0;

        if ($error_username || $error_password) {

            $text .= ' failed because of wrong ';

            if ($error_username) {
                $state += 1;
                $text .= 'username';
            }

            if ($error_password) {
                $state += 2;
                $text .= 'password';
            }

            // Start ban process only when requested and only when state indicates a login error from user credentials
            if ($this->ban && $ban) {
                $banlog = new BanLogEntry($this->db);
                $banlog->setText($text);
                $banlog->setCode($state);
                $banlog->add();
            }

            if (isset($this->logger)) {
                $this->logger->warning($text, [$state]);
            }

            return;
        }

        // Still here? Log success!
        if (isset($this->logger)) {
            $this->logger->info($text . ' success');
        }
    }