feat(logging): Exclude /status route from logging

This patch should reduce the logging noise a lot, by removing the
`/status` route from logging unless hedgedoc is running in debug mode or
the route throws an error code.

This is achieved by providing a "skip"-function to the morgan logging
provider.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
Sheogorath 2021-08-15 20:50:18 +02:00
parent 6c17823da1
commit add5d998c0
No known key found for this signature in database
GPG key ID: C9B1C80737B9CE18
2 changed files with 7 additions and 0 deletions

6
app.js
View file

@ -65,6 +65,12 @@ if (!config.useSSL && config.protocolUseSSL) {
// logger // logger
app.use(morgan('combined', { app.use(morgan('combined', {
skip: function(req, res) {
// skip logging if specified
// unless the app is running in debug mode
// or throws an error
return req.skipLogging && config.loglevel !== "debug" && res.statusCode < 400
},
stream: logger.stream stream: logger.stream
})) }))

View file

@ -14,6 +14,7 @@ const statusRouter = module.exports = Router()
// get status // get status
statusRouter.get('/status', function (req, res, next) { statusRouter.get('/status', function (req, res, next) {
req.skipLogging = true
realtime.getStatus(function (data) { realtime.getStatus(function (data) {
res.set({ res.set({
'Cache-Control': 'private', // only cache by client 'Cache-Control': 'private', // only cache by client