Skip to content

Commit 4b123dd

Browse files
committed
rich handler tweak
1 parent 3977549 commit 4b123dd

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.2.2] - Unreleased
8+
## [2.2.2] - 2020-06-14
99

1010
### Changed
1111

12-
- Extra paramters added to RichLogging
12+
- Exposed RichHandler highlighter as a class var
1313

1414
## [2.2.1] - 2020-06-14
1515

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "2.2.1"
5+
version = "2.2.2"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <willmcgugan@gmail.com>"]
88
license = "MIT"

rich/logging.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from datetime import datetime
33
from logging import Handler, LogRecord
44
from pathlib import Path
5-
from typing import Optional
5+
from typing import ClassVar, List, Optional, Type
66

77
from . import get_console
88
from rich._log_render import LogRender
99
from rich.console import Console
10-
from rich.highlighter import Highlighter, ReprHighlighter
10+
from rich.highlighter import Highlighter, RegexHighlighter, ReprHighlighter
1111
from rich.markup import render
1212
from rich.text import Text
1313

@@ -20,11 +20,21 @@ class RichHandler(Handler):
2020
level (int, optional): Log level. Defaults to logging.NOTSET.
2121
console (:class:`~rich.console.Console`, optional): Optional console instance to write logs.
2222
Default will create a new console writing to stderr.
23+
enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True.
2324
2425
"""
2526

26-
KEYWORDS = ["GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS", "TRACE", "PATCH"]
27-
HIGHLIGHTER_CLASS = ReprHighlighter
27+
KEYWORDS: ClassVar[Optional[List[str]]] = [
28+
"GET",
29+
"POST",
30+
"HEAD",
31+
"PUT",
32+
"DELETE",
33+
"OPTIONS",
34+
"TRACE",
35+
"PATCH",
36+
]
37+
HIGHLIGHTER_CLASS: ClassVar[Type[Highlighter]] = ReprHighlighter
2838

2939
def __init__(
3040
self,
@@ -50,9 +60,10 @@ def emit(self, record: LogRecord) -> None:
5060
level = Text()
5161
level.append(record.levelname, log_style)
5262
message_text = Text(message)
53-
message_text.highlight_words(self.KEYWORDS, "logging.keyword")
5463
if self.highlighter:
5564
message_text = self.highlighter(message_text)
65+
if self.KEYWORDS:
66+
message_text.highlight_words(self.KEYWORDS, "logging.keyword")
5667

5768
self.console.print(
5869
self._log_render(

0 commit comments

Comments
 (0)