[英]How to change logging level in google app engine python production server?
I have tried to search answers for this question online, but in vain. 我试图在线搜索此问题的答案,但徒劳。 I do see the answer for " How do set the log level in google app engine python dev server ", which is useful to know - but if I understand correctly, this doesn't automatically translate to the production environment, right? 我确实看到了“ 如何在google app引擎python dev服务器中设置日志级别 ”的答案,这很有用,但要知道-但是,如果我理解正确,它不会自动转换为生产环境,对吗?
Deploying my dev code with hundreds of logging.debug()
statements always makes them show up on the production server logs. 使用数百个logging.debug()
语句部署我的开发代码始终会使它们显示在生产服务器日志中。 Is there a simple switch I could flip on the production server to set the logging level and avoid clogging the logs with all debug messages? 我可以在生产服务器上设置一个简单的开关来设置日志记录级别,并避免所有调试消息阻塞日志吗? At least from looking at the Google App Engine's admin console, I haven't found there is a way to do this. 至少从查看Google App Engine的管理控制台来看,我还没有找到实现此目的的方法。 This is hard to believe because one would think that App Engine developers would have provisioned a super simple way to do this. 很难相信,因为有人会认为App Engine开发人员会提供一种超级简单的方法来执行此操作。
As Paul Collingwood said in his comment, it is easy to set a filter in the Developer Console, in order to reduce visual clutter. 正如Paul Collingwood在评论中所说,很容易在开发人员控制台中设置过滤器,以减少视觉混乱。
If there are cases in which you do not wish to have the debug logs recorded at all (eg while in production), you might like to write a little wrapper function for the logging calls, which checks whether the app is in dev or production, and based on that decides whether to write something to log. 如果在某些情况下您根本不想记录调试日志(例如,在生产环境中),则可能希望为日志记录调用编写一些包装函数,以检查应用程序是在开发环境中还是在生产环境中,并据此决定是否要写入日志。
I'm thinking something like: 我在想类似的东西:
import logging
class Logger()
def debug(*args, **kwargs):
if not running_in_production(): # needs to be implemented elsewhere.
logging.debug(*args, **kwargs)
def info(*args, **kwargs):
""" any rules here? """
logging.info(*args, **kwargs)
# other functions here.
Then, in your individual files, you could replace import logging
with import logger as logging
for a drop-in replacement which is adaptable to the environment where it is running - and to any other imaginable factors. 然后,在您的单个文件中,您可以将import logging
替换为import logging
import logger as logging
适用于其运行环境以及任何其他可想象因素的嵌入式替换的import logger as logging
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.