flea
flea copied to clipboard
Add request:log() function
This allows some basic logging to stdio. Takes a level string (WARN, ERROR, INFO) and the message to print, and gives a somewhat useful output. I'm not sure I'm happy with the format, it should probably conform to NGINX or apache access logs style. Logging to a file vs blindly printing may also be useful.
Nginx[1] and apache[2] both forward the fcgi process's stderr to their error logs, which I think is the most appropriate mechanism to use here.
Fcgi hijacks stdout/stderr so this can't be done in pure Lua, and requires changes in lua-fcgi (for example).
1: https://www.ruby-forum.com/topic/206019 - can't find anything official... 2: "mod_fastcgi logs FastCGI application error (stderr) output to the server log associated with the request."
Dumping this to stderr seems to do exactly what I want then. My only thoughts are DEBUG/INFO level logging may not belong there.
If you don't have any additional thoughts, I'll make a pull to add a luafcgi_log() on the C side, and then rewrite this pull to use that. I may also add a genericly named luafcgi_error() and make _log() a stub that calls _error().
Do you mind if I sit on this one for a few days?
Everyone seems to have slightly different logging requirements, so I think it's worth thinking about either making it very flexible, or not including it at all.
The most flexible approach would be to log to the output streams (so this PR + stderr), and let people pipe things where they want them. However, at that point, the logging code is so trivial that it doesn't really seem necessary to include in the framework.
No hurries on this, I'm not sure I like any of the solutions either.
I think my minimum requirements are a print() function to stdout (the base lua one is fine here,) and a print_err() function to stderr (currently lacking.) Whether or not log() lives in the framework or my code doesn't seem to be a big issue.
If there is a log() function in the framework, my minimum requirements are printing the IP, an error level, and a message. I just added the user agent to match Apache style access logs.