69 if failed_modules:
70 logging.warning(f"Failed to import {failed_modules} modules")
71 if failed_handlers:
72 logging.warning(f"Failed to add {failed_handlers} to handlers")73
74 if len(sys.argv) == 4:
75 restart_type = sys.argv[3]
67 f"Imported {success_handlers} handlers from {success_modules} modules."
68 )
69 if failed_modules:
70 logging.warning(f"Failed to import {failed_modules} modules")71 if failed_handlers:
72 logging.warning(f"Failed to add {failed_handlers} to handlers")
73
63 else:
64 success_modules += 1
65
66 logging.info(67 f"Imported {success_handlers} handlers from {success_modules} modules."
68 )
69 if failed_modules:
52 success_handlers += 1
53 except Exception as e:
54 failed_handlers += 1
55 logging.warning(56 f"Can't add {module_path}.{name}.{handler.__name__}: {e.__class__.__name__}: {e}"
57 )
58 except Exception as e:
28 )
29 die()
30 except (errors.NotAcceptable, errors.Unauthorized) as e:
31 logging.error(32 f"{e.__class__.__name__}: {e}\n"
33 f"Get help"
34 )
Formatting the message manually before passing it to a logging
call does unnecessary work if logging is disabled. Consider using the logging
module's built-in formatting features to avoid that.
If your logging level is set to "WARNING"
, but the logging call is:
logging.debug("Data: %s", data)
In the above example, there will be no logging as the level debug
is below warning
. The conversion of the data
object to a string will be skipped by the logging module resulting in improved performance.
logging.debug(f"Data: {data}")
In the code shown above, the conversion of the data
object to a string will happen regardless of whether the message is logged or not (which is based on the log level).
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug(f"Entered function {inspect.stack[0][3]}"))
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug("Entered function %s", inspect.stack[0][3])