-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogger.py
More file actions
94 lines (81 loc) · 2.66 KB
/
logger.py
File metadata and controls
94 lines (81 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from rich.console import Console
from rich.text import Text
import typer
class Logger:
__slots__ = ("console", "err_console", "quiet", "verbose")
def __init__(self, *, verbose: bool = False, quiet: bool = False) -> None:
self.verbose = verbose
self.quiet = quiet
self.console = Console()
self.err_console = Console(stderr=True)
def configure(self, verbose: bool = False, quiet: bool = False) -> None:
self.verbose = verbose
self.quiet = quiet
def debug(
self,
*msg: str | Text,
style: str | None = typer.colors.BRIGHT_BLACK,
highlight: bool = False,
markup: bool = False,
console: Console | None = None,
) -> None:
"""Print a debug message.
Will only be shown if verbose mode is enabled and not in quiet mode.
"""
if self.verbose and not self.quiet:
(console or self.console).print(
*msg, style=style, highlight=highlight, markup=markup
)
def info(
self,
*msg: str | Text,
style: str | None = None,
highlight: bool = False,
markup: bool = False,
no_wrap: bool | None = None,
console: Console | None = None,
) -> None:
"""Print an informational message.
Will be suppressed in quiet mode.
"""
if not self.quiet:
(console or self.console).print(
*msg, style=style, highlight=highlight, markup=markup, no_wrap=no_wrap
)
def result(
self,
*msg: str | Text,
style: str | None = None,
highlight: bool = False,
markup: bool = False,
console: Console | None = None,
) -> None:
"""Print a result message, like info but ignores quiet mode."""
(console or self.console).print(
*msg, style=style, highlight=highlight, markup=markup
)
def warning(
self,
*msg: str | Text,
style: str | None = typer.colors.YELLOW,
highlight: bool = False,
markup: bool = False,
console: Console | None = None,
) -> None:
"""Print a warning message."""
(console or self.console).print(
*msg, style=style, highlight=highlight, markup=markup
)
def error(
self,
*msg: str | Text,
style: str | None = typer.colors.RED,
highlight: bool = False,
markup: bool = False,
console: Console | None = None,
) -> None:
"""Print an error message."""
(console or self.err_console).print(
*msg, style=style, highlight=highlight, markup=markup
)
logger = Logger()