aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-05-05 08:47:26 +0200
committerMatěj Cepl <mcepl@cepl.eu>2024-05-05 08:52:01 +0200
commit91d4e6e2f57e84fdfbac56e6cf835f6eceaec6fc (patch)
tree983bae119bd2eae59d99bc42e8493260af710801
parent045068165f989a94935a48e42057a57c68ce403f (diff)
downloadlazygl2srht-91d4e6e2f57e84fdfbac56e6cf835f6eceaec6fc.tar.gz
fix: use proper logging instead of print()
Ordinary print() function in Python is buffered (there is flush option, but it alleviates just part of problems). Logging module knows about and deals with the problem. https://stackabuse.com/bytes/flush-the-output-of-the-print-function-in-python/ https://stackoverflow.com/q/230751/164233 https://stackoverflow.com/q/55619733/164233 (logging.INFO changed during the development of the code to logging.DEBUG as needed).
-rwxr-xr-ximport_issues.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/import_issues.py b/import_issues.py
index 4b1722e..666644e 100755
--- a/import_issues.py
+++ b/import_issues.py
@@ -123,6 +123,7 @@
import argparse
import csv
+import logging
import json
import os
import re
@@ -137,6 +138,9 @@ from typing import Dict, List, Optional
ID_RE = re.compile(r'^[0-9]+$')
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ level=logging.DEBUG)
+log = logging.getLogger()
email_count = 0
issue_count = 0
@@ -173,7 +177,7 @@ def do_mail(
):
global email_count
email_count += 1
- print(f"---- #{email_count}")
+ log.info(f"---- #{email_count}")
date = format_datetime(datetime.now(timezone.utc))
msg_id = make_msgid()
@@ -491,7 +495,7 @@ def run(
for issue_json in issue_jsons:
issue_json['notes'].sort(key=lambda x: x['created_at'])
- print("-------- CREATING TICKETS")
+ log.info("-------- CREATING TICKETS")
issue_id_map: Dict[int, int] = {}
@@ -560,7 +564,7 @@ def run(
issue_id_map[gitlab_issue_id] = srht_issue_id
- print("-------- CREATING COMMENTS")
+ log.info("-------- CREATING COMMENTS")
for issue_json in issue_jsons:
for note_json in issue_json['notes']:
@@ -607,7 +611,7 @@ def run(
is_confidential=(note_json['confidential'] is True),
)
- print("-------- CLOSING CLOSED ISSUES")
+ log.info("-------- CLOSING CLOSED ISSUES")
for issue_json in issue_jsons:
if issue_json['state'] == 'closed':
@@ -807,7 +811,7 @@ def main():
assert smtp_user, f"No SMTP user given."
assert smtp_password, f"No SMTP password given."
- print(f"Connecting to {smtp_host}:{smtp_port}, user {smtp_user!r}.")
+ log.info(f"Connecting to {smtp_host}:{smtp_port}, user {smtp_user!r}.")
if smtp_ssl:
smtp = smtplib.SMTP_SSL(host=smtp_host, port=smtp_port)