Skip to main content
 首页 » 编程设计

python之谷歌应用引擎,NDB : Suppress tasklet warnings

2025年05月04日24over140

只是一个小烦恼,但似乎 AppEngine 的 NDB (Python) 正在为源自模型的错误生成警告,无论是否处理异常:

testCannotInsertWithoutCurrency (expense_test.ExpenseTest) ... {'amount': 9.9, 'description': 'Foo'} 
WARNING:root:initial generator _put_tasklet(context.py:335) raised BadValueError(Entity has uninitialized properties: currency) 
WARNING:root:suspended generator put(context.py:812) raised BadValueError(Entity has uninitialized properties: currency) 

正如您从输出中看到的那样,我只是在编写测​​试,所以我实际上期望错误会发生并且我对警告产生的所有噪音不感兴趣。有什么办法可以禁用它吗?在文档中找不到有关日志级别等的任何信息。

请您参考如下方法:

您可以使用记录器的 setLevel 方法显式设置日志级别。

例如

 logging.getLogger().setLevel(logging.INFO)