-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
前端错误日志按状态码区分存放 #80
Conversation
这个模块有缓存日志吗?好像没看到..每个请求都打开一次文件再关闭吗? |
请求结束前,日志是缓存在ngx.ctx.category_log.log_entry中的,在category_log.lua 61行,请求结束时,才会写到对应文件中,写的时候是打开又关闭一次文件的。 |
打开文件关闭文件挺费的..可能对性能会有影响. 可以一次打开后一直用吗? 或者再说吧..性能影响不一定很大.. |
嗯,这里写的日志文件不是nginx自己打开的那个日志文件,是lua代码自己临时需要时创建的文件,例如如果请求返回状态吗是505,就会创建一个front_505.error.log的文件,如果不存在的话。我再测试一下打开文件的性能吧,如果要保存文件描述符的话可能逻辑会稍微复杂一些。 |
@drmingdrmer 我测试了一下, |
## new | ||
|
||
**syntax**: | ||
`category_log.wrap_log(opts)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
简单说明下这个函数干啥的吧..
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有个情况是timer里的日志怎么打印出来...我看timer里也可以使用ngx.ctx
There was a problem hiding this comment.
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中的)会被写到另外的文件中,这些日志在两个文件中都有的。
1748b4d
to
603d8bd
Compare
No description provided.