2019-12-09 18:44:46 +00:00
|
|
|
diff --git a/src/services/log.js b/src/services/log.js
|
2023-01-12 20:17:04 +00:00
|
|
|
index a141eae14..094b9381b 100644
|
2019-12-09 18:44:46 +00:00
|
|
|
--- a/src/services/log.js
|
|
|
|
+++ b/src/services/log.js
|
2022-02-04 09:59:09 +00:00
|
|
|
@@ -1,15 +1,7 @@
|
2019-12-09 18:44:46 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
-const fs = require('fs');
|
2024-03-02 08:01:02 +00:00
|
|
|
-const dataDir = require('./data_dir.js');
|
|
|
|
const cls = require('./cls.js');
|
2022-02-04 09:59:09 +00:00
|
|
|
|
2019-12-09 18:44:46 +00:00
|
|
|
-if (!fs.existsSync(dataDir.LOG_DIR)) {
|
|
|
|
- fs.mkdirSync(dataDir.LOG_DIR, 0o700);
|
|
|
|
-}
|
|
|
|
-
|
2021-03-02 13:28:21 +00:00
|
|
|
-let logFile = null;
|
2019-12-09 18:44:46 +00:00
|
|
|
-
|
2021-03-02 13:28:21 +00:00
|
|
|
const SECOND = 1000;
|
|
|
|
const MINUTE = 60 * SECOND;
|
|
|
|
const HOUR = 60 * MINUTE;
|
2022-02-04 09:59:09 +00:00
|
|
|
@@ -17,38 +9,6 @@ const DAY = 24 * HOUR;
|
2019-12-09 18:44:46 +00:00
|
|
|
|
2021-03-02 13:28:21 +00:00
|
|
|
const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n';
|
2019-12-09 18:44:46 +00:00
|
|
|
|
2021-03-02 13:28:21 +00:00
|
|
|
-let todaysMidnight = null;
|
2019-12-09 18:44:46 +00:00
|
|
|
-
|
2021-03-02 13:28:21 +00:00
|
|
|
-initLogFile();
|
|
|
|
-
|
|
|
|
-function getTodaysMidnight() {
|
|
|
|
- const now = new Date();
|
|
|
|
-
|
|
|
|
- return new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function initLogFile() {
|
|
|
|
- todaysMidnight = getTodaysMidnight();
|
|
|
|
-
|
2023-01-12 20:17:04 +00:00
|
|
|
- const path = `${dataDir.LOG_DIR}/trilium-${formatDate()}.log`;
|
2021-03-02 13:28:21 +00:00
|
|
|
-
|
|
|
|
- if (logFile) {
|
|
|
|
- logFile.end();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- logFile = fs.createWriteStream(path, {flags: 'a'});
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function checkDate(millisSinceMidnight) {
|
|
|
|
- if (millisSinceMidnight >= DAY) {
|
|
|
|
- initLogFile();
|
2021-06-05 11:59:50 +00:00
|
|
|
-
|
2021-11-14 16:04:13 +00:00
|
|
|
- millisSinceMidnight -= DAY;
|
2021-03-02 13:28:21 +00:00
|
|
|
- }
|
2021-06-05 11:59:50 +00:00
|
|
|
-
|
|
|
|
- return millisSinceMidnight;
|
2021-03-02 13:28:21 +00:00
|
|
|
-}
|
|
|
|
-
|
|
|
|
function log(str) {
|
2022-02-04 09:59:09 +00:00
|
|
|
const bundleNoteId = cls.get("bundleNoteId");
|
|
|
|
|
|
|
|
@@ -56,12 +16,6 @@ function log(str) {
|
|
|
|
str = `[Script ${bundleNoteId}] ${str}`;
|
|
|
|
}
|
|
|
|
|
2021-06-05 11:59:50 +00:00
|
|
|
- let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
|
2021-03-02 13:28:21 +00:00
|
|
|
-
|
2021-06-05 11:59:50 +00:00
|
|
|
- millisSinceMidnight = checkDate(millisSinceMidnight);
|
2021-03-02 13:28:21 +00:00
|
|
|
-
|
2023-01-12 20:17:04 +00:00
|
|
|
- logFile.write(`${formatTime(millisSinceMidnight)} ${str}${NEW_LINE}`);
|
2019-12-09 18:44:46 +00:00
|
|
|
-
|
2021-03-02 13:28:21 +00:00
|
|
|
console.log(str);
|
2019-12-09 18:44:46 +00:00
|
|
|
}
|
2023-01-12 20:17:04 +00:00
|
|
|
|