Skip to content

Commit 21178b8

Browse files
committed
Log more things
1 parent 8d7e43e commit 21178b8

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

bumpchanges/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
"Work with CHANGELOG.md files."
33

44
import argparse
5+
from logging import getLogger
56

67
from pathlib import Path
78

8-
from .changelog import Changelog
9+
from .changelog import Changelog, ChangelogError
10+
from .logging import setup_logging
911

1012

1113
def update_changelog(changelog_file: Path, repo_url: str, version: str):
1214
"Rewrite a CHANGELOG file for a new release."
13-
changelog = Changelog(changelog_file, repo_url)
15+
16+
try:
17+
changelog = Changelog(changelog_file, repo_url)
18+
except ChangelogError:
19+
getLogger(__name__).exception("Could not parse changelog")
20+
raise
21+
1422
changelog.update_version(version)
1523

1624
changelog_file.write_text(changelog.render(), encoding="utf-8")
@@ -24,6 +32,8 @@ def main():
2432
parser.add_argument("version", type=str)
2533

2634
args = parser.parse_args()
35+
setup_logging()
36+
2737
update_changelog(args.changelog, args.repo_url, args.version)
2838

2939

bumpchanges/changelog.py

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

33
import datetime
44
import itertools
5+
import logging
56
import re
67

78
from pathlib import Path
@@ -132,6 +133,8 @@ def from_tokens(cls, tokens):
132133
else:
133134
raise ChangelogError(f"Invalid section heading: {tokens[1].content}")
134135

136+
logging.getLogger(__name__).info("Parsed new version %s", kwargs.get("version"))
137+
135138
# The rest of the tokens should be the lists. Strip any rulers now.
136139
tokens = [token for token in tokens[3:] if token.type != "hr"]
137140

@@ -176,7 +179,6 @@ def from_tokens(cls, tokens):
176179
kwargs.setdefault("changed", []).extend(items)
177180

178181
else:
179-
print(tokens)
180182
raise ChangelogError("Don't know how to handle these tokens")
181183

182184
assert not tokens
@@ -251,6 +253,8 @@ def __init__(self, changelog_file: Path, repo_url: str):
251253
self.changelog_file = changelog_file
252254
self.repo_url = repo_url
253255

256+
logger = logging.getLogger(__name__)
257+
254258
groups = [[]]
255259

256260
all_tokens = MarkdownIt("gfm-like").parse(
@@ -275,6 +279,7 @@ def __init__(self, changelog_file: Path, repo_url: str):
275279
assert nexttoken is not None
276280
if re.match(r"^\[\d", nexttoken.content):
277281
token.tag = "h2"
282+
logger.notice("Changing `%s` from h1 to h2", nexttoken.content)
278283

279284
if token.tag == "h2":
280285
# A lot of our repositories have an issue where "Added",
@@ -285,6 +290,7 @@ def __init__(self, changelog_file: Path, repo_url: str):
285290
r"Add|Fix|Change|Remove", nexttoken.content, flags=re.IGNORECASE
286291
):
287292
token.tag = "h3"
293+
logger.notice("Changing `%s` from h2 to h3", nexttoken.content)
288294
else:
289295
# Split split these tokens off into a new Version
290296
groups.append([])
@@ -301,7 +307,9 @@ def __init__(self, changelog_file: Path, repo_url: str):
301307
def update_version(self, next_version: str):
302308
"Move all unreleased changes under the new version."
303309
if not self.versions or self.versions[0].version != "Unreleased":
304-
print("WARNING: No Unreleased section - adding a new empty section")
310+
logging.getLogger(__name__).warning(
311+
"No Unreleased section - adding a new empty section"
312+
)
305313
self.versions.insert(0, Version.blank_unreleased())
306314

307315
# Change the version and date of the unreleased section. For now

bumpchanges/logging.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ def filter(self, record):
2929
return True
3030

3131

32-
def setup_logging() -> logging.Logger:
33-
"Set up logging to GitHub Actions and return the configured logger."
32+
def setup_logging():
33+
"Set up logging to GitHub Actions.logger."
3434
# Does this need to be re-entrant like this?
35-
logger_name = "bumpchanges"
36-
3735
if logging.getLevelName("NOTICE") == NOTICE:
38-
return logging.getLogger(logger_name)
36+
return
3937

4038
logging.addLevelName(NOTICE, "NOTICE")
4139

@@ -49,7 +47,6 @@ def setup_logging() -> logging.Logger:
4947
defaults={"ghaprefix": ""}
5048
))
5149

52-
root_logger = logging.getLogger(logger_name)
50+
# Set these handlers on the root logger of this module
51+
root_logger = logging.getLogger(__name__.rpartition('.')[0])
5352
root_logger.addHandler(handler)
54-
55-
return root_logger

0 commit comments

Comments
 (0)