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