mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	improve request logging
This commit is contained in:
		
							
								
								
									
										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 |     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.json({limit: '500mb'})); | ||||||
| app.use(bodyParser.urlencoded({extended: false})); | app.use(bodyParser.urlencoded({extended: false})); | ||||||
| app.use(cookieParser()); | app.use(cookieParser()); | ||||||
| @@ -78,12 +73,10 @@ app.use((req, res, next) => { | |||||||
| // error handler | // error handler | ||||||
| app.use((err, req, res, next) => { | app.use((err, req, res, next) => { | ||||||
|     if (err && err.message && ( |     if (err && err.message && ( | ||||||
|         err.message.includes("Invalid package") |         (err.message.includes("Router not found for request") && err.message.includes(".js.map")) | ||||||
|         || (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(".css.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 { |     else { | ||||||
|         log.info(err); |         log.info(err); | ||||||
|   | |||||||
| @@ -111,11 +111,7 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio | |||||||
|             res.sendStatus(500); |             res.sendStatus(500); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         const time = Date.now() - start; |         log.request(req, Date.now() - start); | ||||||
|  |  | ||||||
|         if (time >= 10) { |  | ||||||
|             console.log(`Slow request: ${time}ms - ${method} ${path}`); |  | ||||||
|         } |  | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ function error(message) { | |||||||
|  |  | ||||||
| const requestBlacklist = [ "/libraries", "/app", "/images", "/stylesheets" ]; | const requestBlacklist = [ "/libraries", "/app", "/images", "/stylesheets" ]; | ||||||
|  |  | ||||||
| function request(req) { | function request(req, timeMs) { | ||||||
|     for (const bl of requestBlacklist) { |     for (const bl of requestBlacklist) { | ||||||
|         if (req.url.startsWith(bl)) { |         if (req.url.startsWith(bl)) { | ||||||
|             return; |             return; | ||||||
| @@ -75,7 +75,8 @@ function request(req) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     info(req.method + " " + req.url); |     info((timeMs >= 10 ? "Slow " : "") + | ||||||
|  |         req.method + " " + req.url + " took " + timeMs + "ms"); | ||||||
| } | } | ||||||
|  |  | ||||||
| function pad(num) { | function pad(num) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user