node-logy 0.1.0 → 0.1.2
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/logger.d.ts +256 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +688 -0
- package/dist/logger.js.map +1 -0
- package/dist/protocol.d.ts +286 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +414 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +257 -0
- package/dist/server.js.map +1 -0
- package/package.json +1 -1
- package/dist/index.d.ts +0 -99
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -363
- package/dist/index.js.map +0 -1
- package/dist/node_process.d.ts +0 -5
- package/dist/node_process.d.ts.map +0 -1
- package/dist/node_process.js +0 -245
- package/dist/node_process.js.map +0 -1
- package/dist/types.d.ts +0 -88
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { LogLevelType } from "./protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Timestamp format options
|
|
4
|
+
*/
|
|
5
|
+
export type TimestampType = "iso" | "locale" | "utc" | "unix" | "unix_ms" | "date" | "time" | "datetime" | "short" | "custom";
|
|
6
|
+
/**
|
|
7
|
+
* Options to change the logger
|
|
8
|
+
*/
|
|
9
|
+
export type LoggerOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Where to store the log files output
|
|
12
|
+
*/
|
|
13
|
+
basePath: string;
|
|
14
|
+
/**
|
|
15
|
+
* If this logger should save logs to log files
|
|
16
|
+
*/
|
|
17
|
+
saveToLogFiles: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* If this logger log's should be printed to the stdout of the process
|
|
20
|
+
*/
|
|
21
|
+
outputToConsole: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* If the output to console should be colored
|
|
24
|
+
*/
|
|
25
|
+
useColoredOutput: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Map of specific log level and what color to use
|
|
28
|
+
*/
|
|
29
|
+
colorMap: Record<LogLevelType, string>;
|
|
30
|
+
/**
|
|
31
|
+
* If it should add timestamps to logs
|
|
32
|
+
*/
|
|
33
|
+
showTimeStamps: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Which timestamp format to use (only applies when showTimeStamps is true)
|
|
36
|
+
*/
|
|
37
|
+
timestampType: TimestampType;
|
|
38
|
+
/**
|
|
39
|
+
* Custom timestamp format string (only used when timestampType is "custom")
|
|
40
|
+
* Use tokens: YYYY=year, MM=month, DD=day, HH=hour, mm=minute, ss=second, ms=millisecond
|
|
41
|
+
*/
|
|
42
|
+
customTimestampFormat?: string;
|
|
43
|
+
/**
|
|
44
|
+
* If it should show log level
|
|
45
|
+
*/
|
|
46
|
+
showLogLevel: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Map a specific log level with a string value use for it
|
|
49
|
+
*/
|
|
50
|
+
logLevelMap: Record<LogLevelType, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Minimum log level to process (filters out lower levels)
|
|
53
|
+
*/
|
|
54
|
+
minLevel?: LogLevelType;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum log level to process (filters out higher levels)
|
|
57
|
+
*/
|
|
58
|
+
maxLevel?: LogLevelType;
|
|
59
|
+
/**
|
|
60
|
+
* Specific levels to include (whitelist)
|
|
61
|
+
*/
|
|
62
|
+
includeLevels?: LogLevelType[];
|
|
63
|
+
/**
|
|
64
|
+
* Specific levels to exclude (blacklist)
|
|
65
|
+
*/
|
|
66
|
+
excludeLevels?: LogLevelType[];
|
|
67
|
+
/**
|
|
68
|
+
* Filter function to determine if a log should be processed
|
|
69
|
+
*/
|
|
70
|
+
filter?: (level: LogLevelType, message: any) => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Include process ID in logs
|
|
73
|
+
*/
|
|
74
|
+
showProcessId?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Include hostname in logs
|
|
77
|
+
*/
|
|
78
|
+
showHostname?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Include environment name (dev/prod) in logs
|
|
81
|
+
*/
|
|
82
|
+
environment?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Show where it was called at (file:line:column)
|
|
85
|
+
*/
|
|
86
|
+
showCallSite?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Custom error for logger initialization failures
|
|
90
|
+
*/
|
|
91
|
+
export declare class LoggerInitializationError extends Error {
|
|
92
|
+
constructor(message: string);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Used to log to console and also the log files
|
|
96
|
+
*/
|
|
97
|
+
export declare class Logger {
|
|
98
|
+
/**
|
|
99
|
+
* Local refrence to options passed
|
|
100
|
+
*/
|
|
101
|
+
private _options;
|
|
102
|
+
/**
|
|
103
|
+
* Holds the spawned side car process
|
|
104
|
+
*/
|
|
105
|
+
private _process;
|
|
106
|
+
/**
|
|
107
|
+
* Holds the process stdout buffer content
|
|
108
|
+
*/
|
|
109
|
+
private _processStdoutBuffer;
|
|
110
|
+
/**
|
|
111
|
+
* Used to encode request to / from binary protocol
|
|
112
|
+
*/
|
|
113
|
+
private _requestEncoder;
|
|
114
|
+
/**
|
|
115
|
+
* Used to encode responses to / from binary protocol
|
|
116
|
+
*/
|
|
117
|
+
private _responseEncoder;
|
|
118
|
+
/**
|
|
119
|
+
* A requests id
|
|
120
|
+
*/
|
|
121
|
+
private _id;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the next ID if it exceeds 1 million then rolls back to zero
|
|
124
|
+
*/
|
|
125
|
+
private _getNextId;
|
|
126
|
+
/**
|
|
127
|
+
* Holds pending requests that expect a response
|
|
128
|
+
*/
|
|
129
|
+
private _pending;
|
|
130
|
+
constructor(options?: Partial<LoggerOptions>);
|
|
131
|
+
/**
|
|
132
|
+
* Get the path to the server / sidecar
|
|
133
|
+
* @returns Path to the server
|
|
134
|
+
*/
|
|
135
|
+
private _getServerFilePath;
|
|
136
|
+
/**
|
|
137
|
+
* Inits the side car process
|
|
138
|
+
*/
|
|
139
|
+
private _initProcess;
|
|
140
|
+
/**
|
|
141
|
+
* Writes to the stdin of the process
|
|
142
|
+
*/
|
|
143
|
+
private _writeToStdin;
|
|
144
|
+
/**
|
|
145
|
+
* Clears pending requests on process exit/error
|
|
146
|
+
*/
|
|
147
|
+
private _clearPending;
|
|
148
|
+
/**
|
|
149
|
+
* Parses the stdout buffer produced by the spawned process
|
|
150
|
+
* Uses ResponseEncoder for all protocol operations
|
|
151
|
+
*/
|
|
152
|
+
private _parseProcessStdout;
|
|
153
|
+
/**
|
|
154
|
+
* Handle a decoded response
|
|
155
|
+
*/
|
|
156
|
+
private _handleResponse;
|
|
157
|
+
/**
|
|
158
|
+
* Resolve any pending requests that expected a response
|
|
159
|
+
* @param response The response
|
|
160
|
+
*/
|
|
161
|
+
private _resolvePending;
|
|
162
|
+
/**
|
|
163
|
+
* Send a request that expects a response to the sidecar process
|
|
164
|
+
* @param request The request to send that expects a response
|
|
165
|
+
*/
|
|
166
|
+
private _sendRequest;
|
|
167
|
+
/**
|
|
168
|
+
* Validates the basePath option
|
|
169
|
+
*/
|
|
170
|
+
private _validateBasePath;
|
|
171
|
+
/**
|
|
172
|
+
* Creates the log directory if file logging is enabled
|
|
173
|
+
*/
|
|
174
|
+
private _initializeDirectory;
|
|
175
|
+
/**
|
|
176
|
+
* Extract call site information (file:line:column) from stack trace
|
|
177
|
+
*/
|
|
178
|
+
private _getCallSite;
|
|
179
|
+
/**
|
|
180
|
+
* Check if a log level should be processed based on filtering rules
|
|
181
|
+
*/
|
|
182
|
+
private _shouldLog;
|
|
183
|
+
/**
|
|
184
|
+
* Verifies the log directory is writable
|
|
185
|
+
*/
|
|
186
|
+
private _verifyWritable;
|
|
187
|
+
/**
|
|
188
|
+
* Get the string representation of a log level
|
|
189
|
+
*/
|
|
190
|
+
private _getLevelString;
|
|
191
|
+
/**
|
|
192
|
+
* Format timestamp based on the configured timestampType
|
|
193
|
+
*/
|
|
194
|
+
private _formatTimestamp;
|
|
195
|
+
/**
|
|
196
|
+
* Apply custom format string to date
|
|
197
|
+
* Tokens: YYYY=year, MM=month, DD=day, HH=hour, mm=minute, ss=second, ms=millisecond
|
|
198
|
+
*/
|
|
199
|
+
private _applyCustomFormat;
|
|
200
|
+
/**
|
|
201
|
+
* Convert any value to string representation
|
|
202
|
+
*/
|
|
203
|
+
private _stringify;
|
|
204
|
+
/**
|
|
205
|
+
* Format a log message with optional fields
|
|
206
|
+
*/
|
|
207
|
+
private _formatMessage;
|
|
208
|
+
/**
|
|
209
|
+
* Apply color to the entire message if colored output is enabled
|
|
210
|
+
*/
|
|
211
|
+
private _colorize;
|
|
212
|
+
/**
|
|
213
|
+
* Log a specific level and content
|
|
214
|
+
* @param level The specific level to log
|
|
215
|
+
* @param message The content of the message
|
|
216
|
+
* @param messages Any addtional messages
|
|
217
|
+
*/
|
|
218
|
+
log(level: LogLevelType, message: any, ...messages: any[]): void;
|
|
219
|
+
/**
|
|
220
|
+
* Convenience method for INFO level
|
|
221
|
+
*/
|
|
222
|
+
info(message: any, ...messages: any[]): void;
|
|
223
|
+
/**
|
|
224
|
+
* Convenience method for WARN level
|
|
225
|
+
*/
|
|
226
|
+
warn(message: any, ...messages: any[]): void;
|
|
227
|
+
/**
|
|
228
|
+
* Convenience method for ERROR level
|
|
229
|
+
*/
|
|
230
|
+
error(message: any, ...messages: any[]): void;
|
|
231
|
+
/**
|
|
232
|
+
* Convenience method for DEBUG level
|
|
233
|
+
*/
|
|
234
|
+
debug(message: any, ...messages: any[]): void;
|
|
235
|
+
/**
|
|
236
|
+
* Convenience method for FATAL level
|
|
237
|
+
*/
|
|
238
|
+
fatal(message: any, ...messages: any[]): void;
|
|
239
|
+
/**
|
|
240
|
+
* Flush remaning buffer to log files
|
|
241
|
+
*/
|
|
242
|
+
flush(): Promise<void>;
|
|
243
|
+
/**
|
|
244
|
+
* Used to reload / refresh the process
|
|
245
|
+
*/
|
|
246
|
+
reload(): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* Used to shut down the child process and clean up
|
|
249
|
+
*/
|
|
250
|
+
shutdown(): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Get current logger options (read-only copy)
|
|
253
|
+
*/
|
|
254
|
+
get options(): Readonly<LoggerOptions>;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAMb,MAAM,YAAY,CAAC;AAIpB;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,QAAQ,GACR,KAAK,GACL,MAAM,GACN,SAAS,GACT,MAAM,GACN,MAAM,GACN,UAAU,GACV,OAAO,GACP,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,aAAa,EAAE,aAAa,CAAC;IAE7B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAE1C;;OAEG;IACH,QAAQ,CAAC,EAAE,YAAY,C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