Skip to content

Commit 31e9435

Browse files
reludakkomar
andauthored
chore(python_server): replace print with sys.stdout.write (#820)
* chore(python_server): replace print with sys.stdout.write because print writes the ping and newline separately, which increases the chances of something else, like another ping, getting printed between them * Add changelog entry --------- Co-authored-by: Arkadiusz Komarzewski <[email protected]>
1 parent 31efbeb commit 31e9435

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Python server: Fix logging mechanism ([#820](https://github.com/mozilla/glean_parser/pull/820))
6+
57
## 18.1.0
68

79
- Python server: Support sending custom pings without events ([#817](https://github.com/mozilla/glean_parser/pull/817))

glean_parser/templates/python_server.jinja2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from datetime import datetime, timezone
1212
from typing import Any
1313
from uuid import uuid4
1414
import json
15+
import sys
1516

1617
GLEAN_EVENT_MOZLOG_TYPE = "glean-server-event"
1718

@@ -111,7 +112,7 @@ class {{ ping|camelize }}ServerEventLogger:
111112
}
112113
ping_envelope_serialized = json.dumps(ping_envelope)
113114

114-
print(ping_envelope_serialized)
115+
sys.stdout.write(f"{ping_envelope_serialized}\n")
115116

116117
{% for event in metrics_by_type["event"] %}
117118
def {{ event|record_event_function_name }}(
@@ -132,7 +133,7 @@ class {{ ping|camelize }}ServerEventLogger:
132133
"""
133134
Record and submit a {{ event.category }}_{{ event.name }} event:
134135
{{ event.description|clean_string }}
135-
Event is logged to STDOUT via `print`.
136+
Event is logged to STDOUT via `sys.stdout.write`.
136137

137138
:param str user_agent: The user agent.
138139
:param str ip_address: The IP address. Will be used to decode Geo information

0 commit comments

Comments
 (0)