如何在 google 云控制台中为云功能设置日志文件?

How to setup logging file for cloud function in google cloud console?

我已将 python3.7 函数部署到 google 云。以下语句设置函数的日志记录。如果我从命令行执行函数,recommender_logs.log 文件将存储在当前工作目录中。

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='recommender_logs.log',
                    filemode='w')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
# set a format which is simpler for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)

我需要知道,当我从 google 云控制台 执行函数时,我需要在其中设置此文件,以便函数记录文件将存储在其中。 如果我不设置任何路径,文件将默认存储在哪里?

我可以在 Logging 控制台中看到日志,但除此之外还有什么地方可以看到这个文件,还是只能选择云存储桶?有谁能帮忙吗

部署在 GCP 中的每个功能都在一个单独的容器中运行,如果它需要存储任何数据,那么 it can only do so in the /tmp directory if the container it's running it

从计算、云 Shell 或使用 API 部署都没有关系。 Your functions file system is isolated from any other function 甚至它自己的另一个实例。

您以某种持久的方式存储文件,例如必须将其导出到 GCP 存储桶。 Have a look at this Stack answer - 它可能对你有用。