mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
logging stuff to rotated files through simple-node-logger
This commit is contained in:
41
services/log.js
Normal file
41
services/log.js
Normal file
@@ -0,0 +1,41 @@
|
||||
"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);
|
||||
}
|
||||
|
||||
function error(message) {
|
||||
logger.error(message);
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user