1
0
mirror of https://github.com/ihabunek/toot synced 2024-12-23 07:27:12 +01:00

Respect debug and debug_file settings

This commit is contained in:
Ivan Habunek 2023-06-28 14:09:55 +02:00
parent ee20b7ac0e
commit cee2c93815
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 22 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import sys
from argparse import ArgumentParser, FileType, ArgumentTypeError, Action
from collections import namedtuple
from itertools import chain
from toot import config, commands, CLIENT_NAME, CLIENT_WEBSITE, __version__
from toot import config, commands, CLIENT_NAME, CLIENT_WEBSITE, __version__, settings
from toot.exceptions import ApiError, ConsoleError
from toot.output import print_out, print_err
from toot.settings import get_setting
@ -932,9 +932,8 @@ def run_command(app, user, name, args):
def main():
# Enable debug logging if --debug is in args
if "--debug" in sys.argv:
filename = os.getenv("TOOT_LOG_FILE")
if settings.get_debug():
filename = settings.get_debug_file()
logging.basicConfig(level=logging.DEBUG, filename=filename)
logging.getLogger("urllib3").setLevel(logging.INFO)

View File

@ -1,8 +1,11 @@
import os
import sys
from functools import lru_cache
from os.path import exists, join
from tomlkit import parse
from toot.config import get_config_dir
from typing import Type
from typing import Optional, Type
TOOT_SETTINGS_FILE_NAME = "settings.toml"
@ -51,3 +54,18 @@ def _get_setting(dct, keys, type: Type, default=None):
return _get_setting(dct[key], keys[1:], type, default)
return default
def get_debug() -> bool:
if "--debug" in sys.argv:
return True
return get_setting("common.debug", bool, False)
def get_debug_file() -> Optional[str]:
from_env = os.getenv("TOOT_LOG_FILE")
if from_env:
return from_env
return get_setting("common.debug_file", str)