node-logy 0.0.3 → 0.0.5
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/License +9 -0
- package/README.md +1 -1
- package/dist/index.d.ts +26 -63
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -140
- package/dist/index.js.map +1 -1
- package/dist/node_process.d.ts +5 -0
- package/dist/node_process.d.ts.map +1 -0
- package/dist/node_process.js +244 -0
- package/dist/node_process.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -2
package/License
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Yousaf Wazir
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* List of options you can pass to change the logger behaviour
|
|
3
|
-
*/
|
|
4
|
-
type NodeLoggerOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* Indicates if output produced specifically to the stdout console should be colored (defaults to `true`)
|
|
7
|
-
*/
|
|
8
|
-
useColoredOutput: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Indicates if stdout console output produced by this logger should be saved to log files (defaults to `true`)
|
|
11
|
-
*/
|
|
12
|
-
saveToLogFile: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The base path / path to the folder to save the log outputs to (defaults to `./logs`) then is converted to an absolute path internally
|
|
15
|
-
*/
|
|
16
|
-
logFilesBasePath: string;
|
|
17
|
-
/**
|
|
18
|
-
* Indicates how long old log files should be kept (defaults to `30` days)
|
|
19
|
-
*/
|
|
20
|
-
logFileRetentionPeriodInDays: number;
|
|
21
|
-
/**
|
|
22
|
-
* Indicates if it should add the time of when the log was made for a given log item (defaults to `true`)
|
|
23
|
-
*/
|
|
24
|
-
showLogTime: boolean;
|
|
25
|
-
};
|
|
1
|
+
import type types = require("./types");
|
|
26
2
|
/**
|
|
27
3
|
* Represents a logger used to log to node's stdout console and also save logs to log files.
|
|
28
|
-
* Uses
|
|
29
|
-
* as it has to ensure it makes the folder and file.
|
|
30
|
-
* Logs themselves are asynchronously added in a queue system then added to log files.
|
|
4
|
+
* Uses a seperate process that writes to log file while the main logger in your application process is non blocking
|
|
31
5
|
*/
|
|
32
6
|
declare class NodeLogger {
|
|
33
7
|
/**
|
|
@@ -35,31 +9,35 @@ declare class NodeLogger {
|
|
|
35
9
|
*/
|
|
36
10
|
private _options;
|
|
37
11
|
/**
|
|
38
|
-
*
|
|
12
|
+
* Holds ref to the go binary that we write to the stdin of
|
|
39
13
|
*/
|
|
40
|
-
private
|
|
14
|
+
private _spawnRef;
|
|
41
15
|
/**
|
|
42
|
-
*
|
|
16
|
+
* Indicates if flush has been sent
|
|
43
17
|
*/
|
|
44
|
-
private
|
|
18
|
+
private _isFlushing;
|
|
45
19
|
/**
|
|
46
|
-
*
|
|
20
|
+
* Tracks the UTC date (YYYY-MM-DD) to handle daily file rotation
|
|
47
21
|
*/
|
|
48
|
-
private
|
|
49
|
-
/**
|
|
50
|
-
* Indicates when the last clean happened; should be every 24 hours.
|
|
51
|
-
* Holds a UTC string of when it last happened.
|
|
52
|
-
*/
|
|
53
|
-
private _lastCleanedOldLogsUtc;
|
|
22
|
+
private _currentDateStr;
|
|
54
23
|
/**
|
|
55
24
|
* Pass additional options on initialization to change the logger's behaviour
|
|
56
25
|
* @param options Change the behaviour of the logger
|
|
57
26
|
*/
|
|
58
|
-
constructor(options?: Partial<NodeLoggerOptions>);
|
|
27
|
+
constructor(options?: Partial<types.NodeLoggerOptions>);
|
|
28
|
+
/**
|
|
29
|
+
* Helper to format a date into a UTC YYYY-MM-DD string
|
|
30
|
+
*/
|
|
31
|
+
private getUtcDateString;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the UTC day has changed
|
|
34
|
+
*/
|
|
35
|
+
private checkDateRotation;
|
|
59
36
|
/**
|
|
60
|
-
*
|
|
37
|
+
* Trys to find the `node_process` file which spawn the protcol handler
|
|
38
|
+
* @returns The path to the file or undefined
|
|
61
39
|
*/
|
|
62
|
-
private
|
|
40
|
+
private findNodeProcessFile;
|
|
63
41
|
/**
|
|
64
42
|
* Log information
|
|
65
43
|
* @param level The specific level of log message
|
|
@@ -93,30 +71,15 @@ declare class NodeLogger {
|
|
|
93
71
|
*/
|
|
94
72
|
error(messageOrError: unknown, ...messages: unknown[]): void;
|
|
95
73
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* to make sure we don't write to stale log files.
|
|
99
|
-
* The format is as follows: base path provided, then the filename is `YYYY-MM-DD`
|
|
100
|
-
*/
|
|
101
|
-
private getTodaysLogFilePath;
|
|
102
|
-
/**
|
|
103
|
-
* Enqueues the log message to be asynchronously added to the log file
|
|
104
|
-
* @param message The message to add to the log file
|
|
105
|
-
*/
|
|
106
|
-
private enqueMessage;
|
|
107
|
-
/**
|
|
108
|
-
* Processes the message queue asynchronously
|
|
109
|
-
*/
|
|
110
|
-
private processQueue;
|
|
111
|
-
/**
|
|
112
|
-
* Synchronously flushes all remaining logs in the queue to the log file.
|
|
113
|
-
* Used during process exit to ensure no logs are lost.
|
|
74
|
+
* Used to write any remaning logs to the stdin and close the sidecar logger - NEEDS to be called on app exit or on app cleanup
|
|
75
|
+
* as if not it will keep the app alive and wait for flush command
|
|
114
76
|
*/
|
|
115
|
-
|
|
77
|
+
flush(): Promise<void>;
|
|
116
78
|
/**
|
|
117
|
-
*
|
|
79
|
+
* Write to the stdin of the process in the protocol defined
|
|
80
|
+
* @param request The request payload
|
|
118
81
|
*/
|
|
119
|
-
private
|
|
82
|
+
private writeToStdin;
|
|
120
83
|
/**
|
|
121
84
|
* Extracts as much information as possible from an error or object and returns it as a string
|
|
122
85
|
* @param error The error object or any object to extract information from
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,KAAK,GAAG,QAAQ,SAAS,CAAC,CAAC;AAsBvC;;;GAGG;AACH,cAAM,UAAU;IACd;;OAEG;IACH,OAAO,CAAC,QAAQ,CAA0B;IAE1C;;OAEG;IACH,OAAO,CAAC,SAAS,CAA6D;IAE9E;;OAEG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;OAEG;IACH,OAAO,CAAC,eAAe,CAAS;IAEhC;;;OAGG;gBACS,OAAO,GAAE,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAkB;IA6DtE;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;;;OAKG;IACH,OAAO,CAAC,GAAG;IA6CX;;;;OAIG;IACI,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE;IAIpD;;;;OAIG;IACI,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE;IAIpD;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,cAAc,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI5D;;;OAGG;IACI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgC7B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAuBpB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAwFzB;;;;AAED,kBAEE"}
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
2
|
+
const child_process = require("node:child_process");
|
|
3
3
|
const path = require("node:path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
/**
|
|
6
|
+
* ANSI Escape Codes for terminal colors
|
|
7
|
+
*/
|
|
8
|
+
const ANSI_RESET = "\x1b[0m";
|
|
4
9
|
/**
|
|
5
10
|
* Holds default options for the logger
|
|
6
11
|
*/
|
|
7
12
|
const defaultOptions = {
|
|
8
|
-
logFileRetentionPeriodInDays: 30,
|
|
9
13
|
logFilesBasePath: "./logs",
|
|
10
14
|
saveToLogFile: true,
|
|
11
15
|
showLogTime: true,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
INFO: "\x1b[34m",
|
|
19
|
-
WARN: "\x1b[33m",
|
|
20
|
-
ERROR: "\x1b[31m",
|
|
16
|
+
useAnsiColors: true,
|
|
17
|
+
colorMap: {
|
|
18
|
+
INFO: "\x1b[32m", // Green
|
|
19
|
+
WARN: "\x1b[33m", // Yellow
|
|
20
|
+
ERROR: "\x1b[31m", // Red
|
|
21
|
+
},
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
24
|
* Represents a logger used to log to node's stdout console and also save logs to log files.
|
|
24
|
-
* Uses
|
|
25
|
-
* as it has to ensure it makes the folder and file.
|
|
26
|
-
* Logs themselves are asynchronously added in a queue system then added to log files.
|
|
25
|
+
* Uses a seperate process that writes to log file while the main logger in your application process is non blocking
|
|
27
26
|
*/
|
|
28
27
|
class NodeLogger {
|
|
29
28
|
/**
|
|
@@ -31,36 +30,28 @@ class NodeLogger {
|
|
|
31
30
|
*/
|
|
32
31
|
_options;
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
_messageQueue = [];
|
|
37
|
-
/**
|
|
38
|
-
* How many messages we can hold before we start dropping old ones if we cannot write to log file
|
|
33
|
+
* Holds ref to the go binary that we write to the stdin of
|
|
39
34
|
*/
|
|
40
|
-
|
|
35
|
+
_spawnRef = null;
|
|
41
36
|
/**
|
|
42
|
-
* Indicates if
|
|
37
|
+
* Indicates if flush has been sent
|
|
43
38
|
*/
|
|
44
|
-
|
|
39
|
+
_isFlushing = false;
|
|
45
40
|
/**
|
|
46
|
-
*
|
|
47
|
-
* Holds a UTC string of when it last happened.
|
|
41
|
+
* Tracks the UTC date (YYYY-MM-DD) to handle daily file rotation
|
|
48
42
|
*/
|
|
49
|
-
|
|
43
|
+
_currentDateStr;
|
|
50
44
|
/**
|
|
51
45
|
* Pass additional options on initialization to change the logger's behaviour
|
|
52
46
|
* @param options Change the behaviour of the logger
|
|
53
47
|
*/
|
|
54
48
|
constructor(options = defaultOptions) {
|
|
55
|
-
|
|
49
|
+
const mergedColorMap = { ...defaultOptions.colorMap, ...options.colorMap };
|
|
50
|
+
this._options = { ...defaultOptions, ...options, colorMap: mergedColorMap };
|
|
51
|
+
this._currentDateStr = this.getUtcDateString(new Date());
|
|
56
52
|
if (typeof this._options !== "object") {
|
|
57
53
|
throw new TypeError("Options passed cannot be null or undefined; it must be an object");
|
|
58
54
|
}
|
|
59
|
-
if (typeof this._options.logFileRetentionPeriodInDays !== "number" ||
|
|
60
|
-
(typeof this._options.logFileRetentionPeriodInDays === "number" &&
|
|
61
|
-
this._options.logFileRetentionPeriodInDays <= 0)) {
|
|
62
|
-
throw new TypeError("logFileRetentionPeriodInDays must be a number and greater than 0");
|
|
63
|
-
}
|
|
64
55
|
if (typeof this._options.logFilesBasePath !== "string" ||
|
|
65
56
|
(typeof this._options.logFilesBasePath === "string" &&
|
|
66
57
|
this._options.logFilesBasePath.trim() === "")) {
|
|
@@ -72,41 +63,66 @@ class NodeLogger {
|
|
|
72
63
|
if (typeof this._options.showLogTime !== "boolean") {
|
|
73
64
|
throw new TypeError("showLogTime must be a boolean");
|
|
74
65
|
}
|
|
75
|
-
if (typeof this._options.useColoredOutput !== "boolean") {
|
|
76
|
-
throw new TypeError("useColoredOutput must be a boolean");
|
|
77
|
-
}
|
|
78
66
|
this._options.logFilesBasePath = path.resolve(this._options.logFilesBasePath);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
throw new Error(`Could not create log directory: ${this.extractErrorInfo(error)}`);
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
if (this._options.saveToLogFile) {
|
|
90
|
-
this.cleanupOldLogFiles();
|
|
91
|
-
this._lastCleanedOldLogsUtc = new Date().toUTCString();
|
|
67
|
+
if (options.saveToLogFile) {
|
|
68
|
+
let process_path = this.findNodeProcessFile();
|
|
69
|
+
if (!process_path) {
|
|
70
|
+
throw new Error("Failed ot find node_process file");
|
|
92
71
|
}
|
|
72
|
+
this._spawnRef = child_process.spawn("node", [
|
|
73
|
+
process_path,
|
|
74
|
+
`--basePath=${this._options.logFilesBasePath}`,
|
|
75
|
+
]); // we are spawing a js file so we use node
|
|
76
|
+
process.on("beforeExit", () => {
|
|
77
|
+
this.flush();
|
|
78
|
+
});
|
|
79
|
+
process.on("SIGINT", () => {
|
|
80
|
+
this.flush();
|
|
81
|
+
});
|
|
82
|
+
process.on("SIGTERM", () => {
|
|
83
|
+
this.flush();
|
|
84
|
+
});
|
|
85
|
+
process.on("uncaughtException", () => {
|
|
86
|
+
this.flush();
|
|
87
|
+
});
|
|
93
88
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Helper to format a date into a UTC YYYY-MM-DD string
|
|
92
|
+
*/
|
|
93
|
+
getUtcDateString(date) {
|
|
94
|
+
const y = date.getUTCFullYear();
|
|
95
|
+
const m = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
96
|
+
const d = String(date.getUTCDate()).padStart(2, "0");
|
|
97
|
+
return `${y}-${m}-${d}`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the UTC day has changed
|
|
101
|
+
*/
|
|
102
|
+
checkDateRotation() {
|
|
103
|
+
const nowUtcStr = this.getUtcDateString(new Date());
|
|
104
|
+
if (nowUtcStr !== this._currentDateStr) {
|
|
105
|
+
this._currentDateStr = nowUtcStr;
|
|
106
|
+
this.writeToStdin({
|
|
107
|
+
id: Date.now(),
|
|
108
|
+
method: "reload",
|
|
109
|
+
data: null,
|
|
110
|
+
});
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
/**
|
|
100
|
-
*
|
|
114
|
+
* Trys to find the `node_process` file which spawn the protcol handler
|
|
115
|
+
* @returns The path to the file or undefined
|
|
101
116
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
findNodeProcessFile() {
|
|
118
|
+
try {
|
|
119
|
+
const files = fs.readdirSync(__dirname);
|
|
120
|
+
const match = files.find((file) => file === "node_process.js");
|
|
121
|
+
return match ? path.join(__dirname, match) : undefined;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return undefined;
|
|
105
125
|
}
|
|
106
|
-
const lastCleaned = new Date(this._lastCleanedOldLogsUtc).getTime();
|
|
107
|
-
const now = new Date().getTime();
|
|
108
|
-
const TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1000;
|
|
109
|
-
return now - lastCleaned >= TWENTY_FOUR_HOURS_MS;
|
|
110
126
|
}
|
|
111
127
|
/**
|
|
112
128
|
* Log information
|
|
@@ -117,20 +133,26 @@ class NodeLogger {
|
|
|
117
133
|
log(level, content, ...contents) {
|
|
118
134
|
const now = new Date();
|
|
119
135
|
const logParts = [];
|
|
136
|
+
if (this._options.saveToLogFile) {
|
|
137
|
+
this.checkDateRotation();
|
|
138
|
+
}
|
|
120
139
|
if (this._options.showLogTime) {
|
|
121
140
|
const timestamp = now.toUTCString();
|
|
122
141
|
logParts.push(`[${timestamp}]`);
|
|
123
142
|
}
|
|
124
|
-
|
|
125
|
-
? `${colorMap[level]}${level}\x1b[0m`
|
|
126
|
-
: level;
|
|
127
|
-
logParts.push(`[${levelStr}]`);
|
|
143
|
+
logParts.push(`[${level}]`);
|
|
128
144
|
let message = `${this.extractErrorInfo(content)}`;
|
|
129
145
|
contents.forEach((m) => {
|
|
130
146
|
message += ` ${this.extractErrorInfo(m)}`;
|
|
131
147
|
});
|
|
132
148
|
logParts.push(message);
|
|
133
|
-
|
|
149
|
+
let fullConsoleMessage = logParts.join(" ");
|
|
150
|
+
if (this._options.useAnsiColors) {
|
|
151
|
+
const colorCode = this._options.colorMap[level];
|
|
152
|
+
if (colorCode) {
|
|
153
|
+
fullConsoleMessage = `${colorCode}${fullConsoleMessage}${ANSI_RESET}`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
134
156
|
if (level === "ERROR")
|
|
135
157
|
console.error(fullConsoleMessage);
|
|
136
158
|
else if (level === "WARN")
|
|
@@ -138,12 +160,13 @@ class NodeLogger {
|
|
|
138
160
|
else
|
|
139
161
|
console.log(fullConsoleMessage);
|
|
140
162
|
if (this._options.saveToLogFile) {
|
|
141
|
-
if (this.shouldCleanOldLogs()) {
|
|
142
|
-
this.cleanupOldLogFiles();
|
|
143
|
-
this._lastCleanedOldLogsUtc = new Date().toUTCString();
|
|
144
|
-
}
|
|
145
163
|
const fileTime = this._options.showLogTime ? now.toUTCString() : "";
|
|
146
|
-
|
|
164
|
+
const data = `${fileTime} ${level} ${message}`;
|
|
165
|
+
this.writeToStdin({
|
|
166
|
+
method: "log",
|
|
167
|
+
data,
|
|
168
|
+
id: 1,
|
|
169
|
+
});
|
|
147
170
|
}
|
|
148
171
|
}
|
|
149
172
|
/**
|
|
@@ -178,91 +201,57 @@ class NodeLogger {
|
|
|
178
201
|
this.log("ERROR", messageOrError, ...messages);
|
|
179
202
|
}
|
|
180
203
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* to make sure we don't write to stale log files.
|
|
184
|
-
* The format is as follows: base path provided, then the filename is `YYYY-MM-DD`
|
|
204
|
+
* Used to write any remaning logs to the stdin and close the sidecar logger - NEEDS to be called on app exit or on app cleanup
|
|
205
|
+
* as if not it will keep the app alive and wait for flush command
|
|
185
206
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.processQueue();
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Processes the message queue asynchronously
|
|
203
|
-
*/
|
|
204
|
-
async processQueue() {
|
|
205
|
-
if (this._isWriting)
|
|
206
|
-
return;
|
|
207
|
-
this._isWriting = true;
|
|
208
|
-
while (this._messageQueue.length > 0) {
|
|
209
|
-
const messages = this._messageQueue.splice(0);
|
|
207
|
+
flush() {
|
|
208
|
+
if (this._isFlushing)
|
|
209
|
+
return Promise.resolve();
|
|
210
|
+
this._isFlushing = true;
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
const timeout = setTimeout(() => {
|
|
213
|
+
this._spawnRef?.removeAllListeners("exit");
|
|
214
|
+
reject(new Error("Flush timed out after 4 seconds: Child process failed to exit."));
|
|
215
|
+
}, 4000);
|
|
216
|
+
this._spawnRef?.once("exit", () => {
|
|
217
|
+
clearTimeout(timeout);
|
|
218
|
+
resolve();
|
|
219
|
+
});
|
|
210
220
|
try {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
221
|
+
this.writeToStdin({
|
|
222
|
+
id: 1,
|
|
223
|
+
method: "flush",
|
|
224
|
+
data: null,
|
|
214
225
|
});
|
|
215
226
|
}
|
|
216
|
-
catch (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
break;
|
|
227
|
+
catch (err) {
|
|
228
|
+
clearTimeout(timeout);
|
|
229
|
+
reject(err);
|
|
220
230
|
}
|
|
221
|
-
}
|
|
222
|
-
this._isWriting = false;
|
|
231
|
+
});
|
|
223
232
|
}
|
|
224
233
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
234
|
+
* Write to the stdin of the process in the protocol defined
|
|
235
|
+
* @param request The request payload
|
|
227
236
|
*/
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
237
|
+
writeToStdin(request) {
|
|
238
|
+
if (typeof request !== "object" || request === null) {
|
|
239
|
+
throw new TypeError("request must be an object");
|
|
231
240
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
nodeFs.appendFileSync(this.getTodaysLogFilePath(), content, {
|
|
235
|
-
encoding: "utf8",
|
|
236
|
-
});
|
|
237
|
-
this._messageQueue = [];
|
|
241
|
+
if (!this._spawnRef || !this._spawnRef.stdin.writable) {
|
|
242
|
+
throw new Error("Cannot write to stdin");
|
|
238
243
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Removes log files older than the retention period
|
|
245
|
-
*/
|
|
246
|
-
cleanupOldLogFiles() {
|
|
244
|
+
const json = JSON.stringify(request);
|
|
245
|
+
const header = `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n`;
|
|
246
|
+
const payload = header + json;
|
|
247
247
|
try {
|
|
248
|
-
|
|
249
|
-
const now = new Date();
|
|
250
|
-
const retentionMs = this._options.logFileRetentionPeriodInDays * 24 * 60 * 60 * 1000;
|
|
251
|
-
for (const file of files) {
|
|
252
|
-
if (!file.endsWith(".log"))
|
|
253
|
-
continue;
|
|
254
|
-
const dateString = file.replace(".log", "");
|
|
255
|
-
const fileDate = new Date(`${dateString}T00:00:00Z`);
|
|
256
|
-
if (isNaN(fileDate.getTime()))
|
|
257
|
-
continue;
|
|
258
|
-
const fileAgeMs = now.getTime() - fileDate.getTime();
|
|
259
|
-
if (fileAgeMs > retentionMs) {
|
|
260
|
-
nodeFs.unlinkSync(path.join(this._options.logFilesBasePath, file));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
248
|
+
this._spawnRef.stdin.write(payload);
|
|
263
249
|
}
|
|
264
250
|
catch (error) {
|
|
265
|
-
console.error(
|
|
251
|
+
console.error("Failed to write to node_process");
|
|
252
|
+
console.error(this.extractErrorInfo(error));
|
|
253
|
+
this._spawnRef.kill();
|
|
254
|
+
throw error;
|
|
266
255
|
}
|
|
267
256
|
}
|
|
268
257
|
/**
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,oDAAqD;AACrD,kCAAmC;AACnC,yBAA0B;AAG1B;;GAEG;AACH,MAAM,UAAU,GAAG,SAAS,CAAC;AAE7B;;GAEG;AACH,MAAM,cAAc,GAA4B;IAC9C,gBAAgB,EAAE,QAAQ;IAC1B,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU,EAAE,QAAQ;QAC1B,IA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
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This is a self contained script that is spawend using the main node logger class as a sidecar to offload the writing logs to a log file to a serpate process
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
/**
|
|
9
|
+
* Holds args passed to the CLI
|
|
10
|
+
*/
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
/**
|
|
13
|
+
* Options for how the process should act
|
|
14
|
+
*/
|
|
15
|
+
const options = {
|
|
16
|
+
basePath: "",
|
|
17
|
+
startedUtc: new Date().toUTCString(),
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Buffer for stdin data
|
|
21
|
+
*/
|
|
22
|
+
let buffer = "";
|
|
23
|
+
/**
|
|
24
|
+
* How much we store beofre we flush
|
|
25
|
+
*/
|
|
26
|
+
const BATCH_SIZE = 1000;
|
|
27
|
+
/**
|
|
28
|
+
* How long we wait and collect logs beofre flushing
|
|
29
|
+
*/
|
|
30
|
+
const FLUSH_MS = 50;
|
|
31
|
+
/**
|
|
32
|
+
* Holds the messages we add to thje log file
|
|
33
|
+
*/
|
|
34
|
+
let batch = [];
|
|
35
|
+
/**
|
|
36
|
+
* The timer used to run flush batches
|
|
37
|
+
*/
|
|
38
|
+
let timer = null;
|
|
39
|
+
/**
|
|
40
|
+
* The stream to write to the file
|
|
41
|
+
*/
|
|
42
|
+
let writeStream = null;
|
|
43
|
+
/**
|
|
44
|
+
* Write the data to the file stream
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
function flushBatch() {
|
|
48
|
+
if (batch.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
const data = batch.join("\n") + "\n";
|
|
51
|
+
writeStream?.write(data);
|
|
52
|
+
batch = [];
|
|
53
|
+
stopTimer();
|
|
54
|
+
}
|
|
55
|
+
/** Stop the timer for flush */
|
|
56
|
+
function stopTimer() {
|
|
57
|
+
if (timer) {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
timer = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Starts the flush timer to be called when it's ready
|
|
64
|
+
*/
|
|
65
|
+
function startTimer() {
|
|
66
|
+
if (timer)
|
|
67
|
+
return;
|
|
68
|
+
timer = setTimeout(() => {
|
|
69
|
+
flushBatch();
|
|
70
|
+
timer = null;
|
|
71
|
+
}, FLUSH_MS);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Loops through args and looks for flags and extracts and sets there values
|
|
75
|
+
*/
|
|
76
|
+
function setOptionValues() {
|
|
77
|
+
for (const arg of args) {
|
|
78
|
+
if (arg.startsWith("--basePath=")) {
|
|
79
|
+
options.basePath = path.resolve(arg.split("=")[1] ?? "");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate the arg values to make sure they are valid
|
|
85
|
+
*/
|
|
86
|
+
function validateOptions() {
|
|
87
|
+
if (!options.basePath || options.basePath == "") {
|
|
88
|
+
console.error("Error: --basePath is required");
|
|
89
|
+
console.error("Usage: --basePath=/some/path");
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sync create the base folder path if it does not exit
|
|
95
|
+
*/
|
|
96
|
+
function createBasePath() {
|
|
97
|
+
try {
|
|
98
|
+
if (!fs.existsSync(options.basePath)) {
|
|
99
|
+
fs.mkdirSync(options.basePath, { recursive: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error("Failed to make base dir");
|
|
104
|
+
console.error(error);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets todays log file path in format YYYY-MM-DD and returns a string for example `c:/dev/logs/2026-01.23.log`
|
|
110
|
+
*/
|
|
111
|
+
function getTodaysLogFile() {
|
|
112
|
+
const today = new Date().toISOString().split("T")[0];
|
|
113
|
+
return path.join(options.basePath, `${today}.log`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Send response back to stdout
|
|
117
|
+
*/
|
|
118
|
+
function sendResponse(response) {
|
|
119
|
+
const json = JSON.stringify(response);
|
|
120
|
+
const header = `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n`;
|
|
121
|
+
process.stdout.write(header + json);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Handle a request
|
|
125
|
+
*/
|
|
126
|
+
function handleRequest(req) {
|
|
127
|
+
try {
|
|
128
|
+
if (!req || typeof req !== "object")
|
|
129
|
+
throw new Error("Invalid request object");
|
|
130
|
+
const { id, method, data } = req;
|
|
131
|
+
if (typeof id !== "number")
|
|
132
|
+
throw new Error("Invalid or missing id");
|
|
133
|
+
if (typeof method !== "string")
|
|
134
|
+
throw new Error("Invalid or missing method");
|
|
135
|
+
switch (method) {
|
|
136
|
+
case "log":
|
|
137
|
+
const logText = String(data);
|
|
138
|
+
batch.push(logText);
|
|
139
|
+
if (batch.length >= BATCH_SIZE) {
|
|
140
|
+
flushBatch();
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
startTimer();
|
|
144
|
+
}
|
|
145
|
+
sendResponse({
|
|
146
|
+
id,
|
|
147
|
+
method,
|
|
148
|
+
success: true,
|
|
149
|
+
error: null,
|
|
150
|
+
message: "queued",
|
|
151
|
+
});
|
|
152
|
+
break;
|
|
153
|
+
case "flush":
|
|
154
|
+
flushBatch();
|
|
155
|
+
stopTimer();
|
|
156
|
+
if (writeStream) {
|
|
157
|
+
writeStream.end();
|
|
158
|
+
writeStream.on("finish", () => {
|
|
159
|
+
sendResponse({
|
|
160
|
+
id,
|
|
161
|
+
method,
|
|
162
|
+
success: true,
|
|
163
|
+
error: null,
|
|
164
|
+
message: "flushed and closed",
|
|
165
|
+
});
|
|
166
|
+
process.nextTick(() => process.exit(0));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
process.exit(0);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case "reload":
|
|
174
|
+
flushBatch();
|
|
175
|
+
writeStream?.end();
|
|
176
|
+
writeStream = fs.createWriteStream(getTodaysLogFile(), { flags: "a" });
|
|
177
|
+
sendResponse({
|
|
178
|
+
id,
|
|
179
|
+
method,
|
|
180
|
+
success: true,
|
|
181
|
+
error: null,
|
|
182
|
+
message: "reloaded",
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
throw new Error("Unknown method: " + method);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
sendResponse({
|
|
191
|
+
id: req?.id ?? -1,
|
|
192
|
+
method: req?.method ?? "unknown",
|
|
193
|
+
success: false,
|
|
194
|
+
error: err instanceof Error ? err.message : String(err),
|
|
195
|
+
message: null,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Parses the buffer for complete messages
|
|
201
|
+
*/
|
|
202
|
+
function parseBuffer() {
|
|
203
|
+
while (true) {
|
|
204
|
+
const headerEnd = buffer.indexOf("\r\n\r\n");
|
|
205
|
+
if (headerEnd === -1)
|
|
206
|
+
return; // incomplete header
|
|
207
|
+
const header = buffer.slice(0, headerEnd);
|
|
208
|
+
const match = header.match(/Content-Length:\s*(\d+)/i);
|
|
209
|
+
if (!match) {
|
|
210
|
+
console.error("Malformed header: missing Content-Length");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const contentLength = parseInt(match[1], 10);
|
|
214
|
+
const bodyStart = headerEnd + 4;
|
|
215
|
+
if (buffer.length < bodyStart + contentLength)
|
|
216
|
+
return; // incomplete body
|
|
217
|
+
const body = buffer.slice(bodyStart, bodyStart + contentLength);
|
|
218
|
+
buffer = buffer.slice(bodyStart + contentLength); // consume
|
|
219
|
+
let request;
|
|
220
|
+
try {
|
|
221
|
+
request = JSON.parse(body);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
console.error("Malformed JSON body");
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
handleRequest(request);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Main entry point
|
|
232
|
+
*/
|
|
233
|
+
async function main() {
|
|
234
|
+
setOptionValues();
|
|
235
|
+
validateOptions();
|
|
236
|
+
createBasePath();
|
|
237
|
+
writeStream = fs.createWriteStream(getTodaysLogFile(), { flags: "a" });
|
|
238
|
+
process.stdin.on("data", (chunk) => {
|
|
239
|
+
buffer += chunk;
|
|
240
|
+
parseBuffer();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
main();
|
|
244
|
+
//# sourceMappingURL=node_process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node_process.js","sourceRoot":"","sources":["../src/node_process.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAGH,yBAA0B;AAC1B,6BAA8B;AAE9B;;GAEG;AACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,GAA6B;IACxC,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;CACrC,CAAC;AAEF;;GAEG;AACH,IAAI,MAAM,GAAG,EAAE,CAAC;AAEhB;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACH,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB;;GAEG;AACH,IAAI,KAAK,GAAa,EAAE,CAAC;AAEzB;;GAEG;AACH,IAAI,KAAK,GAA0B,IAAI,CAAC;AAExC;;GAEG;AACH,IAAI,WAAW,GAA0B,IAAI,CAAC;AAE9C;;;GAGG;AACH,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AG,SAAS,GAAG,CAAC,CAAC;QAEhC,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,aAAa;YAAE,OAAO,CAAC,kBAAkB;QAEzE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC;QAChE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,UAAU;QAE5D,IAAI,OAAiC,CAAC;QACtC,IAAI,CAAC;YACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,aAAa,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,eAAe,EAAE,CAAC;IAClB,eAAe,EAAE,CAAC;IAClB,cAAc,EAAE,CAAC;IAEjB,WAAW,GAAG,EAAE,CAAC,iBAAiB,CAAC,gBAAgB,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAEvE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC;QAChB,WAAW,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of methods / actions that the node_process can perform
|
|
3
|
+
*/
|
|
4
|
+
export type RequestMethod = "log" | "reload" | "flush";
|
|
5
|
+
/**
|
|
6
|
+
* Represents the shape of data sent to the node_process
|
|
7
|
+
*/
|
|
8
|
+
export type NodeProcessRequest = {
|
|
9
|
+
id: number;
|
|
10
|
+
method: RequestMethod;
|
|
11
|
+
data: any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Response shape
|
|
15
|
+
*/
|
|
16
|
+
export type NodeProcessResponse = {
|
|
17
|
+
id: number;
|
|
18
|
+
method: RequestMethod;
|
|
19
|
+
success: boolean;
|
|
20
|
+
error: any;
|
|
21
|
+
message: any;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Options for node_process mapped from CLI args
|
|
25
|
+
*/
|
|
26
|
+
export type NodeProcessOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* The base path that points to the directory we will write the log files to
|
|
29
|
+
*/
|
|
30
|
+
basePath: string;
|
|
31
|
+
/**
|
|
32
|
+
* The time the process started as a string in UTC time
|
|
33
|
+
*/
|
|
34
|
+
startedUtc: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Indicates which level of log should be used
|
|
38
|
+
*/
|
|
39
|
+
export type LogLevel = "WARN" | "INFO" | "ERROR";
|
|
40
|
+
/**
|
|
41
|
+
* List of options you can pass to change the logger behaviour
|
|
42
|
+
*/
|
|
43
|
+
export type NodeLoggerOptions = {
|
|
44
|
+
/**
|
|
45
|
+
* Indicates if stdout console output produced by this logger should be saved to log files (defaults to `true`)
|
|
46
|
+
*/
|
|
47
|
+
saveToLogFile: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The base path / path to the folder to save the log outputs to (defaults to `./logs`) then is converted to an absolute path internally
|
|
50
|
+
*/
|
|
51
|
+
logFilesBasePath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Indicates if it should add the time of when the log was made for a given log item (defaults to `true`)
|
|
54
|
+
*/
|
|
55
|
+
showLogTime: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Indicates if it should use colored console outputs (defaults to `true`)
|
|
58
|
+
*/
|
|
59
|
+
useAnsiColors: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Mapped type: Each LogLevel must correspond to a string color value
|
|
62
|
+
*
|
|
63
|
+
* (default)
|
|
64
|
+
* ```js
|
|
65
|
+
* colorMap: {
|
|
66
|
+
INFO: "\x1b[32m", // Green
|
|
67
|
+
WARN: "\x1b[33m", // Yellow
|
|
68
|
+
ERROR: "\x1b[31m", // Red
|
|
69
|
+
},
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
colorMap: {
|
|
73
|
+
[key in LogLevel]: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE;SACP,GAAG,IAAI,QAAQ,GAAG,MAAM;KAC1B,CAAC;CACH,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-logy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A lightweight Node.js logging utility that outputs logs to the console and writes them to rotating log files. Supports different log levels, timestamps, and customizable formatting for production-ready applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"files": [
|
|
27
27
|
"README.md",
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"License"
|
|
29
30
|
],
|
|
30
31
|
"homepage": "https://github.com/UmbrellaCrow612/node-logger?tab=readme-ov-file#node-logger",
|
|
31
32
|
"repository": {
|