2017-10-25 10:04:52 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const fs = require('fs');
|
2017-12-07 08:42:23 +08:00
|
|
|
const data_dir = require('./data_dir');
|
2017-10-25 10:04:52 +08:00
|
|
|
|
2017-12-07 08:42:23 +08:00
|
|
|
if (!fs.existsSync(data_dir.LOG_DIR)) {
|
|
|
|
fs.mkdirSync(data_dir.LOG_DIR, 0o700);
|
2017-10-25 10:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const logger = require('simple-node-logger').createRollingFileLogger({
|
|
|
|
errorEventName: 'error',
|
2017-12-07 08:42:23 +08:00
|
|
|
logDirectory: data_dir.LOG_DIR,
|
2017-10-25 10:04:52 +08:00
|
|
|
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);
|
2017-10-25 10:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2018-02-16 11:30:05 +08:00
|
|
|
info("ERROR: " + message);
|
2017-10-25 10:04:52 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 09:51:44 +08:00
|
|
|
const requestBlacklist = [ "/libraries", "/javascripts", "/images", "/stylesheets" ];
|
2017-10-25 10:04:52 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-10-25 10:04:52 +08:00
|
|
|
module.exports = {
|
|
|
|
info,
|
|
|
|
error,
|
|
|
|
request
|
|
|
|
};
|