mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Add rich handler for better-formatted debug logging (#1627)
This commit is contained in:
parent
44e2ace833
commit
cd47070894
3 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,8 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from rich.logging import RichHandler
|
||||||
|
|
||||||
from jrnl.args import parse_args
|
from jrnl.args import parse_args
|
||||||
from jrnl.exception import JrnlException
|
from jrnl.exception import JrnlException
|
||||||
from jrnl.jrnl import run
|
from jrnl.jrnl import run
|
||||||
|
@ -21,7 +23,9 @@ def configure_logger(debug=False):
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format="%(levelname)-8s %(name)-12s %(message)s",
|
datefmt="[%X]",
|
||||||
|
format="%(message)s",
|
||||||
|
handlers=[RichHandler()],
|
||||||
)
|
)
|
||||||
logging.getLogger("parsedatetime").setLevel(logging.INFO)
|
logging.getLogger("parsedatetime").setLevel(logging.INFO)
|
||||||
logging.getLogger("keyring.backend").setLevel(logging.ERROR)
|
logging.getLogger("keyring.backend").setLevel(logging.ERROR)
|
||||||
|
@ -34,7 +38,7 @@ def cli(manual_args=None):
|
||||||
|
|
||||||
args = parse_args(manual_args)
|
args = parse_args(manual_args)
|
||||||
configure_logger(args.debug)
|
configure_logger(args.debug)
|
||||||
logging.debug("Parsed args: %s", args)
|
logging.debug("Parsed args:\n%s", args)
|
||||||
|
|
||||||
status_code = run(args)
|
status_code = run(args)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from typing import Callable
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
import xdg.BaseDirectory
|
import xdg.BaseDirectory
|
||||||
|
from rich.pretty import pretty_repr
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
from ruamel.yaml import constructor
|
from ruamel.yaml import constructor
|
||||||
|
|
||||||
|
@ -126,12 +127,15 @@ def scope_config(config, journal_name):
|
||||||
if type(journal_conf) is dict:
|
if type(journal_conf) is dict:
|
||||||
# We can override the default config on a by-journal basis
|
# We can override the default config on a by-journal basis
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Updating configuration with specific journal overrides %s", journal_conf
|
"Updating configuration with specific journal overrides:\n%s",
|
||||||
|
pretty_repr(journal_conf),
|
||||||
)
|
)
|
||||||
config.update(journal_conf)
|
config.update(journal_conf)
|
||||||
else:
|
else:
|
||||||
# But also just give them a string to point to the journal file
|
# But also just give them a string to point to the journal file
|
||||||
config["journal"] = journal_conf
|
config["journal"] = journal_conf
|
||||||
|
|
||||||
|
logging.debug("Scoped config:\n%s", pretty_repr(config))
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from rich.pretty import pretty_repr
|
||||||
|
|
||||||
from jrnl.config import DEFAULT_JOURNAL_KEY
|
from jrnl.config import DEFAULT_JOURNAL_KEY
|
||||||
from jrnl.config import get_config_path
|
from jrnl.config import get_config_path
|
||||||
from jrnl.config import get_default_config
|
from jrnl.config import get_default_config
|
||||||
|
@ -101,7 +103,7 @@ def load_or_install_jrnl(alt_config_path):
|
||||||
logging.debug("Configuration file not found, installing jrnl...")
|
logging.debug("Configuration file not found, installing jrnl...")
|
||||||
config = install()
|
config = install()
|
||||||
|
|
||||||
logging.debug('Using configuration "%s"', config)
|
logging.debug('Using configuration:\n"%s"', pretty_repr(config))
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue