feat[logging]: flexible logging support

This commit is contained in:
2026-06-28 00:48:50 +03:00
parent 206a8730a8
commit 17aaa41101
10 changed files with 403 additions and 12 deletions
+18 -1
View File
@@ -1,11 +1,14 @@
import logging
from urllib.parse import urljoin
import requests
from pydantic import TypeAdapter
from .log_fields import OPERATION, PAGE, REPOSITORY_COUNT, STATUS_CODE
from .models import GiteaRepository
REPOSITORIES_ADAPTER = TypeAdapter(list[GiteaRepository])
logger = logging.getLogger(__name__)
class GiteaApi:
@@ -30,7 +33,14 @@ class GiteaApi:
params={"limit": page_size, "page": page_id},
)
if r.status_code != 200:
print(f"Failed request, code {r.status_code}")
logger.error(
"failed to fetch repositories",
extra={
OPERATION: "fetch_repositories",
STATUS_CODE: r.status_code,
PAGE: page_id,
},
)
return []
repos_data = r.json()
if not repos_data:
@@ -40,4 +50,11 @@ class GiteaApi:
cur_repos = REPOSITORIES_ADAPTER.validate_python(repos_data)
for repo in cur_repos:
all_repos[repo.repo_id] = repo
logger.info(
"repositories fetched",
extra={
OPERATION: "fetch_repositories",
REPOSITORY_COUNT: len(all_repos),
},
)
return list(all_repos.values())