~adnano/go-gemini-devel

4 2

[Feature request] Log status code

Details
Message ID
<C949P8WNNK0L.1FBJ6LYPO4KLF@localhost>
DKIM signature
pass
Download raw message
Hey Adnano, 

I was wondering if this library could provide some sort of wrapper to
log the request status code when the server runs. Kind of like the
Gorilla logging handler:
https://pkg.go.dev/github.com/gorilla/handlers#LoggingHandler

Let me know if you think this should be a part of this library or
something external to it.

All the best, and thanks again for this project,
Alex
Details
Message ID
<C949ZVKX0UCJ.1ECCLWNVZ4E5T@nitro>
In-Reply-To
<C949P8WNNK0L.1FBJ6LYPO4KLF@localhost> (view parent)
DKIM signature
pass
Download raw message
On Mon Feb 8, 2021 at 10:51 AM EST, alex wennerberg wrote:
> Hey Adnano,
>
> I was wondering if this library could provide some sort of wrapper to
> log the request status code when the server runs. Kind of like the
> Gorilla logging handler:
> https://pkg.go.dev/github.com/gorilla/handlers#LoggingHandler
>
> Let me know if you think this should be a part of this library or
> something external to it.

go-gemini is more of a lower level library analogous to net/http, so it
probably should not be part of the library.

With the current design of go-gemini a logging wrapper is not possible.
This can be solved in one of two ways:

- Make ResponseWriter an interface similar to http.ResponseWriter. This
  would allow wrapping the ResponseWriter in a logging response writer
  that keeps track of the status code.
- Expose the ResponseWriter status code and meta fields, so that a
  logging handler can log them.

Once either of the above is implemented, implementing a logging handler
should be very simple.
Details
Message ID
<C9531JG020PB.4V57E734AEBE@nitro>
In-Reply-To
<C949ZVKX0UCJ.1ECCLWNVZ4E5T@nitro> (view parent)
DKIM signature
pass
Download raw message
I made ResponseWriter an interface, so it is now possible to wrap
ResponseWriter in another implementation that will keep track of the
status code and meta for logging purposes.

I also made a few other changes to increase consistency with net/http.
Details
Message ID
<C9HW6ZPKO59O.20ZE1OO7JVXS0@nitro>
In-Reply-To
<C9531JG020PB.4V57E734AEBE@nitro> (view parent)
DKIM signature
pass
Download raw message
I added an example logging middleware to examples/server.go to
demonstrate that a logging middleware is possible.
Details
Message ID
<C9HX9XL20JTG.ULPOIKRCLMA4@debian-alex>
In-Reply-To
<C9HW6ZPKO59O.20ZE1OO7JVXS0@nitro> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
On Wed Feb 24, 2021 at 8:13 AM PST, Adnan Maolood wrote:
> I added an example logging middleware to examples/server.go to
> demonstrate that a logging middleware is possible.

Great! I'll test this out on Flounder soon

Alex
Reply to thread Export thread (mbox)