Skip to content

Commit

Permalink
use default path when --log path invalidated (#820)
Browse files Browse the repository at this point in the history
* add log path check and use default path when --log path invalide

* add file type check
  • Loading branch information
noO0oOo0ob authored Jan 15, 2024
1 parent 29979fd commit 5ea7b92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lyrebird/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def make_stream_handler():

def make_file_handler(_log_path=None):
# Set default value
if not _log_path:
if not check_path(_log_path):
_log_path = DEFAULT_LOG_PATH

# Add pid and thread name in log file
Expand All @@ -67,6 +67,16 @@ def make_file_handler(_log_path=None):
return file_handler


def check_path(path):
if not path:
return False
if not os.path.exists(os.path.dirname(path)):
return False
if os.path.isdir(path) or path.split('.')[-1] != 'log':
return False
return True


def init(config, log_queue = None):
global LOGGER_INITED
if LOGGER_INITED:
Expand Down Expand Up @@ -141,6 +151,9 @@ def run(self, msg_queue, config, log_queue, *args, **kwargs):
_logger = logging.getLogger(_logger_name)
_logger.addHandler(file_handler)
_logger.setLevel(logger_level)

if log_path and not check_path(log_path):
lyrebird_logger.warning(f'Illegal log path: {log_path}, log file path have changed to the default path: {DEFAULT_LOG_PATH}')

while True:
try:
Expand Down
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (2, 23, 4)
IVERSION = (2, 23, 5)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION

0 comments on commit 5ea7b92

Please sign in to comment.