feat[logging]: flexible logging support
This commit is contained in:
+18
-1
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user