ElasticBeanstalk 中的 Flask 日志记录

发布于 2025-01-10 11:59:33 字数 335 浏览 1 评论 0原文

我正在尝试为部署在 ElasticBeanstalk 中的 Flask 应用程序设置日志记录。

我有一个基本的日志记录,可以在我的控制台中打印内容。

但在 Beanstalk 中部署时,我看不到任何应用程序日志。

为了实现这一目标,是否需要设置任何特定的配置?

只是分享一个示例代码。

用户.py

import logging 

class User(Resource): 

    def details(self):
      user_info = "Hello"
      logging.info(user_info)

I am trying to set up Logging for my Flask app which is deployed in ElasticBeanstalk.

I have a basic logging in place that prints stuff in my console.

But on deploying in Beanstalk, I am not able to see any of the application logs.

Is there any specific config that needs to be setup in order to achieve this?

Just sharing a sample code.

user.py

import logging 

class User(Resource): 

    def details(self):
      user_info = "Hello"
      logging.info(user_info)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2025-01-17 11:59:33

您可以将配置文件添加到 .ebextensions 文件夹,该文件夹将应用程序的日志添加到 EB 自动下载的日志中。

假设您的应用程序记录到 Flask 应用程序根目录中名为 logs 的文件夹,您将创建一个名为 .ebextensions/logging.config 的文件,如下所示

files:
  "/opt/elasticbeanstalk/tasks/taillogs.d/your_app_name_logs.conf" :
    mode: "000644"
    owner: root
    group: root
    content: |
      /var/app/current/logs/*.log

:(此处的官方文档略有不同: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.logging.html

然后,部署后,您应该能够使用 GUI 来下拉日志。

You can add a config file to your .ebextensions folder that adds your application's logs to the logs that EB downloads automatically.

Assuming that your application logs to a folder called logs in the Flask app root, you would make a file called .ebextensions/logging.config that looks like this:

files:
  "/opt/elasticbeanstalk/tasks/taillogs.d/your_app_name_logs.conf" :
    mode: "000644"
    owner: root
    group: root
    content: |
      /var/app/current/logs/*.log

(Which is a slight variation on the official documents here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.logging.html)

Then, after you deploy, you should be able to use the GUI to pull down logs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文