Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端错误日志按状态码区分存放 #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

13yu
Copy link

@13yu 13yu commented Dec 29, 2017

No description provided.

@drmingdrmer
Copy link
Contributor

这个模块有缓存日志吗?好像没看到..每个请求都打开一次文件再关闭吗?

@13yu
Copy link
Author

13yu commented Jan 2, 2018

请求结束前,日志是缓存在ngx.ctx.category_log.log_entry中的,在category_log.lua 61行,请求结束时,才会写到对应文件中,写的时候是打开又关闭一次文件的。

@drmingdrmer
Copy link
Contributor

drmingdrmer commented Jan 3, 2018

打开文件关闭文件挺费的..可能对性能会有影响. 可以一次打开后一直用吗?
但麻烦的地方是要处理nginx reopen 日志文件的信号. 能及时关闭.


或者再说吧..性能影响不一定很大..

@13yu
Copy link
Author

13yu commented Jan 3, 2018

嗯,这里写的日志文件不是nginx自己打开的那个日志文件,是lua代码自己临时需要时创建的文件,例如如果请求返回状态吗是505,就会创建一个front_505.error.log的文件,如果不存在的话。我再测试一下打开文件的性能吧,如果要保存文件描述符的话可能逻辑会稍微复杂一些。

@13yu
Copy link
Author

13yu commented Jan 19, 2018

@drmingdrmer 我测试了一下,
local f = io.open('testfile', 'a+') f.close()这段代码执行1000次,通常只需要2ms,重复打开文件因该没有太大的性能开销。

## new

**syntax**:
`category_log.wrap_log(opts)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简单说明下这个函数干啥的吧..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_M.max_entry_n = opts.max_entry_n
_M.log_level = opts.log_level or ngx.INFO

ngx.log = category_log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有个情况是timer里的日志怎么打印出来...我看timer里也可以使用ngx.ctx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timer里的日志好像不能按状态码区分,timer里的ctx和request中的ctx好像不是同一个,在timer里应该得不到返回状态码,不过所有的日志包括timer中的日志都会正常写到front.error.log,只有指定状态码的日志(不包括timer中的)会被写到另外的文件中,这些日志在两个文件中都有的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants