我正在使用logging.info
输出有关我的脚本正在做什么的信息,我正在使用logging.basicConfig(level=logging.INFO)
启用此功能。这个(logging.basicConfig(level=logging.INFO)
)也影响我调用的其他模块(例如SQLAlchemy),导致比我想要的更详细的输出。我可以将我的实际脚本的日志记录级别设置为INFO,但不能将其使用的第三方模块设置为INFO(我更喜欢将它们作为警告)?
执行此操作的常规方法是在模块的开头为当前模块定义记录器(通常基于文件名),并在整个过程中参考。
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def function_that_logs():
logger.info('will log') # note, using logger not logging
logger.debug('will not log')