Skip to content

Commit

Permalink
Fix some typing for the JSON file handler
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 3, 2023
1 parent a9b3a37 commit 600b5e9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/sdsstools/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,16 @@ def _set_file_handler(
mode: str = "a",
when: str = "midnight",
utc: bool = True,
at_time: Union[str, datetime.time] = None,
at_time: datetime.time | None = None,
):
if rotating:
fh = TimedRotatingFileHandler(
str(filepath), when=when, utc=utc, atTime=at_time
str(filepath),
when=when,
utc=utc,
atTime=at_time,
)
fh.suffix = suffix # type: ignore
fh.suffix = suffix
else:
fh = logging.FileHandler(str(filepath), mode=mode)
return fh
Expand All @@ -369,7 +372,7 @@ def start_file_logger(
rollover: bool = False,
when: str = "midnight",
utc: bool = True,
at_time: Union[str, datetime.time] = None,
at_time: datetime.time | None = None,
as_json: bool = False,
with_json: bool = False,
):
Expand All @@ -396,7 +399,7 @@ def start_file_logger(
If `True`, times in UTC will be used; otherwise local time is used.
at_time
The time of day when rollover occurs, when rollover is set to occur
at midnight or on a particular weekday.
at "midnight" or "on a particular weekday".
as_json
If `True`, outputs a JSON log instead of a human log
with_json
Expand All @@ -409,6 +412,7 @@ def start_file_logger(
SUFFIX = "%Y-%m-%d_%H:%M:%S"

# set the JSON file path name
json_log_file_path: str | None = None
suffix = pathlib.Path(log_file_path).suffix
if as_json and suffix != ".json":
log_file_path = log_file_path.replace(suffix, ".json")
Expand Down Expand Up @@ -439,7 +443,7 @@ def start_file_logger(
at_time=at_time,
)

if with_json:
if with_json and json_log_file_path:
self.jh = self._set_file_handler(
json_log_file_path,
SUFFIX,
Expand Down

0 comments on commit 600b5e9

Please sign in to comment.