Respect debug and debug_file settings
This commit is contained in:
parent
ee20b7ac0e
commit
cee2c93815
2 changed files with 22 additions and 5 deletions
|
@ -7,7 +7,7 @@ import sys
|
||||||
from argparse import ArgumentParser, FileType, ArgumentTypeError, Action
|
from argparse import ArgumentParser, FileType, ArgumentTypeError, Action
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import chain
|
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.exceptions import ApiError, ConsoleError
|
||||||
from toot.output import print_out, print_err
|
from toot.output import print_out, print_err
|
||||||
from toot.settings import get_setting
|
from toot.settings import get_setting
|
||||||
|
@ -932,9 +932,8 @@ def run_command(app, user, name, args):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Enable debug logging if --debug is in args
|
if settings.get_debug():
|
||||||
if "--debug" in sys.argv:
|
filename = settings.get_debug_file()
|
||||||
filename = os.getenv("TOOT_LOG_FILE")
|
|
||||||
logging.basicConfig(level=logging.DEBUG, filename=filename)
|
logging.basicConfig(level=logging.DEBUG, filename=filename)
|
||||||
logging.getLogger("urllib3").setLevel(logging.INFO)
|
logging.getLogger("urllib3").setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from os.path import exists, join
|
from os.path import exists, join
|
||||||
from tomlkit import parse
|
from tomlkit import parse
|
||||||
from toot.config import get_config_dir
|
from toot.config import get_config_dir
|
||||||
from typing import Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
|
|
||||||
TOOT_SETTINGS_FILE_NAME = "settings.toml"
|
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 _get_setting(dct[key], keys[1:], type, default)
|
||||||
|
|
||||||
return 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)
|
||||||
|
|
Loading…
Reference in a new issue