Python logging done/fail messages -
when using python logging
library, standard approach write message this:
logging.info("all right")
but necessary show result status of (long) task (after while after output of main part of message). example:
some long computing... [done]
or
some long computing... [fail]
how can solve problem?
total:
ok. possible, in next line. output success message in same line must use other tool (probably, custom), not logging
python library.
it sounds might out.
import logging logging.basicconfig(format = "%(asctime)s - %(levelname)s - %(message)s", level = logging.debug) logging.info("long task starting") try: startlongtaskfunction() logging.info("long task finished") except: logging.exception("long task failed")
note logging.exception() different logging.error(). after log entry added logging.exception(), entire python error message included well.
if want log critical events in startlongtaskfunction, can insert log entries inside function well. if import function separate module, can still reference same log file.
Comments
Post a Comment