importloggingfromindexpyimportIndexapp=Index()logger=logging.getLogger("example")@app.on_startupdeflogger_on_startup():logger.info("Called on startup")@app.on_shutdowndeflogger_on_shutdown():logger.info("Called on shutdown")
也可以在创建 Index 对象时作为参数传递,以下程序与上等价。
1 2 3 4 5 6 7 8 910111213141516171819
importloggingfromindexpyimportIndexlogger=logging.getLogger("example")deflogger_on_startup():logger.info("Called on startup")deflogger_on_shutdown():logger.info("Called on shutdown")app=Index(on_startup=[logger_on_startup],on_shutdown=[logger_on_shutdown],)