Skip to content

Commit c433b35

Browse files
Improve logging (#143)
* Improve logging Trying to strike the right balance between verbose and non-verbose mode in the CLI. Particularly for the upload command it's been not satisfactory. The list of files being uploaded as coverage is now listed in non-verbose mode. Plus there's a positive feedback now that the process (command) finished - for ALL commands. So you know that at least the CLI did its thing, even though there might still be errors. And again for the upload command, separate better the response from codecov-api and the response from the PUT request afterwards. To help debugging and all that. * Make positive feedback less intrusive It was a lot of data in the "process complete" message. We don't need all that just to let users know the process terminated. So breaking that up again into 2 messages, the 2nd having all the data in verbose level.
1 parent 509312f commit c433b35

7 files changed

Lines changed: 39 additions & 8 deletions

File tree

codecov_cli/helpers/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ def request_result(resp):
5959
def log_warnings_and_errors_if_any(
6060
sending_result: RequestResult, process_desc: str, fail_on_error: bool = False
6161
):
62+
logger.info(
63+
f"Process {process_desc} complete",
64+
)
6265
logger.debug(
63-
f"Process {process_desc} complete.",
66+
f"{process_desc} result",
6467
extra=dict(extra_log_attributes=dict(result=sending_result)),
6568
)
6669
if sending_result.warnings:

codecov_cli/services/upload/upload_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def generate_upload_data(self) -> UploadCollectionResult:
131131
logger.debug("Collecting relevant files")
132132
network = self.network_finder.find_files()
133133
coverage_files = self.coverage_file_finder.find_coverage_files()
134-
logger.debug(f"Found {len(coverage_files)} coverage files to upload")
134+
logger.info(f"Found {len(coverage_files)} coverage files to upload")
135135
for file in coverage_files:
136-
logger.debug(f"> {file}")
136+
logger.info(f"> {file}")
137137
return UploadCollectionResult(
138138
network=network,
139139
coverage_files=coverage_files,

codecov_cli/services/upload/upload_sender.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import json
3+
import logging
34
import typing
45
import uuid
56
import zlib
@@ -17,6 +18,8 @@
1718
UploadCollectionResultFile,
1819
)
1920

21+
logger = logging.getLogger("codecovcli")
22+
2023

2124
class UploadSender(object):
2225
def send_upload_data(
@@ -53,11 +56,17 @@ def send_upload_data(
5356
# Data that goes to storage
5457
reports_payload = self._generate_payload(upload_data, env_vars)
5558

59+
logger.debug("Sending upload request to Codecov")
5660
resp_from_codecov = send_post_request(url=url, data=data, headers=headers)
5761
if resp_from_codecov.status_code >= 400:
5862
return resp_from_codecov
5963
resp_json_obj = json.loads(resp_from_codecov.text)
64+
logger.debug(
65+
"Upload request to Codecov complete.",
66+
extra=dict(extra_log_attributes=dict(response=resp_json_obj)),
67+
)
6068
put_url = resp_json_obj["raw_upload_location"]
69+
logger.debug("Sending upload to storage")
6170
resp_from_storage = send_put_request(put_url, data=reports_payload)
6271
return resp_from_storage
6372

tests/services/commit/test_commit_service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def test_commit_command_with_warnings(mocker):
3131

3232
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
3333
assert out_bytes == [
34+
("info", "Process Commit creating complete"),
3435
("info", "Commit creating process had 1 warning"),
3536
("warning", "Warning 1: somewarningmessage"),
3637
]
@@ -73,7 +74,13 @@ def test_commit_command_with_error(mocker):
7374
)
7475

7576
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
76-
assert out_bytes == [("error", "Commit creating failed: Permission denied")]
77+
assert out_bytes == [
78+
(
79+
"info",
80+
"Process Commit creating complete",
81+
),
82+
("error", "Commit creating failed: Permission denied"),
83+
]
7784
assert res == mock_send_commit_data.return_value
7885
mock_send_commit_data.assert_called_with(
7986
commit_sha="commit_sha",

tests/services/report/test_report_results.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_report_results_command_with_warnings(mocker):
3434

3535
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
3636
assert out_bytes == [
37+
("info", "Process Report results creating complete"),
3738
("info", "Report results creating process had 1 warning"),
3839
("warning", "Warning 1: somewarningmessage"),
3940
]
@@ -73,7 +74,10 @@ def test_report_results_command_with_error(mocker):
7374
)
7475

7576
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
76-
assert out_bytes == [("error", "Report results creating failed: Permission denied")]
77+
assert out_bytes == [
78+
("info", "Process Report results creating complete"),
79+
("error", "Report results creating failed: Permission denied"),
80+
]
7781
assert res == mock_send_reports_result_request.return_value
7882
mock_send_reports_result_request.assert_called_with(
7983
commit_sha="commit_sha",

tests/services/report/test_report_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_create_report_command_with_warnings(mocker):
5858

5959
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
6060
assert out_bytes == [
61+
("info", "Process Report creating complete"),
6162
("info", "Report creating process had 1 warning"),
6263
("warning", "Warning 1: somewarningmessage"),
6364
]
@@ -101,7 +102,10 @@ def test_create_report_command_with_error(mocker):
101102
)
102103

103104
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
104-
assert out_bytes == [("error", "Report creating failed: Permission denied")]
105+
assert out_bytes == [
106+
("info", "Process Report creating complete"),
107+
("error", "Report creating failed: Permission denied"),
108+
]
105109
assert res == RequestResult(
106110
error=RequestError(
107111
code="HTTP Error 403",

tests/services/upload/test_upload_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):
6969
)
7070
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
7171
assert out_bytes == [
72+
("info", "Process Upload complete"),
7273
("info", "Upload process had 1 warning"),
7374
("warning", "Warning 1: somewarningmessage"),
7475
]
@@ -151,6 +152,7 @@ def test_do_upload_logic_happy_path(mocker):
151152
)
152153
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
153154
assert out_bytes == [
155+
("info", "Process Upload complete"),
154156
("info", "Upload process had 1 warning"),
155157
("warning", "Warning 1: somewarningmessage"),
156158
]
@@ -237,7 +239,8 @@ def test_do_upload_logic_dry_run(mocker):
237239
cli_config, ["first_plugin", "another", "forth"]
238240
)
239241
assert out_bytes == [
240-
("info", "dry-run option activated. NOT sending data to Codecov.")
242+
("info", "dry-run option activated. NOT sending data to Codecov."),
243+
("info", "Process Upload complete"),
241244
]
242245
assert res == RequestResult(
243246
error=None,
@@ -294,9 +297,10 @@ def test_do_upload_logic_verbose(mocker, use_verbose_option):
294297
"Selected uploader to use: <class 'codecov_cli.services.upload.legacy_upload_sender.LegacyUploadSender'>",
295298
),
296299
("info", "dry-run option activated. NOT sending data to Codecov."),
300+
("info", "Process Upload complete"),
297301
(
298302
"debug",
299-
'Process Upload complete. --- {"result": "RequestResult(error=None, warnings=None, status_code=200, text=\'Data NOT sent to Codecov because of dry-run option\')"}',
303+
'Upload result --- {"result": "RequestResult(error=None, warnings=None, status_code=200, text=\'Data NOT sent to Codecov because of dry-run option\')"}',
300304
),
301305
]
302306
assert res == RequestResult(

0 commit comments

Comments
 (0)