mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
improve request logging
This commit is contained in:
parent
18749092ff
commit
dee4083bf3
11
src/app.js
11
src/app.js
@ -23,11 +23,6 @@ app.use(helmet({
|
||||
hidePoweredBy: false // deactivated because electron 4.0 crashes on this right after startup
|
||||
}));
|
||||
|
||||
app.use((req, res, next) => {
|
||||
log.request(req);
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(bodyParser.json({limit: '500mb'}));
|
||||
app.use(bodyParser.urlencoded({extended: false}));
|
||||
app.use(cookieParser());
|
||||
@ -78,12 +73,10 @@ app.use((req, res, next) => {
|
||||
// error handler
|
||||
app.use((err, req, res, next) => {
|
||||
if (err && err.message && (
|
||||
err.message.includes("Invalid package")
|
||||
|| (err.message.includes("Router not found for request") && err.message.includes("node_modules"))
|
||||
|| (err.message.includes("Router not found for request") && err.message.includes(".js.map"))
|
||||
(err.message.includes("Router not found for request") && err.message.includes(".js.map"))
|
||||
|| (err.message.includes("Router not found for request") && err.message.includes(".css.map"))
|
||||
)) {
|
||||
// electron 6 outputs a lot of such errors which do not seem important
|
||||
// ignore
|
||||
}
|
||||
else {
|
||||
log.info(err);
|
||||
|
@ -111,11 +111,7 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
|
||||
res.sendStatus(500);
|
||||
}
|
||||
|
||||
const time = Date.now() - start;
|
||||
|
||||
if (time >= 10) {
|
||||
console.log(`Slow request: ${time}ms - ${method} ${path}`);
|
||||
}
|
||||
log.request(req, Date.now() - start);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ function error(message) {
|
||||
|
||||
const requestBlacklist = [ "/libraries", "/app", "/images", "/stylesheets" ];
|
||||
|
||||
function request(req) {
|
||||
function request(req, timeMs) {
|
||||
for (const bl of requestBlacklist) {
|
||||
if (req.url.startsWith(bl)) {
|
||||
return;
|
||||
@ -75,7 +75,8 @@ function request(req) {
|
||||
return;
|
||||
}
|
||||
|
||||
info(req.method + " " + req.url);
|
||||
info((timeMs >= 10 ? "Slow " : "") +
|
||||
req.method + " " + req.url + " took " + timeMs + "ms");
|
||||
}
|
||||
|
||||
function pad(num) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user