[英]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. 我不知道您是在本地测试应用程序还是已部署它。
print()
function output can be found in the cloud shell. print()
函数的输出。 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.