Python logger模块 - 浅雨凉 - 博客园
import
logging
logger
=
logging.getLogger(__name__)
logger.setLevel(level
=
logging.INFO)
handler
=
logging.FileHandler(
"log.txt"
)
handler.setLevel(logging.INFO)
formatter
=
logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.info(
"Start print log"
)
logger.debug(
"Do something"
)
logger.warning(
"Something maybe fail."
)
logger.info(
"Finish"
)