Skip to content

Commit 0716607

Browse files
authored
Fix #55: Improved Logging (#83)
* fix#55: updated logging Signed-off-by: sushant-suse <[email protected]> * fix#55: worked on the NameError and AttributeError issues Signed-off-by: sushant-suse <[email protected]> * fix#55: worked on the NameError and AttributeError issues Signed-off-by: sushant-suse <[email protected]> * fix#55: worked on the NameError and AttributeError issues Signed-off-by: sushant-suse <[email protected]> * fix#55: renamed the changelog file with correct PR number Signed-off-by: sushant-suse <[email protected]> * fix#55: modified as per Toms suggestions Signed-off-by: sushant-suse <[email protected]> --------- Signed-off-by: sushant-suse <[email protected]>
1 parent 4daccc9 commit 0716607

10 files changed

Lines changed: 265 additions & 338 deletions

File tree

changelog.d/83.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a bug where `INFO` and `DEBUG` level logs were not written to the log file. The logging system is now non-blocking and fully configurable via `pyproject.toml`.

src/docbuild/cli/callback.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..models.doctype import Doctype
77
from ..utils.merge import merge_doctypes
88

9-
#
109
log = logging.getLogger(__name__)
1110

1211

src/docbuild/cli/cmd_cli.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
from pathlib import Path
44
import sys
5-
5+
import logging
66
import click
7+
import rich.console
8+
import rich.logging
9+
from rich.pretty import install
10+
from rich.traceback import install as install_traceback
711

812
from ..__about__ import __version__
913
from ..config.app import replace_placeholders
@@ -29,6 +33,14 @@
2933
PYTHON_VERSION = (
3034
f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}'
3135
)
36+
# Global instance of Rich Console
37+
CONSOLE = rich.console.Console(stderr=True, highlight=False)
38+
39+
def _setup_console() -> None:
40+
"""Configures the rich console."""
41+
install_traceback(console=CONSOLE, show_locals=True)
42+
# The Rich console is now handled by the logging setup.
43+
# install(console=CONSOLE)
3244

3345
@click.group(
3446
name=APP_NAME,
@@ -38,7 +50,6 @@
3850
)
3951
@click.version_option(
4052
__version__,
41-
# package_name=__package__,
4253
prog_name=APP_NAME,
4354
message=f"%(prog)s, version %(version)s running Python {PYTHON_VERSION}",
4455
)
@@ -97,7 +108,6 @@ def cli(
97108
:param env_config: Filename to a environment's TOML config file.
98109
:param kwargs: Additional keyword arguments.
99110
"""
100-
setup_logging(cliverbosity=verbose)
101111

102112
if ctx.invoked_subcommand is None:
103113
# If no subcommand is invoked, show the help message
@@ -127,6 +137,10 @@ def cli(
127137
)
128138
context.appconfig = replace_placeholders(context.appconfig)
129139

140+
# Phase 2: Advanced logging setup with user configuration.
141+
logging_config = context.appconfig.get('logging', {})
142+
setup_logging(cliverbosity=verbose, user_config={'logging': logging_config})
143+
130144
(
131145
context.envconfigfiles,
132146
context.envconfig,
@@ -149,4 +163,4 @@ def cli(
149163
cli.add_command(config)
150164
cli.add_command(repo)
151165
cli.add_command(metadata)
152-
cli.add_command(validate)
166+
cli.add_command(validate)

src/docbuild/cli/cmd_repo/cmd_clone.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
import click
1515

1616
from ...cli.context import DocBuildContext
17-
from ...logging import GITLOGGERNAME
1817
from .process import process
18+
from ...constants import GITLOGGER_NAME
1919

20-
log = logging.getLogger(GITLOGGERNAME)
20+
log = logging.getLogger(__name__)
2121

22+
git_logger = logging.getLogger(GITLOGGER_NAME)
2223

2324
@click.command(help=__doc__)
2425
@click.argument(

src/docbuild/cli/cmd_repo/process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
from ...cli.context import DocBuildContext
88
from ...config.xml.stitch import create_stitchfile
9-
from ...logging import GITLOGGERNAME
109
from ...models.repo import Repo
1110
from ...utils.contextmgr import make_timer
11+
from ...constants import GITLOGGER_NAME
1212

13-
log = logging.getLogger(GITLOGGERNAME)
13+
log = logging.getLogger(GITLOGGER_NAME)
1414

1515

1616
async def clone_repo(repo: Repo, base_dir: Path) -> bool:
@@ -127,4 +127,4 @@ async def process(context: DocBuildContext, repos: tuple[str, ...]) -> int:
127127
# Return 0 for success (all clones succeeded), 1 for failure.
128128
if all(results):
129129
return 0
130-
return 1
130+
return 1

src/docbuild/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
used in production."""
140140

141141
# --- Logging constants ---
142+
GITLOGGER_NAME = "docbuild.git"
143+
"""The standardized name for the Git-related logger."""
144+
142145
BASE_LOG_DIR = Path.home() / '.local' / 'state' / APP_NAME / 'logs'
143146
"""The directory where log files will be stored, typically at
144147
:file:`~/.local/state/docbuild/logs` as recommended by the XDG Base

0 commit comments

Comments
 (0)