@tenonhq/dovetail-core 0.0.86 → 0.0.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FileLogger.js +34 -1
- package/dist/logMessages.js +9 -4
- package/package.json +1 -1
package/dist/FileLogger.js
CHANGED
|
@@ -41,10 +41,15 @@ exports.enableFileLogging = enableFileLogging;
|
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
// Roll over to a fresh log file once the current one has had this many writes.
|
|
45
|
+
// Long-running sessions (e.g. `dove watch`) would otherwise grow a single
|
|
46
|
+
// debug log unbounded; capping at 200 writes per file keeps each one small.
|
|
47
|
+
const ROTATION_WRITE_LIMIT = 200;
|
|
44
48
|
class FileLogger {
|
|
45
49
|
logFilePath;
|
|
46
50
|
logStream = null;
|
|
47
51
|
initialized = false;
|
|
52
|
+
writeCount = 0;
|
|
48
53
|
constructor() {
|
|
49
54
|
// Initialize on first use
|
|
50
55
|
this.logFilePath = "";
|
|
@@ -63,7 +68,8 @@ class FileLogger {
|
|
|
63
68
|
// Create or append to the log file
|
|
64
69
|
this.logStream = fs.createWriteStream(this.logFilePath, { flags: 'a' });
|
|
65
70
|
this.initialized = true;
|
|
66
|
-
|
|
71
|
+
this.writeCount = 0;
|
|
72
|
+
// Write header to log file — once, at the top of each (rotated) file
|
|
67
73
|
this.writeToFile(`\n${"=".repeat(80)}`);
|
|
68
74
|
this.writeToFile(`Dovetail Debug Log - Started at ${new Date().toISOString()}`);
|
|
69
75
|
this.writeToFile(`Log file: ${this.logFilePath}`);
|
|
@@ -76,6 +82,29 @@ class FileLogger {
|
|
|
76
82
|
console.error(chalk_1.default.red(`Failed to create log file: ${error}`));
|
|
77
83
|
}
|
|
78
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Close the current log file and start a new one once it has reached
|
|
87
|
+
* ROTATION_WRITE_LIMIT writes. Keeps any single debug log from growing huge
|
|
88
|
+
* during long watch sessions.
|
|
89
|
+
*/
|
|
90
|
+
rotateIfNeeded() {
|
|
91
|
+
if (!this.initialized)
|
|
92
|
+
return;
|
|
93
|
+
if (this.writeCount < ROTATION_WRITE_LIMIT)
|
|
94
|
+
return;
|
|
95
|
+
if (this.logStream && this.logStream.writable) {
|
|
96
|
+
const timestamp = new Date().toISOString();
|
|
97
|
+
this.logStream.write(`[${timestamp}] ${"=".repeat(80)}\n`);
|
|
98
|
+
this.logStream.write(`[${timestamp}] Log rotated after ${ROTATION_WRITE_LIMIT} writes — continues in a new file\n`);
|
|
99
|
+
this.logStream.write(`[${timestamp}] ${"=".repeat(80)}\n`);
|
|
100
|
+
}
|
|
101
|
+
if (this.logStream) {
|
|
102
|
+
this.logStream.end();
|
|
103
|
+
this.logStream = null;
|
|
104
|
+
}
|
|
105
|
+
this.initialized = false;
|
|
106
|
+
this.initialize();
|
|
107
|
+
}
|
|
79
108
|
/**
|
|
80
109
|
* Write a message to the log file
|
|
81
110
|
*/
|
|
@@ -83,9 +112,13 @@ class FileLogger {
|
|
|
83
112
|
if (!this.initialized) {
|
|
84
113
|
this.initialize();
|
|
85
114
|
}
|
|
115
|
+
else {
|
|
116
|
+
this.rotateIfNeeded();
|
|
117
|
+
}
|
|
86
118
|
if (this.logStream && this.logStream.writable) {
|
|
87
119
|
const timestamp = new Date().toISOString();
|
|
88
120
|
this.logStream.write(`[${timestamp}] ${message}\n`);
|
|
121
|
+
this.writeCount++;
|
|
89
122
|
}
|
|
90
123
|
}
|
|
91
124
|
/**
|
package/dist/logMessages.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.logBuildResults = exports.logPushResults = exports.log = void 0;
|
|
|
7
7
|
exports.logFilePush = logFilePush;
|
|
8
8
|
exports.logDeploy = logDeploy;
|
|
9
9
|
const Logger_1 = require("./Logger");
|
|
10
|
+
const FileLogger_1 = require("./FileLogger");
|
|
10
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
12
|
exports.log = console.log;
|
|
12
13
|
function parseError(err) {
|
|
@@ -20,14 +21,18 @@ function logFilePush(context, res) {
|
|
|
20
21
|
const instance = process.env.SN_INSTANCE || "instance";
|
|
21
22
|
const label = chalk_1.default.bold.blue;
|
|
22
23
|
const timestamp = new Date().toLocaleTimeString();
|
|
24
|
+
const fileLabel = context.tableName + "/" + context.name + " (" + context.targetField + ")";
|
|
23
25
|
if (success) {
|
|
24
|
-
Logger_1.logger.info(chalk_1.default.green("Pushed") + " " +
|
|
25
|
-
"
|
|
26
|
+
Logger_1.logger.info(chalk_1.default.green("Pushed") + " " + fileLabel + " to " + instance +
|
|
27
|
+
" at " + timestamp);
|
|
28
|
+
// Persist every push to the session log file (file-only, no console echo).
|
|
29
|
+
// The log file rotates every 200 writes (see FileLogger) so it never grows huge.
|
|
30
|
+
FileLogger_1.fileLogger.debug("Pushed " + fileLabel + " to " + instance + " at " + timestamp);
|
|
26
31
|
}
|
|
27
32
|
else {
|
|
28
|
-
Logger_1.logger.error("Failed to push " +
|
|
29
|
-
" (" + context.targetField + ") to " + instance);
|
|
33
|
+
Logger_1.logger.error("Failed to push " + fileLabel + " to " + instance);
|
|
30
34
|
Logger_1.logger.error(message);
|
|
35
|
+
FileLogger_1.fileLogger.debug("Failed to push " + fileLabel + " to " + instance + ": " + message);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
function multiLog(files, success, resultSet, successMessage, errorMessage, err) {
|