简体   繁体   English

Google Stackdriver使用Redis队列登录App Engine(Python)

[英]Google Stackdriver logging in App Engine (Python) using Redis queue

I want to log using Stackdriver Logging to App Engine using Redis queue. 我想使用Stackdriver进行日志记录,使用Redis队列登录到App Engine。 So I'm using Redis Server, Redis Queue and Python logging to do this. 所以我正在使用Redis Server,Redis Queue和Python日志记录来做到这一点。 Here's my code: 这是我的代码:

import logging
from redis import Redis
from rq import Queue
import time

class SomeClass():

def log_using_redis(self,text):
    log_text = logging.warn(text)
    f=open("stack_log.txt","a+")
    f.write(str(text))
    return "logged Successfully using redis"


def get(self):
    text = 'Hello, Logged Successfully!'+time.strftime('%a, %d %b %Y %H:%M:%S %Z(%z)')
    redis_conn = Redis()
    q = Queue(connection=redis_conn)
    job = q.enqueue(self.log_using_redis,text)
    print job.result

When I run RQ worker I'm getting some output on terminal but couldn't find where the logs are being stored. 当我运行RQ worker时,我在终端上得到了一些输出,但是找不到日志的存储位置。

If I try to log directly without using Redis, the logs are being stored at Global in the logging section of Google Cloud. 如果我尝试不使用Redis进行直接日志记录,则日志将存储在Google Cloud日志记录部分的Global中。 The queue is working properly, to check I've been appending the text to a file. 队列工作正常,以检查是否已将文本附加到文件中。

It seems the logging isn't working. 似乎日志记录无法正常工作。 If it is being logged, where can I find my logs on Google Cloud? 如果正在记录日志,我在哪里可以在Google Cloud上找到日志?

Taking into account that you are using Python client library, use print() function to obtain the desired results. 考虑到您正在使用Python客户端库,请使用print()函数以获得所需的结果。 I don't know if you are testing the application locally or you have deployed it. 我不知道您是在本地测试应用程序还是已部署它。

  1. If you are testing the application locally: print() function output can be found in the cloud shell. 如果要在本地测试该应用程序,则可以在cloud shell中找到print()函数的输出。
  2. If you have deployed the application: go to the GCP console, App Engine and services. 如果您已部署该应用程序:请转到GCP控制台,App Engine和服务。 Select the service in which you have deployed your application. 选择已在其中部署应用程序的服务。 In the right side click on tools and select "Logs". 在右侧单击工具,然后选择“日志”。 This will redirect the page to your app logs. 这会将页面重定向到您的应用日志。

A more precise logging can be defined using the Stackdriver Logging for Python . 可以使用Stackdriver Logging for Python定义更精确的日志记录 The warning level can be defined. 可以定义警告级别。 This can help you manage your application or identify events of interest. 这可以帮助您管理应用程序或确定感兴趣的事件。 Find an example code here . 在此处找到示例代码。

You might find useful Stackdriver Logging agent , an application based on fluentd that runs on your virtual machine (VM) instances. 您可能会发现有用的Stackdriver Logging代理 ,这是一个基于fluentd的应用程序,可在您的虚拟机(VM)实例上运行。 The Logging agent is pre-configured to send logs from VM instances to Stackdriver Logging. 日志代理已预先配置为将日志从VM实例发送到Stackdriver Logging。 There are source and configuraiton files available for redis . 有可用于redis的源文件和配置文件。

If you want a more general vision, App Engine flexible environment logs official documentation can help you to understand the different available logs. 如果您需要更一般的眼光, App Engine灵活的环境日志官方文档可以帮助您了解其他可用日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在App Engine Standard python中使用Google Stackdriver日志时出错 - Error using Google Stackdriver Logging in App Engine Standard python python日志记录不适用于使用Google App Engine的Web应用程序 - python logging does not work for web app using google app engine 使用Python API的Google App Engine任务队列错误 - Google App Engine Task Queue Error using Python API Python Google Stackdriver 上的结构化日志记录为 jsonPayload - Python Structured Logging on Google Stackdriver as jsonPayload Google App Engine / Python - 更改日志记录格式 - Google App Engine/Python - Change logging formatting Google App Engine任务队列后端Python - Google App Engine Task Queue Backend Python 如何从 StackDriver Logging API 反序列化 App Engine 应用程序日志? - How to deserialize App Engine application logs from StackDriver Logging API? Google App Engine错误未显示在使用Flask的StackDriver错误报告中 - Google App Engine Errors not showing up in StackDriver Error Reporting using Flask 使用Google-Cloud-Python库将Stackdriver日志导出到BigQuery时出现访问问题 - Access issue with exporting Stackdriver logging to BigQuery using google-cloud-python library 如何在Google App Engine中动态更改python应用程序的日志记录级别? - How to dynamically change logging level of python app in Google App Engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM