2
2
from datetime import datetime
3
3
from logging import Handler , LogRecord
4
4
from pathlib import Path
5
- from typing import Optional
5
+ from typing import ClassVar , List , Optional , Type
6
6
7
7
from . import get_console
8
8
from rich ._log_render import LogRender
9
9
from rich .console import Console
10
- from rich .highlighter import Highlighter , ReprHighlighter
10
+ from rich .highlighter import Highlighter , RegexHighlighter , ReprHighlighter
11
11
from rich .markup import render
12
12
from rich .text import Text
13
13
@@ -20,11 +20,21 @@ class RichHandler(Handler):
20
20
level (int, optional): Log level. Defaults to logging.NOTSET.
21
21
console (:class:`~rich.console.Console`, optional): Optional console instance to write logs.
22
22
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.
23
24
24
25
"""
25
26
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
28
38
29
39
def __init__ (
30
40
self ,
@@ -50,9 +60,10 @@ def emit(self, record: LogRecord) -> None:
50
60
level = Text ()
51
61
level .append (record .levelname , log_style )
52
62
message_text = Text (message )
53
- message_text .highlight_words (self .KEYWORDS , "logging.keyword" )
54
63
if self .highlighter :
55
64
message_text = self .highlighter (message_text )
65
+ if self .KEYWORDS :
66
+ message_text .highlight_words (self .KEYWORDS , "logging.keyword" )
56
67
57
68
self .console .print (
58
69
self ._log_render (
0 commit comments