Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1e714c

Browse filesBrowse files
Helen Koiketheacodes
Helen Koike
authored andcommitted
Print to stderr instead of stdout when exiting the program (#5569)
The function print sends the output to stdout disturbing the output of the application. Redirect its output to stderr instead with sys.stderr
1 parent f67a57e commit e1e714c
Copy full SHA for e1e714c

File tree

Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed

‎logging/google/cloud/logging/handlers/transports/background_thread.py

Copy file name to clipboardExpand all lines: logging/google/cloud/logging/handlers/transports/background_thread.py
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import atexit
2323
import logging
24+
import sys
2425
import threading
2526
import time
2627

@@ -195,7 +196,9 @@ def stop(self, grace_period=None):
195196
self._queue.put_nowait(_WORKER_TERMINATOR)
196197

197198
if grace_period is not None:
198-
print('Waiting up to %d seconds.' % (grace_period,))
199+
print(
200+
'Waiting up to %d seconds.' % (grace_period,),
201+
file=sys.stderr)
199202

200203
self._thread.join(timeout=grace_period)
201204

@@ -216,12 +219,15 @@ def _main_thread_terminated(self):
216219
if not self._queue.empty():
217220
print(
218221
'Program shutting down, attempting to send %d queued log '
219-
'entries to Stackdriver Logging...' % (self._queue.qsize(),))
222+
'entries to Stackdriver Logging...' % (self._queue.qsize(),),
223+
file=sys.stderr)
220224

221225
if self.stop(self._grace_period):
222-
print('Sent all pending logs.')
226+
print('Sent all pending logs.', file=sys.stderr)
223227
else:
224-
print('Failed to send %d pending logs.' % (self._queue.qsize(),))
228+
print(
229+
'Failed to send %d pending logs.' % (self._queue.qsize(),),
230+
file=sys.stderr)
225231

226232
def enqueue(self, record, message, resource=None, labels=None):
227233
"""Queues a log entry to be written by the background thread.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.