Skip to content

Commit eec4eaa

Browse files
author
Benito Palacios Sanchez
committed
Show warnings and errors in summary depending verbosity
1 parent 5e5a722 commit eec4eaa

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

src/logger.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,35 @@
3939

4040
def log(msg, level, state, color=None):
4141
"""Log the given message."""
42-
if state['verbosity'] >= level:
43-
# Add the clock if so
44-
if not state['no_timestamp']:
45-
if 'clocks' in state:
46-
clock = " %s " % state['clocks'][1].isoformat()
47-
else:
48-
clock = "".ljust(28)
49-
msg = clock + "|" + msg
42+
if state['verbosity'] < level:
43+
return
5044

51-
# Add the current line if so
52-
if state['show_lines']:
53-
msg = " %05d/%04d |%s" % (
54-
state['log_line'], state['current_line'], msg)
45+
# Add the clock if so
46+
if not state['no_timestamp']:
47+
if 'clocks' in state:
48+
clock = " %s " % state['clocks'][1].isoformat()
49+
else:
50+
clock = "".ljust(28)
51+
msg = clock + "|" + msg
5552

56-
if 'onlyIf' in state and not state['onlyIf'].search(msg):
57-
return
53+
# Add the current line if so
54+
if state['show_lines']:
55+
msg = " %05d/%04d |%s" % (
56+
state['log_line'], state['current_line'], msg)
5857

59-
# Highlight the message if so
60-
if 'highlight' in state and state['highlight'].search(msg):
61-
color = (color or "") + COLORS['BOLD']
58+
if 'onlyIf' in state and not state['onlyIf'].search(msg):
59+
return
6260

63-
# Apply color if specified
64-
if color and not state['no_colors']:
65-
msg = color + msg + COLORS['ENDC']
61+
# Highlight the message if so
62+
if 'highlight' in state and state['highlight'].search(msg):
63+
color = (color or "") + COLORS['BOLD']
6664

67-
# Write the message
68-
print(msg)
65+
# Apply color if specified
66+
if color and not state['no_colors']:
67+
msg = color + msg + COLORS['ENDC']
68+
69+
# Write the message
70+
print(msg)
6971

7072

7173
def log_recv(addr, entity, text, state, level=0):
@@ -105,6 +107,9 @@ def log_event(text, state, level=0):
105107

106108
def log_warning(text, state, level=0):
107109
"""Log a warning message."""
110+
if state['verbosity'] < level:
111+
return
112+
108113
state['warnings'].add(text)
109114
if state['inline']:
110115
text = "%s|%s|%s| *Warning: %s*" % (
@@ -114,6 +119,9 @@ def log_warning(text, state, level=0):
114119

115120
def log_error(text, state, level=0):
116121
"""Log an error."""
122+
if state['verbosity'] < level:
123+
return
124+
117125
state['errors'].add(text)
118126
if state['inline']:
119127
text = "%s|%s|%s| **Error: %s**" % (

0 commit comments

Comments
 (0)