node-logy 0.0.1
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/README.md +65 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +366 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Node logger
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm i node-logger
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
A lightweight logger for node js to print to console and also save them to log files auto rotating
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# Example
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
let logger = new NodeLogger();
|
|
15
|
+
|
|
16
|
+
logger.info("Hello world", "more", 123);
|
|
17
|
+
logger.warn("Hello world");
|
|
18
|
+
logger.error(new Error("Yo"), "some other");
|
|
19
|
+
|
|
20
|
+
process.on("exit", () => {
|
|
21
|
+
logger.flushLogsSync();
|
|
22
|
+
console.log("finished");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
[Fri, 23 Jan 2026 14:57:23 GMT] [INFO] Hello world more 123
|
|
30
|
+
[Fri, 23 Jan 2026 14:57:23 GMT] [WARN] Hello world
|
|
31
|
+
[Fri, 23 Jan 2026 14:57:23 GMT] [ERROR] Name: Error
|
|
32
|
+
Message: Yo
|
|
33
|
+
Stack: Error: Yo
|
|
34
|
+
at Object.<anonymous> (C:\dev\node-logger\src\test.ts:7:14)
|
|
35
|
+
at Module._compile (node:internal/modules/cjs/loader:1730:14)
|
|
36
|
+
at Module.m._compile (C:\dev\node-logger\node_modules\ts-node\src\index.ts:1618:23)
|
|
37
|
+
at node:internal/modules/cjs/loader:1895:10
|
|
38
|
+
at Object.require.extensions.<computed> [as .ts] (C:\dev\node-logger\node_modules\ts-node\src\index.ts:1621:12)
|
|
39
|
+
at Module.load (node:internal/modules/cjs/loader:1465:32)
|
|
40
|
+
at Function._load (node:internal/modules/cjs/loader:1282:12)
|
|
41
|
+
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
|
|
42
|
+
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
|
|
43
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5) some other
|
|
44
|
+
finished
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
log file:
|
|
48
|
+
|
|
49
|
+
```log
|
|
50
|
+
Fri, 23 Jan 2026 14:54:17 GMT INFO Hello world more 123
|
|
51
|
+
Fri, 23 Jan 2026 14:54:17 GMT WARN Hello world
|
|
52
|
+
Fri, 23 Jan 2026 14:54:17 GMT ERROR Name: Error
|
|
53
|
+
Message: Yo
|
|
54
|
+
Stack: Error: Yo
|
|
55
|
+
at Object.<anonymous> (C:\dev\node-logger\src\test.ts:7:14)
|
|
56
|
+
at Module._compile (node:internal/modules/cjs/loader:1730:14)
|
|
57
|
+
at Module.m._compile (C:\dev\node-logger\node_modules\ts-node\src\index.ts:1618:23)
|
|
58
|
+
at node:internal/modules/cjs/loader:1895:10
|
|
59
|
+
at Object.require.extensions.<computed> [as .ts] (C:\dev\node-logger\node_modules\ts-node\src\index.ts:1621:12)
|
|
60
|
+
at Module.load (node:internal/modules/cjs/loader:1465:32)
|
|
61
|
+
at Function._load (node:internal/modules/cjs/loader:1282:12)
|
|
62
|
+
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
|
|
63
|
+
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
|
|
64
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5) some other
|
|
65
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Represents a logger used to log to node's stdout console and also save logs to log files.
|
|
28
|
+
* Uses some blocking at the beginning if you want to save output to log files
|
|
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.
|
|
31
|
+
*/
|
|
32
|
+
declare class NodeLogger {
|
|
33
|
+
/**
|
|
34
|
+
* Holds the options passed to the logger
|
|
35
|
+
*/
|
|
36
|
+
private _options;
|
|
37
|
+
/**
|
|
38
|
+
* Queue for log messages waiting to be written to file
|
|
39
|
+
*/
|
|
40
|
+
private _messageQueue;
|
|
41
|
+
/**
|
|
42
|
+
* How many messages we can hold before we start dropping old ones if we cannot write to log file
|
|
43
|
+
*/
|
|
44
|
+
private _maxQueueMessages;
|
|
45
|
+
/**
|
|
46
|
+
* Indicates if a write operation is currently in progress
|
|
47
|
+
*/
|
|
48
|
+
private _isWriting;
|
|
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;
|
|
54
|
+
/**
|
|
55
|
+
* Pass additional options on initialization to change the logger's behaviour
|
|
56
|
+
* @param options Change the behaviour of the logger
|
|
57
|
+
*/
|
|
58
|
+
constructor(options?: Partial<NodeLoggerOptions>);
|
|
59
|
+
/**
|
|
60
|
+
* Checks if 24 hours have passed since the last log cleanup.
|
|
61
|
+
*/
|
|
62
|
+
private shouldCleanOldLogs;
|
|
63
|
+
/**
|
|
64
|
+
* Log information
|
|
65
|
+
* @param level The specific level of log message
|
|
66
|
+
* @param content A message or error object or object
|
|
67
|
+
* @param contents Any other messages or error objects
|
|
68
|
+
*/
|
|
69
|
+
private log;
|
|
70
|
+
/**
|
|
71
|
+
* Logs an informational message to the console
|
|
72
|
+
* @param message The message to log
|
|
73
|
+
* @param messages Any other message objects or error objects
|
|
74
|
+
*/
|
|
75
|
+
info(message: unknown, ...messages: unknown[]): void;
|
|
76
|
+
/**
|
|
77
|
+
* Logs a warning message to the console
|
|
78
|
+
* @param message The message to log
|
|
79
|
+
* @param messages Any other message objects or error objects
|
|
80
|
+
*/
|
|
81
|
+
warn(message: unknown, ...messages: unknown[]): void;
|
|
82
|
+
/**
|
|
83
|
+
* Logs an error message to the console.
|
|
84
|
+
* It is recommended you pass the actual error object so we can print as much information as possible.
|
|
85
|
+
*
|
|
86
|
+
* For example:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* logger.error(new Error(""));
|
|
90
|
+
* ```
|
|
91
|
+
* @param messageOrError The error object or message to log
|
|
92
|
+
* @param messages Any other message objects or error objects
|
|
93
|
+
*/
|
|
94
|
+
error(messageOrError: unknown, ...messages: unknown[]): void;
|
|
95
|
+
/**
|
|
96
|
+
* Gets today's log file path.
|
|
97
|
+
* Because if it runs for 24 hours we need to recompute it each time
|
|
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.
|
|
114
|
+
*/
|
|
115
|
+
flushLogsSync(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Removes log files older than the retention period
|
|
118
|
+
*/
|
|
119
|
+
private cleanupOldLogFiles;
|
|
120
|
+
/**
|
|
121
|
+
* Extracts as much information as possible from an error or object and returns it as a string
|
|
122
|
+
* @param error The error object or any object to extract information from
|
|
123
|
+
* @returns A detailed string representation of the error/object
|
|
124
|
+
*/
|
|
125
|
+
private extractErrorInfo;
|
|
126
|
+
}
|
|
127
|
+
declare const _default: {
|
|
128
|
+
NodeLogger: typeof NodeLogger;
|
|
129
|
+
};
|
|
130
|
+
export = _default;
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4BA;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB;;OAEG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,4BAA4B,EAAE,MAAM,CAAC;IAErC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,cAAM,UAAU;IACd;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAoB;IAEpC;;OAEG;IACH,OAAO,CAAC,aAAa,CAAgB;IAErC;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAAO;IAEhC;;OAEG;IACH,OAAO,CAAC,UAAU,CAAkB;IAEpC;;;OAGG;IACH,OAAO,CAAC,sBAAsB,CAAuB;IAErD;;;OAGG;gBACS,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAkB;IAsEhE;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;OAKG;IACH,OAAO,CAAC,GAAG;IAsCX;;;;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;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAQ5B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;YACW,YAAY;IAuB1B;;;OAGG;IACI,aAAa;IAkBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAwFzB;;;;AAED,kBAEE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const nodeFs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
/**
|
|
5
|
+
* Holds default options for the logger
|
|
6
|
+
*/
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
logFileRetentionPeriodInDays: 30,
|
|
9
|
+
logFilesBasePath: "./logs",
|
|
10
|
+
saveToLogFile: true,
|
|
11
|
+
showLogTime: true,
|
|
12
|
+
useColoredOutput: true,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Holds specific log levels and their colors to be printed in
|
|
16
|
+
*/
|
|
17
|
+
const colorMap = {
|
|
18
|
+
INFO: "\x1b[34m",
|
|
19
|
+
WARN: "\x1b[33m",
|
|
20
|
+
ERROR: "\x1b[31m",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Represents a logger used to log to node's stdout console and also save logs to log files.
|
|
24
|
+
* Uses some blocking at the beginning if you want to save output to log files
|
|
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.
|
|
27
|
+
*/
|
|
28
|
+
class NodeLogger {
|
|
29
|
+
/**
|
|
30
|
+
* Holds the options passed to the logger
|
|
31
|
+
*/
|
|
32
|
+
_options;
|
|
33
|
+
/**
|
|
34
|
+
* Queue for log messages waiting to be written to file
|
|
35
|
+
*/
|
|
36
|
+
_messageQueue = [];
|
|
37
|
+
/**
|
|
38
|
+
* How many messages we can hold before we start dropping old ones if we cannot write to log file
|
|
39
|
+
*/
|
|
40
|
+
_maxQueueMessages = 500;
|
|
41
|
+
/**
|
|
42
|
+
* Indicates if a write operation is currently in progress
|
|
43
|
+
*/
|
|
44
|
+
_isWriting = false;
|
|
45
|
+
/**
|
|
46
|
+
* Indicates when the last clean happened; should be every 24 hours.
|
|
47
|
+
* Holds a UTC string of when it last happened.
|
|
48
|
+
*/
|
|
49
|
+
_lastCleanedOldLogsUtc = null;
|
|
50
|
+
/**
|
|
51
|
+
* Pass additional options on initialization to change the logger's behaviour
|
|
52
|
+
* @param options Change the behaviour of the logger
|
|
53
|
+
*/
|
|
54
|
+
constructor(options = defaultOptions) {
|
|
55
|
+
this._options = { ...defaultOptions, ...options };
|
|
56
|
+
if (typeof this._options !== "object") {
|
|
57
|
+
throw new TypeError("Options passed cannot be null or undefined; it must be an object");
|
|
58
|
+
}
|
|
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
|
+
if (typeof this._options.logFilesBasePath !== "string" ||
|
|
65
|
+
(typeof this._options.logFilesBasePath === "string" &&
|
|
66
|
+
this._options.logFilesBasePath.trim() === "")) {
|
|
67
|
+
throw new TypeError("logFilesBasePath must be a non-empty string");
|
|
68
|
+
}
|
|
69
|
+
if (typeof this._options.saveToLogFile !== "boolean") {
|
|
70
|
+
throw new TypeError("saveToLogFile must be a boolean");
|
|
71
|
+
}
|
|
72
|
+
if (typeof this._options.showLogTime !== "boolean") {
|
|
73
|
+
throw new TypeError("showLogTime must be a boolean");
|
|
74
|
+
}
|
|
75
|
+
if (typeof this._options.useColoredOutput !== "boolean") {
|
|
76
|
+
throw new TypeError("useColoredOutput must be a boolean");
|
|
77
|
+
}
|
|
78
|
+
this._options.logFilesBasePath = path.resolve(this._options.logFilesBasePath);
|
|
79
|
+
try {
|
|
80
|
+
if (this._options.saveToLogFile &&
|
|
81
|
+
!nodeFs.existsSync(this._options.logFilesBasePath)) {
|
|
82
|
+
nodeFs.mkdirSync(this._options.logFilesBasePath, { recursive: true });
|
|
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();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(`Failed to initialize logger error: ${this.extractErrorInfo(error)}`);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks if 24 hours have passed since the last log cleanup.
|
|
101
|
+
*/
|
|
102
|
+
shouldCleanOldLogs() {
|
|
103
|
+
if (!this._lastCleanedOldLogsUtc) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
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
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Log information
|
|
113
|
+
* @param level The specific level of log message
|
|
114
|
+
* @param content A message or error object or object
|
|
115
|
+
* @param contents Any other messages or error objects
|
|
116
|
+
*/
|
|
117
|
+
log(level, content, ...contents) {
|
|
118
|
+
const now = new Date();
|
|
119
|
+
const logParts = [];
|
|
120
|
+
if (this._options.showLogTime) {
|
|
121
|
+
const timestamp = now.toUTCString();
|
|
122
|
+
logParts.push(`[${timestamp}]`);
|
|
123
|
+
}
|
|
124
|
+
const levelStr = this._options.useColoredOutput
|
|
125
|
+
? `${colorMap[level]}${level}\x1b[0m`
|
|
126
|
+
: level;
|
|
127
|
+
logParts.push(`[${levelStr}]`);
|
|
128
|
+
let message = `${this.extractErrorInfo(content)}`;
|
|
129
|
+
contents.forEach((m) => {
|
|
130
|
+
message += ` ${this.extractErrorInfo(m)}`;
|
|
131
|
+
});
|
|
132
|
+
logParts.push(message);
|
|
133
|
+
const fullConsoleMessage = logParts.join(" ");
|
|
134
|
+
if (level === "ERROR")
|
|
135
|
+
console.error(fullConsoleMessage);
|
|
136
|
+
else if (level === "WARN")
|
|
137
|
+
console.warn(fullConsoleMessage);
|
|
138
|
+
else
|
|
139
|
+
console.log(fullConsoleMessage);
|
|
140
|
+
if (this._options.saveToLogFile) {
|
|
141
|
+
if (this.shouldCleanOldLogs()) {
|
|
142
|
+
this.cleanupOldLogFiles();
|
|
143
|
+
this._lastCleanedOldLogsUtc = new Date().toUTCString();
|
|
144
|
+
}
|
|
145
|
+
const fileTime = this._options.showLogTime ? now.toUTCString() : "";
|
|
146
|
+
this.enqueMessage(`${fileTime} ${level} ${message}`.trim());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Logs an informational message to the console
|
|
151
|
+
* @param message The message to log
|
|
152
|
+
* @param messages Any other message objects or error objects
|
|
153
|
+
*/
|
|
154
|
+
info(message, ...messages) {
|
|
155
|
+
this.log("INFO", message, ...messages);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Logs a warning message to the console
|
|
159
|
+
* @param message The message to log
|
|
160
|
+
* @param messages Any other message objects or error objects
|
|
161
|
+
*/
|
|
162
|
+
warn(message, ...messages) {
|
|
163
|
+
this.log("WARN", message, ...messages);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Logs an error message to the console.
|
|
167
|
+
* It is recommended you pass the actual error object so we can print as much information as possible.
|
|
168
|
+
*
|
|
169
|
+
* For example:
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* logger.error(new Error(""));
|
|
173
|
+
* ```
|
|
174
|
+
* @param messageOrError The error object or message to log
|
|
175
|
+
* @param messages Any other message objects or error objects
|
|
176
|
+
*/
|
|
177
|
+
error(messageOrError, ...messages) {
|
|
178
|
+
this.log("ERROR", messageOrError, ...messages);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets today's log file path.
|
|
182
|
+
* Because if it runs for 24 hours we need to recompute it each time
|
|
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`
|
|
185
|
+
*/
|
|
186
|
+
getTodaysLogFilePath() {
|
|
187
|
+
const date = new Date().toISOString().split("T")[0];
|
|
188
|
+
return path.normalize(path.join(this._options.logFilesBasePath, `${date}.log`));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Enqueues the log message to be asynchronously added to the log file
|
|
192
|
+
* @param message The message to add to the log file
|
|
193
|
+
*/
|
|
194
|
+
enqueMessage(message) {
|
|
195
|
+
if (this._messageQueue.length >= this._maxQueueMessages) {
|
|
196
|
+
this._messageQueue.shift();
|
|
197
|
+
}
|
|
198
|
+
this._messageQueue.push(message);
|
|
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);
|
|
210
|
+
try {
|
|
211
|
+
const content = messages.join("\n") + "\n";
|
|
212
|
+
await nodeFs.promises.appendFile(this.getTodaysLogFilePath(), content, {
|
|
213
|
+
encoding: "utf8",
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
console.error(`Failed to write logs to file: ${this.extractErrorInfo(error)}`);
|
|
218
|
+
this._messageQueue.unshift(...messages);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
this._isWriting = false;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Synchronously flushes all remaining logs in the queue to the log file.
|
|
226
|
+
* Used during process exit to ensure no logs are lost.
|
|
227
|
+
*/
|
|
228
|
+
flushLogsSync() {
|
|
229
|
+
if (this._messageQueue.length === 0) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
const content = this._messageQueue.join("\n") + "\n";
|
|
234
|
+
nodeFs.appendFileSync(this.getTodaysLogFilePath(), content, {
|
|
235
|
+
encoding: "utf8",
|
|
236
|
+
});
|
|
237
|
+
this._messageQueue = [];
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error(`Failed to flush logs on exit: ${this.extractErrorInfo(error)}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Removes log files older than the retention period
|
|
245
|
+
*/
|
|
246
|
+
cleanupOldLogFiles() {
|
|
247
|
+
try {
|
|
248
|
+
const files = nodeFs.readdirSync(this._options.logFilesBasePath);
|
|
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
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error(`Cleanup failed: ${this.extractErrorInfo(error)}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Extracts as much information as possible from an error or object and returns it as a string
|
|
270
|
+
* @param error The error object or any object to extract information from
|
|
271
|
+
* @returns A detailed string representation of the error/object
|
|
272
|
+
*/
|
|
273
|
+
extractErrorInfo(error) {
|
|
274
|
+
const parts = [];
|
|
275
|
+
if (error === null)
|
|
276
|
+
return "null";
|
|
277
|
+
if (error === undefined)
|
|
278
|
+
return "undefined";
|
|
279
|
+
if (typeof error !== "object") {
|
|
280
|
+
return String(error);
|
|
281
|
+
}
|
|
282
|
+
if (error instanceof Error) {
|
|
283
|
+
if (error.name)
|
|
284
|
+
parts.push(`Name: ${error.name}`);
|
|
285
|
+
if (error.message)
|
|
286
|
+
parts.push(`Message: ${error.message}`);
|
|
287
|
+
if (error.stack) {
|
|
288
|
+
parts.push(`Stack: ${error.stack}`);
|
|
289
|
+
}
|
|
290
|
+
const nodeError = error;
|
|
291
|
+
if (nodeError.code)
|
|
292
|
+
parts.push(`Code: ${nodeError.code}`);
|
|
293
|
+
if (nodeError.errno)
|
|
294
|
+
parts.push(`Errno: ${nodeError.errno}`);
|
|
295
|
+
if (nodeError.syscall)
|
|
296
|
+
parts.push(`Syscall: ${nodeError.syscall}`);
|
|
297
|
+
if (nodeError.path)
|
|
298
|
+
parts.push(`Path: ${nodeError.path}`);
|
|
299
|
+
if (nodeError.port)
|
|
300
|
+
parts.push(`Port: ${nodeError.port}`);
|
|
301
|
+
if (nodeError.address)
|
|
302
|
+
parts.push(`Address: ${nodeError.address}`);
|
|
303
|
+
if (nodeError.dest)
|
|
304
|
+
parts.push(`Dest: ${nodeError.dest}`);
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const obj = error;
|
|
308
|
+
const keys = Object.keys(obj);
|
|
309
|
+
for (const key of keys) {
|
|
310
|
+
if (error instanceof Error &&
|
|
311
|
+
["name", "message", "stack"].includes(key)) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const value = obj[key];
|
|
316
|
+
if (value === null) {
|
|
317
|
+
parts.push(`${key}: null`);
|
|
318
|
+
}
|
|
319
|
+
else if (value === undefined) {
|
|
320
|
+
parts.push(`${key}: undefined`);
|
|
321
|
+
}
|
|
322
|
+
else if (typeof value === "function") {
|
|
323
|
+
parts.push(`${key}: [Function]`);
|
|
324
|
+
}
|
|
325
|
+
else if (typeof value === "object") {
|
|
326
|
+
try {
|
|
327
|
+
const stringified = JSON.stringify(value, null, 2);
|
|
328
|
+
parts.push(`${key}: ${stringified}`);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
parts.push(`${key}: [Object - could not stringify]`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
parts.push(`${key}: ${String(value)}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
parts.push(`${key}: [Could not access property]`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch { }
|
|
344
|
+
if (parts.length > 0) {
|
|
345
|
+
return parts.join("\n");
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
const obj = error;
|
|
349
|
+
if (typeof obj.toString === "function" &&
|
|
350
|
+
obj.toString !== Object.prototype.toString) {
|
|
351
|
+
return obj.toString();
|
|
352
|
+
}
|
|
353
|
+
if (typeof obj.toJSON === "function") {
|
|
354
|
+
return JSON.stringify(obj.toJSON(), null, 2);
|
|
355
|
+
}
|
|
356
|
+
return JSON.stringify(error, null, 2);
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
return "[Unable to extract error information]";
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
module.exports = {
|
|
364
|
+
NodeLogger,
|
|
365
|
+
};
|
|
366
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAmC;AACnC,kCAAmC;AAEnC;;GAEG;AACH,MAAM,cAAc,GAAsB;IACxC,4BAA4B,EAAE,EAAE;IAChC,gBAAgB,EAAE,QAAQ;IAC1B,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAA6B;IACzC,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;CAClB,CAAC;AAqCF;;;;;GAKG;AACH,MAAM,UAAU;IACd;;OAEG;IACK,QAAQ,CAAoB;IAEpC;;OAEG;IACK,aAAa,GAAa,EAAE,CAAC;IAErC;;OAEG;IACK,iBAAiB,GAAG,GAAG,CAAC;IAEhC;;OAEG;IACK,UAAU,GAAY,KAAK,CAAC;IAEpC;;;OAGG;IACK,sBAAsB,GAAkB,IAAI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;IACH,CAAC;CACF;AAED,iBAAS;IACP,UAAU;CACX,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-logy",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"node",
|
|
10
|
+
"nodejs",
|
|
11
|
+
"logger",
|
|
12
|
+
"logging",
|
|
13
|
+
"log",
|
|
14
|
+
"logfile",
|
|
15
|
+
"file-logging",
|
|
16
|
+
"console-logging",
|
|
17
|
+
"debug",
|
|
18
|
+
"info",
|
|
19
|
+
"warn",
|
|
20
|
+
"error",
|
|
21
|
+
"typescript",
|
|
22
|
+
"utility"
|
|
23
|
+
],
|
|
24
|
+
"author": "Yousaf Wazir",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"files": [
|
|
27
|
+
"README.md",
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.0.10",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|