首页 > 解决方案 > 如何在 Apache/Flask 中将多行字符串记录为单个日志条目?

问题描述

我有一个使用 apache 部署的烧瓶应用程序。我正在尝试将格式良好的异常堆栈跟踪打印到错误日志中,但是每一行文本都作为单独的条目日志打印在 apache 的错误日志中,这使得堆栈跟踪难以阅读。

作为一个最小的例子,我在烧瓶路线中有以下语句:

print('hello\nworld')

错误日志的实际输出是:

 [Sat Jun 19 12:39:41.143577 2021] [wsgi:error] [pid 31837:tid 139869910443776] [
 remote 90.64.164.4:34160] hello                                                 
 [Sat Jun 19 12:39:41.143580 2021] [wsgi:error] [pid 31837:tid 139869910443776] [
 remote 90.64.164.4:34160] world                                                 
 [Sat Jun 19 12:39:41.143583 2021] [wsgi:error] [pid 31837:tid 139869910443776] [
 remote 90.64.164.4:34160]

I would like it to be part of one entry like this:

 [Sat Jun 19 12:39:41.143583 2021] [wsgi:error] [pid 31837:tid 139869910443776] [
 remote 90.64.164.4:34160] hello
world

否则,我将不胜感激有关使用 apache 将堆栈跟踪写入日志文件的提示。

标签: pythonapachelogging

解决方案


推荐阅读