log 被截断

438 views
Skip to first unread message

wxianfeng

unread,
Dec 5, 2013, 10:53:49 PM12/5/13
to open...@googlegroups.com
hi all:

我在 openresty 中使用 print 或者 ngx.log 打印返回的 response, response 是json字符串

发现字符串超过一定长度就被截断了. error.log 里不显示完全.

因为运行的是手机客户端, 客户端也不好跟踪数据. 

请问服务端如何把数据全部 print 到 error.log, 而不被截断.

谢谢.

Yichun Zhang (agentzh)

unread,
Dec 5, 2013, 11:27:43 PM12/5/13
to openresty
Hello!

2013/12/5 wxianfeng:
> 我在 openresty 中使用 print 或者 ngx.log 打印返回的 response, response 是json字符串
>
> 发现字符串超过一定长度就被截断了. error.log 里不显示完全.
>

这是标准的 nginx 核心中的限制:error log 消息有硬编码的 2048 字节的上限。这个限制主要是为了作保护,毕竟错误日志打印是高代价操作。

你可以自己把 openresty 源码包中的 bundle/nginx-*/src/core/ngx_log.h 文件中的下面这一行

#define NGX_MAX_ERROR_STR 2048

中的 2048 调大,然后重新用 ./configure && make && make install 构造 openresty.

我打算在下一次 ngx_openresty 发布中将此限制调大为 4096 字节,2048 确实稍微有些小。

Regards,
-agentzh

Yichun Zhang (agentzh)

unread,
Dec 5, 2013, 11:41:27 PM12/5/13
to openresty
Hello!

2013/12/5 Yichun Zhang (agentzh):
> 我打算在下一次 ngx_openresty 发布中将此限制调大为 4096 字节,2048 确实稍微有些小。
>

刚刚在 ngx_openresty 的仓库里添加了 larger_max_error_str 补丁:

https://github.com/agentzh/ngx_openresty/blob/master/patches/nginx-1.4.3-larger_max_error_str.patch

默认大小调整为 4096,同时允许用户在 ./configure 命令行上覆盖默认的限制,而不用自己修改源码,比如

./configure --with-cc-opt="-DNGX_MAX_ERROR_STR=8192"

Regards,
-agentzh

wxianfeng

unread,
Dec 6, 2013, 12:48:26 AM12/6/13
to open...@googlegroups.com
嗯, 赞 春哥

要是能在 nginx.conf 有配置指令就更好了.


2013/12/6 Yichun Zhang (agentzh) <age...@gmail.com>

Regards,
-agentzh

--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Yichun Zhang (agentzh)

unread,
Dec 6, 2013, 12:55:03 AM12/6/13
to openresty
Hello!

2013/12/5 wxianfeng:
> 要是能在 nginx.conf 有配置指令就更好了.
>

Nginx 的错误日志消息的缓冲区目前是直接作为 C 的静态数组分配的,这算是一种优化。根据 Nginx
核心目前的内存分配方式,不太可能做成由配置文件动态指定的形式。

Regards,
-agentzh

andex.li

unread,
Dec 6, 2013, 2:31:59 AM12/6/13
to open...@googlegroups.com

ngx.print() 我试了下 8k都没有被截断,只有ngx.log() 会被截断吧

 

andex.li(李尊敬)

Email:  ande...@zhaopin.com.cn

Tel:   (8610) 58635888 ext. 68504

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 wxianfeng
发送时间: 2013126 11:54
收件人: open...@googlegroups.com
主题: [openresty] log 被截断

--
--

wxianfeng

unread,
Dec 6, 2013, 3:39:04 AM12/6/13
to open...@googlegroups.com

ngx.print 不会输出 到 log 中吧, ngx.print 是和 ngx.say 类似 写到 http body 中的.

andex.li

unread,
Dec 6, 2013, 4:08:37 AM12/6/13
to open...@googlegroups.com

是的,看错了 你用的是print 不是ngx.print()理解错了

 

andex.li(李尊敬)

Email:  ande...@zhaopin.com.cn

Tel:   (8610) 58635888 ext. 68504

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 wxianfeng

发送时间: 2013126 16:39
收件人: open...@googlegroups.com
主题: Re: 答复: [openresty] log 被截断

Reply all
Reply to author
Forward
0 new messages