Skip logging query paramters
Domuska opened this issue · comments
Hello! Thanks for the awesome library!
Is it possible to skip logging query parameters for requests? I'd like to log the route that requests get into, but I don't want to have the query parameters logged.
Thanks!
Hi @Domuska ! Most likely your log format is using the :url
token (https://github.com/expressjs/morgan#url) which is the full URL as Node.js / Express sees it. This includes the query string.
It sounds like you only want to log the path name part of the URL. If you are using Express, this is exposed automatically as req.pathname
.
Provided this, there are two different ways you can log path name instead of URL in your morgan logs
- Create a new token (https://github.com/expressjs/morgan#creating-new-tokens) like
:pathname
and then use that in your log format. For examplemorgan.token('pathname', (req, res) => req.pathname)
. - Redefine the existing
:url
token if you never want the full URL. For examplemorgan.token('url', (req, res) => req.pathname)
.
I hope this helps!
Ah, right, for some reason I didn't realize I could create just a new token to do this. Thanks a bunch!