Files
speckle-server/packages/server/logging/errorLogging.js
T
Iain Sproat 78ecaeffcb Revert structured logging 2 (#1240)
* Revert "'@' shortcut must come after it is configured in bootstrap (#1239)"

This reverts commit 967329473f.

* Revert "Structured logging (attempt 2) (#1234)"

This reverts commit 444d2ca7dd.
2022-12-05 15:46:09 +00:00

23 lines
652 B
JavaScript

/* istanbul ignore file */
const prometheusClient = require('prom-client')
let metricErrorCount = null
module.exports = {
errorLoggingMiddleware(err, req, res, next) {
if (metricErrorCount === null) {
metricErrorCount = new prometheusClient.Counter({
name: 'speckle_server_request_errors',
help: 'Number of requests that threw exceptions',
labelNames: ['route']
})
}
console.log(`Error when handling ${req.originalUrl} from ${req.ip}: ${err.message}`)
let route = 'unknown'
if (req.route && req.route.path) route = req.route.path
metricErrorCount.labels(route).inc()
next(err)
}
}