2019-12-09 19:44:46 +01:00
|
|
|
diff --git a/src/services/log.js b/src/services/log.js
|
2021-06-05 13:59:50 +02:00
|
|
|
index 1345ce39..a9770516 100644
|
2019-12-09 19:44:46 +01:00
|
|
|
--- a/src/services/log.js
|
|
|
|
+++ b/src/services/log.js
|
2021-03-02 14:28:21 +01:00
|
|
|
@@ -1,14 +1,5 @@
|
2019-12-09 19:44:46 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
-const fs = require('fs');
|
|
|
|
-const dataDir = require('./data_dir');
|
|
|
|
-
|
|
|
|
-if (!fs.existsSync(dataDir.LOG_DIR)) {
|
|
|
|
- fs.mkdirSync(dataDir.LOG_DIR, 0o700);
|
|
|
|
-}
|
|
|
|
-
|
2021-03-02 14:28:21 +01:00
|
|
|
-let logFile = null;
|
2019-12-09 19:44:46 +01:00
|
|
|
-
|
2021-03-02 14:28:21 +01:00
|
|
|
const SECOND = 1000;
|
|
|
|
const MINUTE = 60 * SECOND;
|
|
|
|
const HOUR = 60 * MINUTE;
|
2021-06-05 13:59:50 +02:00
|
|
|
@@ -16,45 +7,7 @@ const DAY = 24 * HOUR;
|
2019-12-09 19:44:46 +01:00
|
|
|
|
2021-03-02 14:28:21 +01:00
|
|
|
const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n';
|
2019-12-09 19:44:46 +01:00
|
|
|
|
2021-03-02 14:28:21 +01:00
|
|
|
-let todaysMidnight = null;
|
2019-12-09 19:44:46 +01:00
|
|
|
-
|
2021-03-02 14:28:21 +01:00
|
|
|
-initLogFile();
|
|
|
|
-
|
|
|
|
-function getTodaysMidnight() {
|
|
|
|
- const now = new Date();
|
|
|
|
-
|
|
|
|
- return new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function initLogFile() {
|
|
|
|
- todaysMidnight = getTodaysMidnight();
|
|
|
|
-
|
|
|
|
- const path = dataDir.LOG_DIR + '/trilium-' + formatDate() + '.log';
|
|
|
|
-
|
|
|
|
- if (logFile) {
|
|
|
|
- logFile.end();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- logFile = fs.createWriteStream(path, {flags: 'a'});
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function checkDate(millisSinceMidnight) {
|
|
|
|
- if (millisSinceMidnight >= DAY) {
|
|
|
|
- initLogFile();
|
2021-06-05 13:59:50 +02:00
|
|
|
-
|
|
|
|
- millisSinceMidnight =- DAY;
|
2021-03-02 14:28:21 +01:00
|
|
|
- }
|
2021-06-05 13:59:50 +02:00
|
|
|
-
|
|
|
|
- return millisSinceMidnight;
|
2021-03-02 14:28:21 +01:00
|
|
|
-}
|
|
|
|
-
|
|
|
|
function log(str) {
|
2021-06-05 13:59:50 +02:00
|
|
|
- let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
|
2021-03-02 14:28:21 +01:00
|
|
|
-
|
2021-06-05 13:59:50 +02:00
|
|
|
- millisSinceMidnight = checkDate(millisSinceMidnight);
|
2021-03-02 14:28:21 +01:00
|
|
|
-
|
|
|
|
- logFile.write(formatTime(millisSinceMidnight) + ' ' + str + NEW_LINE);
|
2019-12-09 19:44:46 +01:00
|
|
|
-
|
2021-03-02 14:28:21 +01:00
|
|
|
console.log(str);
|
2019-12-09 19:44:46 +01:00
|
|
|
}
|