go-ozzo / ozzo-routing

An extremely fast Go (golang) HTTP router that supports regular expression route matching. Comes with full support for building RESTful APIs.
MIT License
455 stars 51 forks source link

Implement support for alternative access loggers #33

Closed jonathana closed 7 years ago

jonathana commented 7 years ago

This commit implements additional types that allow custom loggers to be supplied for the ozzo-routing/access middleware. The original access logger has been re-factored to use the new CustomLogger method to create the Logger method that returns the logging middleware. In addition, a logger that can be used to write metrics to Datadog has been created that also uses CustomLogger.

Based on the 2 loggers existing, I believe that at least for now the refactor is sensible and can be used generally for writing to different logging/metric backends.

It might be desirable in the future to, instead of passing the actual request and response objects, to instead extract (or copy in the case of req.URL) data values into a struct that is then passed to the CustomLogger. Absent that, it is the responsibility today of CustomLogger implementors to make sure that their use of the request and response objects is concurrency safe. Specifically, these objects should be treated as read-only.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.643% when pulling d876094a7e640949d093d2a68171340a9d2fb6b1 on jonathana:master into d2a16ccf3fb7eca92e694ccabbd9200bfda4bc6f on go-ozzo:master.

qiangxue commented 7 years ago

Thanks!