trilium/services/log.js

46 lines
1,001 B
JavaScript
Raw Normal View History

"use strict";
const fs = require('fs');
2017-12-07 08:42:23 +08:00
const data_dir = require('./data_dir');
2017-12-07 08:42:23 +08:00
if (!fs.existsSync(data_dir.LOG_DIR)) {
fs.mkdirSync(data_dir.LOG_DIR, 0o700);
}
const logger = require('simple-node-logger').createRollingFileLogger({
errorEventName: 'error',
2017-12-07 08:42:23 +08:00
logDirectory: data_dir.LOG_DIR,
fileNamePattern: 'trilium-<DATE>.log',
dateFormat:'YYYY-MM-DD'
});
function info(message) {
logger.info(message);
2017-10-30 02:55:48 +08:00
console.log(message);
}
function error(message) {
2017-11-09 11:33:08 +08:00
// we're using .info() instead of .error() because simple-node-logger emits weird error for showError()
2017-10-30 02:55:48 +08:00
info(message);
}
2017-11-25 09:51:44 +08:00
const requestBlacklist = [ "/libraries", "/javascripts", "/images", "/stylesheets" ];
function request(req) {
for (const bl of requestBlacklist) {
if (req.url.startsWith(bl)) {
return;
}
}
logger.info(req.method + " " + req.url);
}
2017-12-07 08:42:23 +08:00
info("Using data dir: " + data_dir.TRILIUM_DATA_DIR);
module.exports = {
info,
error,
request
};