作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Cloud Run 中使用 Django
、uwsgi
和 nginx
。
Cloud Run 服务无法显示 Django 日志记录和错误日志。这就是 Error Report
也不能使用的原因。
Cloud Run日志是这样的。它看不到堆栈跟踪...我不知道服务器发生了什么错误。
这是我的设置。
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'local': {
'format': "[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s"
},
'verbose': {
'format': '{message}',
'style': '{',
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'local',
},
},
'root': {
'handlers': ['console'],
'level': 'WARNING',
},
'loggers': {
'users': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
'django.db.backends': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
}
}
[uwsgi]
# this config will be loaded if nothing specific is specified
# load base config from below
ini = :base
# %d is the dir this configuration file is in
socket = %dapp.sock
master = true
processes = 4
[dev]
ini = :base
# socket (uwsgi) is not the same as http, nor http-socket
socket = :8001
[local]
ini = :base
http = :8000
# set the virtual env to use
home=/Users/you/envs/env
[base]
# chdir to the folder of this config file, plus app/website
chdir = %dapp/
# load the module from wsgi.py, it is a python path from
# the directory above.
module=website.wsgi:application
# allow anyone to connect to the socket. This is very permissive
chmod-socket=666
# nginx-app.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:/docker/app.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on, default_server indicates that this server block
# is the block to use if no blocks match the server_name
listen 8080 default_server;
# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
charset utf-8;
# extend timeout settings
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
# no cache
# sendfile off;
# etag off;
# if_modified_since off;
# max upload size
client_max_body_size 200M; # adjust to taste
# Django media
location /media {
alias /docker/app/website/media; # your Django project's media files - amend as required
}
location /static {
alias /docker/app/website/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
[program:app-uwsgi]
command = /usr/local/bin/uwsgi --ini /docker/uwsgi.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx-app]
command = /usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
# Graceful stop, see http://nginx.org/en/docs/control.html
stopsignal=QUIT
Cloud Run 获取 /var
和 /dev
目录日志,对吗? document
为什么此设置无法获取 django 日志记录结果和错误日志,例如 500 错误。
我是这样写loggin的。
logger = logging.getLogger(__name__)
logge.info('hello world')
但是这个日志在Cloud Run的日志中是看不到的。
请帮帮我!
最佳答案
我发现了我的错误。我没有更改 nginx.conf 中的 server_name
我更改了文件表单的这一行
server_name .example.com;
到
server_name MY_DOMAIN;
然后更新 Cloud Run。我现在可以看到错误日志了!
错误报告也能正常工作!
这是没有连接nginx的意思吗?
关于django - 如何在 Cloud Run 的日志中显示 django 日志记录和错误日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69140612/
我是一名优秀的程序员,十分优秀!