简体   繁体   English

如何更改Google App Engine Python生产服务器中的日志记录级别?

[英]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.

相关问题 如何在Google App Engine中动态更改python应用程序的日志记录级别? - How to dynamically change logging level of python app in Google App Engine? Google App Engine / Python - 更改日志记录格式 - Google App Engine/Python - Change logging formatting 在Google App引擎上,如何更改dev_appserver.py的默认日志记录级别? - On the google app engine, how do I change the default logging level of the dev_appserver.py? 如何在开发服务器(Google App Engine)中使用生产BlobStore - How to use production BlobStore in development server (Google App Engine) 如何有效使用Google App Engine python应用程序中的日志记录? - How to efficiently use logging in Google App Engine python application? python日志记录不适用于使用Google App Engine的Web应用程序 - python logging does not work for web app using google app engine Google App Engine服务器到服务器OAuth Python - Google App Engine Server to Server OAuth Python 如何在 Google App Engine Python 服务器上启用 CORS? - How to enable CORS on Google App Engine Python Server? 如何将 Python 3 与 Google App Engine 的本地开发服务器一起使用 - How to use Python 3 with Google App Engine's Local Development Server 在Google App Engine Python中看不到应用程序级别的消息 - App level messages not visible in Google App engine Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM