Skip to content

Commit 8542708

Browse files
committed
adding in style selection to the logging formatter
1 parent 97af76c commit 8542708

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

tmuxp/log.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@
3131
}
3232

3333

34-
def default_log_template(self, record):
34+
def set_style(
35+
message, stylized, style_before=None, style_after=None, prefix='', suffix=''
36+
):
37+
if stylized:
38+
return prefix + style_before + message + style_after + suffix
39+
40+
return prefix + message + suffix
41+
42+
43+
def default_log_template(self, record, stylized=False):
3544
"""
3645
Return the prefix for the log message. Template for Formatter.
3746
@@ -48,37 +57,34 @@ def default_log_template(self, record):
4857
"""
4958

5059
reset = Style.RESET_ALL
51-
levelname = (
52-
LEVEL_COLORS.get(record.levelname)
53-
+ Style.BRIGHT
54-
+ '(%(levelname)s)'
55-
+ Style.RESET_ALL
56-
+ ' '
60+
levelname = set_style(
61+
'(%(levelname)s)',
62+
stylized,
63+
style_before=(LEVEL_COLORS.get(record.levelname) + Style.BRIGHT),
64+
style_after=Style.RESET_ALL,
65+
suffix=' ',
5766
)
58-
asctime = (
59-
'['
60-
+ Fore.BLACK
61-
+ Style.DIM
62-
+ Style.BRIGHT
63-
+ '%(asctime)s'
64-
+ Fore.RESET
65-
+ Style.RESET_ALL
66-
+ ']'
67+
asctime = set_style(
68+
'%(asctime)s',
69+
stylized,
70+
style_before=(Fore.BLACK + Style.DIM + Style.BRIGHT),
71+
style_after=(Fore.RESET + Style.RESET_ALL),
72+
prefix='[',
73+
suffix=']',
6774
)
68-
name = (
69-
' '
70-
+ Fore.WHITE
71-
+ Style.DIM
72-
+ Style.BRIGHT
73-
+ '%(name)s'
74-
+ Fore.RESET
75-
+ Style.RESET_ALL
76-
+ ' '
75+
name = set_style(
76+
'%(name)s',
77+
stylized,
78+
style_before=(Fore.WHITE + Style.DIM + Style.BRIGHT),
79+
style_after=(Fore.RESET + Style.RESET_ALL),
80+
prefix=' ',
81+
suffix=' ',
7782
)
7883

79-
tpl = reset + levelname + asctime + name + reset
84+
if stylized:
85+
return reset + levelname + asctime + name + reset
8086

81-
return tpl
87+
return levelname + asctime + name
8288

8389

8490
class LogFormatter(logging.Formatter):

0 commit comments

Comments
 (0)