| 
									
										
										
										
											2017-10-24 22:04:52 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const LOG_DIR = require('./data_dir').LOG_DIR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!fs.existsSync(LOG_DIR)) { | 
					
						
							|  |  |  |     fs.mkdirSync(LOG_DIR, 0o700); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const logger = require('simple-node-logger').createRollingFileLogger({ | 
					
						
							|  |  |  |     errorEventName: 'error', | 
					
						
							|  |  |  |     logDirectory: LOG_DIR, | 
					
						
							|  |  |  |     fileNamePattern: 'trilium-<DATE>.log', | 
					
						
							|  |  |  |     dateFormat:'YYYY-MM-DD' | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function info(message) { | 
					
						
							|  |  |  |     logger.info(message); | 
					
						
							| 
									
										
										
										
											2017-10-29 14:55:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     console.log(message); | 
					
						
							| 
									
										
										
										
											2017-10-24 22:04:52 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function error(message) { | 
					
						
							| 
									
										
										
										
											2017-10-26 20:31:31 -04:00
										 |  |  |     // we're using .info() instead of .error() because simple-node-logger emits weird error for error()
 | 
					
						
							| 
									
										
										
										
											2017-10-29 14:55:48 -04:00
										 |  |  |     info(message); | 
					
						
							| 
									
										
										
										
											2017-10-24 22:04:52 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const requestBlacklist = [ "/api/audit", "/libraries", "/javascripts", "/images", "/stylesheets" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function request(req) { | 
					
						
							|  |  |  |     for (const bl of requestBlacklist) { | 
					
						
							|  |  |  |         if (req.url.startsWith(bl)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     logger.info(req.method + " " + req.url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     info, | 
					
						
							|  |  |  |     error, | 
					
						
							|  |  |  |     request | 
					
						
							|  |  |  | }; |