Skip to content

Commit

Permalink
fix bug:correct handle when meets PermissionError
Browse files Browse the repository at this point in the history
  • Loading branch information
felix5572 committed May 27, 2024
1 parent 661882a commit 6c1ee2f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dpdispatcher/dlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
dlog.propagate = False
dlog.setLevel(logging.INFO)
try:
cwd_logfile_path = os.path.join(os.getcwd(), "dpdispatcher.log")
dlogf = logging.FileHandler(
os.getcwd() + os.sep + "dpdispatcher" + ".log", delay=True
cwd_logfile_path, delay=True
)
dlog.addHandler(dlogf)
dlog.info(f"LOG INIT:dpdispatcher log direct to {cwd_logfile_path}")
except PermissionError:
dlog.removeHandler(dlogf)

Check failure on line 17 in dpdispatcher/dlog.py

View workflow job for this annotation

GitHub Actions / pyright

"dlogf" is possibly unbound (reportUnboundVariable)
warnings.warn(
"dpdispatcher.log meet permission error. redirect the log to ~/dpdispatcher.log"
f"dump logfile dpdispatcher.log to {cwd_logfile_path} meet permission error. redirect the log to ~/dpdispatcher.log"

Check failure on line 19 in dpdispatcher/dlog.py

View workflow job for this annotation

GitHub Actions / pyright

"cwd_logfile_path" is possibly unbound (reportUnboundVariable)
)
dlogf = logging.FileHandler(
os.path.join(os.path.expanduser("~"), "dpdispatcher.log"), delay=True
)
dlog.addHandler(dlogf)
dlog.info("LOG INIT:dpdispatcher log init at ~/dpdispatcher.log")

dlogf_formatter = logging.Formatter("%(asctime)s - %(levelname)s : %(message)s")
dlogf.setFormatter(dlogf_formatter)
dlog.addHandler(dlogf)
# dlog.addHandler(dlogf)

dlog_stdout = logging.StreamHandler(sys.stdout)
dlog_stdout.setFormatter(dlogf_formatter)
Expand Down

0 comments on commit 6c1ee2f

Please sign in to comment.