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
+67 -1
View File
@@ -2,7 +2,13 @@ from tempfile import NamedTemporaryFile
import pytest
from src.config import Config, FetchConfig, read_toml_config
from src.config import (
Config,
FetchConfig,
LoggingConfig,
read_toml_config,
)
from src.models import LoggingOutputConfig
@pytest.mark.parametrize(
@@ -22,6 +28,7 @@ from src.config import Config, FetchConfig, read_toml_config
out_dir="/home/user/repositories",
endpoint="https://example.com",
fetch=FetchConfig(ssh_key="/tmp/no_key"),
logging=LoggingConfig(),
),
),
(
@@ -39,6 +46,65 @@ from src.config import Config, FetchConfig, read_toml_config
out_dir="/home/user/repositories",
endpoint="https://example.com",
fetch=FetchConfig(user="alex", token="repo-token"),
logging=LoggingConfig(),
),
),
(
'[main]\napi_token = "something"\n'
'format = "{owner}/{name}"\n'
'endpoint = "https://example.com"\n'
'out_dir = "/home/user/repositories"\n'
"\n"
"[fetch]\n"
'ssh_key = "/tmp/no_key"\n'
"\n"
"[logging]\n"
'level = "DEBUG"\n'
"\n"
"[[logging.outputs]]\n"
'type = "console"\n'
'format = "plain"\n'
'stream = "stdout"\n'
"\n"
"[[logging.outputs]]\n"
'type = "console"\n'
'format = "json"\n'
'stream = "stderr"\n'
"\n"
"[[logging.outputs]]\n"
'type = "file"\n'
'path = "/tmp/gitea-mirror.log"\n'
'format = "json"\n'
"max_size = 1048576\n"
"backup_count = 3",
Config(
api_token="something",
repository_format="{owner}/{name}",
out_dir="/home/user/repositories",
endpoint="https://example.com",
fetch=FetchConfig(ssh_key="/tmp/no_key"),
logging=LoggingConfig(
level="DEBUG",
outputs=[
LoggingOutputConfig(
type="console",
format="plain",
stream="stdout",
),
LoggingOutputConfig(
type="console",
format="json",
stream="stderr",
),
LoggingOutputConfig(
type="file",
path="/tmp/gitea-mirror.log",
format="json",
max_size=1048576,
backup_count=3,
),
],
),
),
),
("[main]", None),