Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions aw_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import click

from aw_cli.log import find_oldest_log, print_log, LOGLEVELS
from aw_cli.log import find_latest_log, print_log, LOGLEVELS
from typing import Optional


Expand Down Expand Up @@ -63,20 +63,20 @@ def logs(
testing = ctx.parent.params["testing"]
logdir: Path = Path(get_log_dir(None))

# find the oldest logfile in each of the subdirectories in the logging directory, and print the last lines in each one.
# find the latest logfile in each of the subdirectories in the logging directory, and print the lines in each one.

if module_name:
print_oldest_log(logdir / module_name, testing, since, level)
print_latest_log(logdir / module_name, testing, since, level)
else:
for subdir in sorted(logdir.iterdir()):
if subdir.is_dir():
print_oldest_log(subdir, testing, since, level)
print_latest_log(subdir, testing, since, level)


def print_oldest_log(path, testing, since, level):
path = find_oldest_log(path, testing)
if path:
print_log(path, since, level)
def print_latest_log(path, testing, since, level):
logfile = find_latest_log(path, testing)
if logfile:
print_log(logfile, since, level)
else:
print(f"No logfile found in {path}")

Expand Down
2 changes: 1 addition & 1 deletion aw_cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def print_log(
print(f" (Filtered {lines_printed}/{len(lines)} lines)")


def find_oldest_log(path: Path, testing=False) -> Path:
def find_latest_log(path: Path, testing=False) -> Path:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The return type annotation says Path but the function can return None via two implicit returns (when path is not a directory or when logfiles is empty). Since the PR is already touching the function signature, this is a good moment to fix the annotation to Optional[Path].

Suggested change
def find_latest_log(path: Path, testing=False) -> Path:
def find_latest_log(path: Path, testing=False) -> Optional[Path]:

if not path.is_dir():
return

Expand Down
Loading