|
Kamil Kisiel |
at Apr 24, 2013 at 5:48 pm
|
⇧ |
| |
Currently there is not a way to add custom fields, because the handler
would need to know how to get the data for those fields. The handler works
on the basis of using a custom ResponseWriter implementation that records
the status code, but doesn't really know anything else you are doing in
your handlers. You could probably adopt a similar approach for your custom
handler, the code is not very complicated.
As far as a general solution, it could be possible to write a logging
handler that accepts a template format, and allow it to log request and
response headers. You could then log the user if it was being sent in a
header.
On Wednesday, April 24, 2013 10:10:21 AM UTC-7, Travis Keep wrote:Thanks for showing me this. I did not find this when searching for web log
libraries before, but it looks quite useful. Question: Is it possible to
add custom fields to the logs using these gorilla handlers? I am logging
the current logged in user as well as the usual fields in common logging
format.
On Wednesday, April 24, 2013 9:50:29 AM UTC-7, Kamil Kisiel wrote:You may also want to take a look at LoggingHandler and
CombinedLoggingHandler from
http://godoc.org/github.com/gorilla/handlerswhich are wrappers you can put around an HTTP handler to add Apache-style
logging.
On Wednesday, April 24, 2013 6:33:09 AM UTC-7, Travis Keep wrote:
For what its worth, I contributed github.com/keep94/weblogs.
After finishing my web server, I missed having the access logs. I
started by by wrapping the default handler with a simple log.Printf() to
show the URL, remote address, time, and method but later found handling
panics and extracting http status codes to be less trivial. Therefore I
decided to create this weblogs package so that others can easily add web
logs to their servers.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.