Skip to content
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

Allow passing custom logger #10

Closed
sajal opened this issue Jul 28, 2017 · 5 comments
Closed

Allow passing custom logger #10

sajal opened this issue Jul 28, 2017 · 5 comments

Comments

@sajal
Copy link

sajal commented Jul 28, 2017

Currently setting router.LogRequests = true , the requests logs are printed to stderr using default format. But I would like some way to pass a custom logger, example: logrus . Most logging implementations can be abstracted to a simple interface.

If provided use it, otherwise use the default behavior.

@nbari
Copy link
Owner

nbari commented Sep 26, 2017

Hi @sajal sorry for the late reply, I did some changes but after doing some tests I think is better to add the logger in a middleware.

In any case, I will try to see what could I do, mainly because the logger may need a custom responseWriter that depending on the logger it should be adapted.

Any ideas are more than welcome.

@nbari
Copy link
Owner

nbari commented Sep 28, 2017

@sajal What do you think about this: https://github.com/nbari/violetear/blob/master/violetear.go#L69

Basically, ask for a function so that you can pass the response writer:

// Logger
Logger func(*ResponseWriter, *http.Request)

The default one to use is this one: https://github.com/nbari/violetear/blob/master/logger.go

Please give a try and let me know what you think.

@sajal
Copy link
Author

sajal commented Sep 29, 2017

Thats useful. Looks like my code can use different logging paths based on status, etc...

@nbari
Copy link
Owner

nbari commented Sep 29, 2017

I still doing some improvements, for the idea is that based on your logger you can manipulate the as required, the function needs to be:

func logger(ww *ResponseWriter, r *http.Request) {}

And from there you can take or use any of the ResponseWriter, or the Request.

I will document this later, any ideas are more than welcome.

@nbari
Copy link
Owner

nbari commented Oct 7, 2017

#12

@nbari nbari closed this as completed Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants