diff --git a/py4web/server_adapters.py b/py4web/server_adapters.py index 21f2b872c..a1707edcd 100644 --- a/py4web/server_adapters.py +++ b/py4web/server_adapters.py @@ -67,7 +67,7 @@ def logging_conf(level=logging.WARN, logger_name=__name__): log_to["filemode" ] = "w" log_to["encoding"] = "utf-8" - else: # sys.version_info < (3, 9) + else: h = logging.FileHandler( log_file, @@ -82,12 +82,19 @@ def logging_conf(level=logging.WARN, logger_name=__name__): time_msg = '%H:%M:%S' #date_time_msg = '%Y-%m-%d %H:%M:%S' - logging.basicConfig( - format=short_msg, - datefmt=time_msg, - level=check_level(level), - **log_to, - ) + try: + + logging.basicConfig( + format=short_msg, + datefmt=time_msg, + level=check_level(level), + **log_to, + ) + + except ( OSError, KeyError, ValueError ) as ex: + print(f"{ex}, {__file__}") + print(f'cannot open {log_file}') + logging.basicConfig( level=check_level(level),) if logger_name is None: return None @@ -95,6 +102,7 @@ def logging_conf(level=logging.WARN, logger_name=__name__): logger_name = "SA:" + logger_name log = logging.getLogger(logger_name) log.propagate = True + log.info( f'info start logger {logger_name}' ) log.warn( f'warn start logger {logger_name}' ) log.debug( f'debug start logger {logger_name}' )