Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rich handler to debug logging #1627

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions jrnl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
import traceback

from rich.logging import RichHandler

from jrnl.args import parse_args
from jrnl.exception import JrnlException
from jrnl.jrnl import run
Expand All @@ -21,7 +23,9 @@ def configure_logger(debug=False):

logging.basicConfig(
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("keyring.backend").setLevel(logging.ERROR)
Expand All @@ -34,7 +38,7 @@ def cli(manual_args=None):

args = parse_args(manual_args)
configure_logger(args.debug)
logging.debug("Parsed args: %s", args)
logging.debug("Parsed args:\n%s", args)

status_code = run(args)

Expand Down
6 changes: 5 additions & 1 deletion jrnl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import colorama
import xdg.BaseDirectory
from rich.pretty import pretty_repr
from ruamel.yaml import YAML
from ruamel.yaml import constructor

Expand Down Expand Up @@ -126,12 +127,15 @@ def scope_config(config, journal_name):
if type(journal_conf) is dict:
# We can override the default config on a by-journal basis
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)
else:
# But also just give them a string to point to the journal file
config["journal"] = journal_conf

logging.debug("Scoped config:\n%s", pretty_repr(config))
return config


Expand Down
4 changes: 3 additions & 1 deletion jrnl/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
import sys

from rich.pretty import pretty_repr

from jrnl.config import DEFAULT_JOURNAL_KEY
from jrnl.config import get_config_path
from jrnl.config import get_default_config
Expand Down Expand Up @@ -101,7 +103,7 @@ def load_or_install_jrnl(alt_config_path):
logging.debug("Configuration file not found, installing jrnl...")
config = install()

logging.debug('Using configuration "%s"', config)
logging.debug('Using configuration:\n"%s"', pretty_repr(config))
return config


Expand Down