作者:吴秋仪6_913 | 来源:互联网 | 2023-05-17 00:59
iamusingELKstackforcentralisedloggingfrommydjangoserver.MyELKstackisonaremoteserv
i am using ELK stack for centralised logging from my django server. My ELK stack is on a remote server and logstash.conf looks like this
我正在使用ELK堆栈从我的django服务器进行集中式日志记录。我的ELK堆栈位于远程服务器上,logstash.conf看起来像这样
input {
tcp {
port => 5959
codec => json
}
}
output {
elasticsearch {
hosts => ["xx.xx.xx.xx:9200"]
}
}
both services elasticsearch and logstash are working (checked using docker-compose logs logstash
).
两个服务elasticsearch和logstash都在工作(使用docker-compose logs logstash检查)。
my django server's settings file have logging conf like below
我的django服务器的设置文件有如下所示的日志记录
LOGGING = {
'version': 1,
'handlers': {
'logstash': {
'level': 'INFO',
'class': 'logstash.TCPLogstashHandler',
'host': 'xx.xx.xx.xx',
'port': 5959, # Default value: 5959
'version': 0, # Version of logstash event schema. Default value: 0 (for backward compatibility of the library)
'message_type': 'django', # 'type' field in logstash message. Default value: 'logstash'.
'fqdn': True, # Fully qualified domain name. Default value: false.
'tags': ['django.request'], # list of tags. Default: None.
},
},
'loggers': {
'django.request': {
'handlers': ['logstash'],
'level': 'DEBUG',
},
}
}
I run my django server and logstash handler handles the logs as console shows no logs.I used python-logstash library in django server to construct above conf but logs are not sent to my remote server
我运行我的django服务器和logstash处理程序处理日志,因为控制台显示没有logs.I使用django服务器中的python-logstash库来构造上面的conf但是日志不会发送到我的远程服务器
I checked through many question, verified that services are running are ports are correct but no clue why logs are not being sent to logstash
我检查了很多问题,验证服务正在运行端口是否正确,但没有线索为什么日志没有被发送到logstash
1 个解决方案
2
Looking at the configuration, logger "django.request" is set to level "DEBUG" and the handler "logstash" is set to level "INFO". My guess is that the handler will not process DEBUG messages. I'm not sure though.
查看配置,记录器“django.request”设置为“DEBUG”级别,处理程序“logstash”设置为级别“INFO”。我的猜测是处理程序不会处理DEBUG消息。我不确定。
Set the same level for the logger and the handler to test that it works.
为记录器和处理程序设置相同的级别以测试它是否有效。
What level to use depends on what you want from your logs. In this case I guess level INFO would suffice.
使用的级别取决于您对日志的要求。在这种情况下,我猜水平INFO就足够了。
If not already take a look at Django logging
如果还没有看看Django日志记录
NOTE: From comments it seems not to solve the problem but I hope it is useful anyway.
注意:从评论看来似乎没有解决问题,但我希望它无论如何都是有用的。
UPDATE:
更新:
I tried the following configuration and it catches 404 and 500 errors in the "debug.log".
我尝试了以下配置,它在“debug.log”中捕获了404和500错误。
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'logfile': {
'level': 'WARNING',
'class': 'logging.FileHandler',
'filename': os.path.join(PROJECT_DIR, 'debug.log'),
},
},
'loggers': {
'django.request': {
'handlers': ['logfile'],
'level': 'WARNING',
'propagate': True,
},
}}
With this test configuration the logstash handler should at least receive the message/logrecord. If no luck I suggest to try debug the logstash.TCPLogstashHandler and the SocketHandler (inherited by TCPLogstashHandler) to make sure they receive the emitted record.
使用此测试配置,logstash处理程序至少应该接收消息/ logrecord。如果没有运气我建议尝试调试logstash.TCPLogstashHandler和SocketHandler(由TCPLogstashHandler继承)以确保它们接收发出的记录。