Skip to content

Commit

Permalink
extend logger file_paths to get all parent file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Jan 16, 2024
1 parent 02499c4 commit 9714133
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ python -m pip install musify
## Currently Supported
- **Music Streaming Services**: `Spotify`
- **Audio filetypes**: `.m4a` `.flac` `.wma` `.mp3`
- **Audio filetypes**: `.mp3` `.m4a` `.flac` `.wma`
- **Local playlist filetypes**: `.m3u` `.xautopf`
- **Local Libraries**: `MusicBee`
Expand Down
14 changes: 11 additions & 3 deletions musify/shared/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ class MusifyLogger(logging.Logger):
@property
def file_paths(self) -> list[str]:
"""Get a list of the paths of all file handlers for this logger"""
def extract_paths(lggr: logging.Logger) -> None:
"""Extract file path from the handlers of the given ``lggr``"""
for handler in lggr.handlers:
if isinstance(handler, logging.FileHandler) and handler.baseFilename not in paths:
paths.append(handler.baseFilename)

paths = []
for handler in self.handlers:
if isinstance(handler, logging.FileHandler):
paths.append(handler.baseFilename)
logger = self
extract_paths(logger)
while logger.propagate and logger.parent:
logger = logger.parent
extract_paths(logger)
return paths

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/__resources/test_logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ loggers:
test: &logger
level: DEBUG
handlers: [console_info, file]
propagate: no
propagate: yes

dev:
<<: *logger
Expand Down

0 comments on commit 9714133

Please sign in to comment.