Skip to content

Commit eabff6e

Browse files
authored
Simplify emrun logging. NFC (#26868)
All three logging function had basically the same body so extract that into a function.
1 parent 47317b6 commit eabff6e

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

emrun.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,31 @@ def tick():
130130
http_mutex = threading.RLock()
131131

132132

133-
def logi(msg):
134-
"""Prints a log message to 'info' stdout channel. Always printed."""
133+
def print_message(msg, file):
135134
global last_message_time
136135
with http_mutex:
137-
sys.stdout.write(msg + '\n')
138-
sys.stdout.flush()
136+
file.write(msg + '\n')
137+
file.flush()
139138
last_message_time = tick()
140139

141140

141+
def logi(msg):
142+
"""Prints a log message to stdout. Always printed."""
143+
print_message(msg, sys.stdout)
144+
145+
142146
def logv(msg):
143-
"""Prints a verbose log message to stdout channel.
147+
"""Prints a verbose log message to stdout.
144148
145149
Only shown if run with --verbose.
146150
"""
147-
global last_message_time
148151
if emrun_options.verbose:
149-
with http_mutex:
150-
sys.stdout.write(msg + '\n')
151-
sys.stdout.flush()
152-
last_message_time = tick()
152+
print_message(msg, sys.stdout)
153153

154154

155155
def loge(msg):
156-
"""Prints an error message to stderr channel."""
157-
global last_message_time
158-
with http_mutex:
159-
sys.stderr.write(msg + '\n')
160-
sys.stderr.flush()
161-
last_message_time = tick()
156+
"""Prints an error message to stderr."""
157+
print_message(msg, sys.stderr)
162158

163159

164160
def format_eol(msg):

0 commit comments

Comments
 (0)