Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.73k stars 1.73k forks source link

[BUG] LoggingHandler doesn't write into the file but always inline in VSCode notebooks #3496

Open jordi-torrents opened 2 months ago

jordi-torrents commented 2 months ago

Rich's logging handler produces an inline logging line in VSCode notebooks when the logging should be redirected to a file, and this file never gets writen.

import logging
from rich.logging import RichHandler
from rich.console import Console
from pathlib import Path

logging.basicConfig(
    level=logging.DEBUG,
    handlers=[
        RichHandler(console=Console()),  # inline display
        RichHandler(  # writing log into test.log
            console=Console(file=Path("test.log").open("w", encoding="utf_8"))
        ),
    ],
)
logging.info("Hello world")

This code produces a duplicate logging and the file "test.log" remins empty. image

Everything works fine when running from terminal.

Platform

Click to expand ``` ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = None │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 18 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = False │ │ is_jupyter = False │ │ is_terminal = False │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=214, height=18), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=214, │ │ is_terminal=False, │ │ encoding='utf-8', │ │ max_height=18, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=214, height=18) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 214 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': 'xterm-color', │ │ 'COLORTERM': 'truecolor', │ │ 'CLICOLOR': '1', │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': 'vscode', │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ ```
github-actions[bot] commented 2 months ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory