Skip to content

Commit

Permalink
adding except OSError, ValueError to logging_conf
Browse files Browse the repository at this point in the history
  • Loading branch information
ali96343 committed Sep 23, 2023
1 parent 670e59f commit a5b5b1f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -82,19 +82,27 @@ 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

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}' )
Expand Down

0 comments on commit a5b5b1f

Please sign in to comment.