@zthun/lumberjacky-log 4.0.4 → 4.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/dist/index.cjs +212 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.js +211 -278
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,295 +1,225 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const lodashEs = require('lodash-es');
|
|
6
|
-
|
|
7
|
-
function _define_property$4(obj, key, value) {
|
|
8
|
-
if (key in obj) {
|
|
9
|
-
Object.defineProperty(obj, key, {
|
|
10
|
-
value: value,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true
|
|
14
|
-
});
|
|
15
|
-
} else {
|
|
16
|
-
obj[key] = value;
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let lodash_es = require("lodash-es");
|
|
3
|
+
//#region src/log-entry/log-entry.mts
|
|
20
4
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
5
|
+
* The log level.
|
|
6
|
+
*/ var ZLogLevel = /* @__PURE__ */ function(ZLogLevel) {
|
|
7
|
+
/**
|
|
8
|
+
* A fatal error.
|
|
9
|
+
*
|
|
10
|
+
* Someone's pager is going off at 2:00 in the
|
|
11
|
+
* morning because the nuclear codes have gone off
|
|
12
|
+
* and missiles have been launched.
|
|
13
|
+
*/ ZLogLevel[ZLogLevel["CATASTROPHE"] = 0] = "CATASTROPHE";
|
|
14
|
+
/**
|
|
15
|
+
* A normal error that cause usually be recovered from.
|
|
16
|
+
*
|
|
17
|
+
* May require a fire being put out or some immediate
|
|
18
|
+
* response, but it is not world ending.
|
|
19
|
+
*/ ZLogLevel[ZLogLevel["ERROR"] = 1] = "ERROR";
|
|
20
|
+
/**
|
|
21
|
+
* Nothing is really wrong.
|
|
22
|
+
*
|
|
23
|
+
* Should probably not be ignored and
|
|
24
|
+
* action should be taken, but it's not
|
|
25
|
+
* serious enough to call the fire
|
|
26
|
+
* department.
|
|
27
|
+
*/ ZLogLevel[ZLogLevel["WARNING"] = 2] = "WARNING";
|
|
28
|
+
/**
|
|
29
|
+
* Some information that's good to know.
|
|
30
|
+
*
|
|
31
|
+
* Analytic logs are in this zone and general
|
|
32
|
+
* information goes in this zone. Debug as
|
|
33
|
+
* well, goes into this zone.
|
|
34
|
+
*
|
|
35
|
+
* It is normally best to avoid this log level
|
|
36
|
+
* unless it's really important to display.
|
|
37
|
+
*/ ZLogLevel[ZLogLevel["INFO"] = 3] = "INFO";
|
|
38
|
+
return ZLogLevel;
|
|
55
39
|
}({});
|
|
56
40
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
function _define_property$3(obj, key, value) {
|
|
154
|
-
if (key in obj) {
|
|
155
|
-
Object.defineProperty(obj, key, {
|
|
156
|
-
value: value,
|
|
157
|
-
enumerable: true,
|
|
158
|
-
configurable: true,
|
|
159
|
-
writable: true
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
obj[key] = value;
|
|
163
|
-
}
|
|
164
|
-
return obj;
|
|
165
|
-
}
|
|
41
|
+
* Represents a builder for a log entry
|
|
42
|
+
*/ var ZLogEntryBuilder = class {
|
|
43
|
+
_entry;
|
|
44
|
+
/**
|
|
45
|
+
* Initializes a new instance of this object.
|
|
46
|
+
*/ constructor() {
|
|
47
|
+
this._entry = {
|
|
48
|
+
level: 1,
|
|
49
|
+
message: "",
|
|
50
|
+
created: (/* @__PURE__ */ new Date()).toJSON()
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets the log level.
|
|
55
|
+
*
|
|
56
|
+
* @param level -
|
|
57
|
+
* The log level.
|
|
58
|
+
*
|
|
59
|
+
* @returns
|
|
60
|
+
* This object.
|
|
61
|
+
*/ level(level) {
|
|
62
|
+
this._entry.level = level;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sets the log level to catastrophe.
|
|
67
|
+
*
|
|
68
|
+
* @returns
|
|
69
|
+
* This object.
|
|
70
|
+
*/ catastrophe = this.level.bind(this, 0);
|
|
71
|
+
/**
|
|
72
|
+
* Sets the log level to error.
|
|
73
|
+
*
|
|
74
|
+
* @returns
|
|
75
|
+
* This object.
|
|
76
|
+
*/ error = this.level.bind(this, 1);
|
|
77
|
+
/**
|
|
78
|
+
* Sets the log level to warning.
|
|
79
|
+
*
|
|
80
|
+
* @returns
|
|
81
|
+
* This object.
|
|
82
|
+
*/ warning = this.level.bind(this, 2);
|
|
83
|
+
/**
|
|
84
|
+
* Sets the log level to info.
|
|
85
|
+
*
|
|
86
|
+
* @returns
|
|
87
|
+
* This object.
|
|
88
|
+
*/ info = this.level.bind(this, 3);
|
|
89
|
+
/**
|
|
90
|
+
* Sets the context of the entry.
|
|
91
|
+
*
|
|
92
|
+
* @param ctx -
|
|
93
|
+
* The entry context.
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
* This object.
|
|
97
|
+
*/ context(ctx) {
|
|
98
|
+
this._entry.context = ctx;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sets the message.
|
|
103
|
+
*
|
|
104
|
+
* @param msg -
|
|
105
|
+
* The message to log.
|
|
106
|
+
*
|
|
107
|
+
* @returns
|
|
108
|
+
* This object.
|
|
109
|
+
*/ message(msg) {
|
|
110
|
+
this._entry.message = msg;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Copies the other entry into the current entry.
|
|
115
|
+
*
|
|
116
|
+
* @param other -
|
|
117
|
+
* The entry to copy.
|
|
118
|
+
*
|
|
119
|
+
* @returns
|
|
120
|
+
* This object.
|
|
121
|
+
*/ copy(other) {
|
|
122
|
+
this._entry = structuredClone(other);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns a copy of the built log entry.
|
|
127
|
+
*
|
|
128
|
+
* @returns
|
|
129
|
+
* The built log entry.
|
|
130
|
+
*/ build() {
|
|
131
|
+
return { ...this._entry };
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/logger/logger-composite.mts
|
|
166
136
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (key in obj) {
|
|
190
|
-
Object.defineProperty(obj, key, {
|
|
191
|
-
value: value,
|
|
192
|
-
enumerable: true,
|
|
193
|
-
configurable: true,
|
|
194
|
-
writable: true
|
|
195
|
-
});
|
|
196
|
-
} else {
|
|
197
|
-
obj[key] = value;
|
|
198
|
-
}
|
|
199
|
-
return obj;
|
|
200
|
-
}
|
|
137
|
+
* Represents a logger that logs to multiple sources.
|
|
138
|
+
*/ var ZLoggerComposite = class {
|
|
139
|
+
_children;
|
|
140
|
+
/**
|
|
141
|
+
* Initializes a new instance of this object.
|
|
142
|
+
*
|
|
143
|
+
* @param _children -
|
|
144
|
+
* The collection of child loggers to log to.
|
|
145
|
+
*/ constructor(_children) {
|
|
146
|
+
this._children = _children;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Logs the entry into every one of the child loggers.
|
|
150
|
+
*
|
|
151
|
+
* @param entry -
|
|
152
|
+
* The entry to log.
|
|
153
|
+
*/ log(entry) {
|
|
154
|
+
this._children.forEach((logger) => logger.log(entry));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/logger/logger-console.mts
|
|
201
159
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
_define_property$2(ZLoggerConsole, "FATAL", "!!FATAL!!");
|
|
232
|
-
|
|
233
|
-
function _define_property$1(obj, key, value) {
|
|
234
|
-
if (key in obj) {
|
|
235
|
-
Object.defineProperty(obj, key, {
|
|
236
|
-
value: value,
|
|
237
|
-
enumerable: true,
|
|
238
|
-
configurable: true,
|
|
239
|
-
writable: true
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
obj[key] = value;
|
|
243
|
-
}
|
|
244
|
-
return obj;
|
|
245
|
-
}
|
|
160
|
+
* Represents a logger that logs to the console.
|
|
161
|
+
*/ var ZLoggerConsole = class ZLoggerConsole {
|
|
162
|
+
_console;
|
|
163
|
+
static FATAL = "!!FATAL!!";
|
|
164
|
+
_logFnMap;
|
|
165
|
+
/**
|
|
166
|
+
* Initializes a new instance of this object.
|
|
167
|
+
*
|
|
168
|
+
* @param _console -
|
|
169
|
+
* The console to log to.
|
|
170
|
+
*/ constructor(_console) {
|
|
171
|
+
this._console = _console;
|
|
172
|
+
this._logFnMap = {
|
|
173
|
+
[ZLogLevel.CATASTROPHE]: (msg) => _console.error(msg),
|
|
174
|
+
[ZLogLevel.ERROR]: (msg) => _console.error(msg),
|
|
175
|
+
[ZLogLevel.WARNING]: (msg) => _console.warn(msg)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Logs the entry to the console.
|
|
180
|
+
*
|
|
181
|
+
* @param entry -
|
|
182
|
+
* The entry to log.
|
|
183
|
+
*/ log(entry) {
|
|
184
|
+
(this._logFnMap[entry.level] || ((msg) => this._console.log(msg)))(`${`[${entry.created.toLocaleString()}]`}${entry.level === ZLogLevel.CATASTROPHE ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`}`);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/logger/logger-context.mts
|
|
246
189
|
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (key in obj) {
|
|
270
|
-
Object.defineProperty(obj, key, {
|
|
271
|
-
value: value,
|
|
272
|
-
enumerable: true,
|
|
273
|
-
configurable: true,
|
|
274
|
-
writable: true
|
|
275
|
-
});
|
|
276
|
-
} else {
|
|
277
|
-
obj[key] = value;
|
|
278
|
-
}
|
|
279
|
-
return obj;
|
|
280
|
-
}
|
|
190
|
+
* A logger that sets up a default context in the case that one is not given in the entry.
|
|
191
|
+
*/ var ZLoggerContext = class {
|
|
192
|
+
_context;
|
|
193
|
+
_forward;
|
|
194
|
+
/**
|
|
195
|
+
* Initializes a new instance of this object.
|
|
196
|
+
*
|
|
197
|
+
* @param _context -
|
|
198
|
+
* The default context if one is not provided in the entry.
|
|
199
|
+
* @param _forward -
|
|
200
|
+
* The logger to forward to.
|
|
201
|
+
*/ constructor(_context, _forward) {
|
|
202
|
+
this._context = _context;
|
|
203
|
+
this._forward = _forward;
|
|
204
|
+
}
|
|
205
|
+
log(entry) {
|
|
206
|
+
const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
|
|
207
|
+
return this._forward.log(clone);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/logger/logger-silent.mts
|
|
281
212
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
213
|
+
* A silent logger. This logger does nothing.
|
|
214
|
+
*/ var ZLoggerSilent = class {
|
|
215
|
+
log = lodash_es.noop;
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
289
218
|
exports.ZLogEntryBuilder = ZLogEntryBuilder;
|
|
290
219
|
exports.ZLogLevel = ZLogLevel;
|
|
291
220
|
exports.ZLoggerComposite = ZLoggerComposite;
|
|
292
221
|
exports.ZLoggerConsole = ZLoggerConsole;
|
|
293
222
|
exports.ZLoggerContext = ZLoggerContext;
|
|
294
223
|
exports.ZLoggerSilent = ZLoggerSilent;
|
|
295
|
-
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/log-entry/log-entry.mts","../src/logger/logger-composite.mts","../src/logger/logger-console.mts","../src/logger/logger-context.mts","../src/logger/logger-silent.mts"],"sourcesContent":["/**\n * The log level.\n */\nexport enum ZLogLevel {\n /**\n * A fatal error.\n *\n * Someone's pager is going off at 2:00 in the\n * morning because the nuclear codes have gone off\n * and missiles have been launched.\n */\n CATASTROPHE = 0,\n\n /**\n * A normal error that cause usually be recovered from.\n *\n * May require a fire being put out or some immediate\n * response, but it is not world ending.\n */\n ERROR = 1,\n\n /**\n * Nothing is really wrong.\n *\n * Should probably not be ignored and\n * action should be taken, but it's not\n * serious enough to call the fire\n * department.\n */\n WARNING = 2,\n\n /**\n * Some information that's good to know.\n *\n * Analytic logs are in this zone and general\n * information goes in this zone. Debug as\n * well, goes into this zone.\n *\n * It is normally best to avoid this log level\n * unless it's really important to display.\n */\n INFO = 3,\n}\n\n/**\n * Represents a log entry.\n */\nexport interface IZLogEntry {\n /**\n * The log context.\n *\n * This will usually be a friendly name of a function\n * or class where this log took place.\n */\n context?: string;\n\n /**\n * The log level.\n */\n level: ZLogLevel;\n\n /**\n * The creation of this entry.\n */\n created: Date | string;\n\n /**\n * The log message.\n */\n message: string;\n}\n\n/**\n * Represents a builder for a log entry\n */\nexport class ZLogEntryBuilder {\n private _entry: IZLogEntry;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this._entry = {\n level: ZLogLevel.ERROR,\n message: \"\",\n created: new Date().toJSON(),\n };\n }\n\n /**\n * Sets the log level.\n *\n * @param level -\n * The log level.\n *\n * @returns\n * This object.\n */\n public level(level: ZLogLevel) {\n this._entry.level = level;\n return this;\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe = this.level.bind(this, ZLogLevel.CATASTROPHE);\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error = this.level.bind(this, ZLogLevel.ERROR);\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning = this.level.bind(this, ZLogLevel.WARNING);\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info = this.level.bind(this, ZLogLevel.INFO);\n\n /**\n * Sets the context of the entry.\n *\n * @param ctx -\n * The entry context.\n *\n * @returns\n * This object.\n */\n public context(ctx: string | undefined): this {\n this._entry.context = ctx;\n return this;\n }\n\n /**\n * Sets the message.\n *\n * @param msg -\n * The message to log.\n *\n * @returns\n * This object.\n */\n public message(msg: string): this {\n this._entry.message = msg;\n return this;\n }\n\n /**\n * Copies the other entry into the current entry.\n *\n * @param other -\n * The entry to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZLogEntry): this {\n this._entry = structuredClone(other);\n return this;\n }\n\n /**\n * Returns a copy of the built log entry.\n *\n * @returns\n * The built log entry.\n */\n public build(): IZLogEntry {\n return { ...this._entry };\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to multiple sources.\n */\nexport class ZLoggerComposite implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The collection of child loggers to log to.\n */\n public constructor(private readonly _children: IZLogger[]) {}\n\n /**\n * Logs the entry into every one of the child loggers.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n this._children.forEach((logger) => logger.log(entry));\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogLevel } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to the console.\n */\nexport class ZLoggerConsole implements IZLogger {\n public static readonly FATAL = \"!!FATAL!!\";\n private _logFnMap: any;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param _console -\n * The console to log to.\n */\n public constructor(private _console: Console) {\n this._logFnMap = {\n [ZLogLevel.CATASTROPHE]: (msg: string) => _console.error(msg),\n [ZLogLevel.ERROR]: (msg: string) => _console.error(msg),\n [ZLogLevel.WARNING]: (msg: string) => _console.warn(msg),\n };\n }\n\n /**\n * Logs the entry to the console.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n const fn =\n this._logFnMap[entry.level] || ((msg: string) => this._console.log(msg));\n\n const timestamp = `[${entry.created.toLocaleString()}]`;\n const payload =\n entry.level === ZLogLevel.CATASTROPHE\n ? `: ${ZLoggerConsole.FATAL} - ${entry.message}`\n : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogEntryBuilder } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A logger that sets up a default context in the case that one is not given in the entry.\n */\nexport class ZLoggerContext implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _context -\n * The default context if one is not provided in the entry.\n * @param _forward -\n * The logger to forward to.\n */\n public constructor(\n private _context: string,\n private _forward: IZLogger,\n ) {}\n\n public log(entry: IZLogEntry): void {\n const clone = new ZLogEntryBuilder()\n .copy(entry)\n .context(entry.context || this._context)\n .build();\n return this._forward.log(clone);\n }\n}\n","import { noop } from \"lodash-es\";\nimport type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A silent logger. This logger does nothing.\n */\nexport class ZLoggerSilent implements IZLogger {\n public log: (_: IZLogEntry) => void = noop;\n}\n"],"names":["ZLogLevel","ZLogEntryBuilder","level","_entry","context","ctx","message","msg","copy","other","structuredClone","build","_define_property","catastrophe","bind","error","warning","info","created","Date","toJSON","ZLoggerComposite","log","entry","_children","forEach","logger","ZLoggerConsole","fn","_logFnMap","_console","timestamp","toLocaleString","payload","CATASTROPHE","FATAL","ERROR","WARNING","warn","ZLoggerContext","clone","_context","_forward","ZLoggerSilent","noop"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;IAGO,IAAKA,SAAAA,iBAAAA,SAAAA,SAAAA,EAAAA;AACV;;;;;;AAMC,MAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,CAAA,CAAA,GAAA,aAAA;AAGD;;;;;AAKC,M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C,MACD,YACE,QAAwB,EAChBE,QAAkB,CAC1B;;;aAFQD,QAAAA,GAAAA,QAAAA;aACAC,QAAAA,GAAAA,QAAAA;AACP,IAAA;AASL;;;;;;;;;;;;;;;ACxBA;;AAEC,IACM,MAAMC,aAAAA,CAAAA;;AACX,QAAA,gBAAA,CAAA,IAAA,EAAOrB,KAAAA,EAA+BsB,aAAAA,CAAAA;;AACxC;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ZLogLevel","ZLogEntryBuilder","_entry","level","message","created","Date","toJSON","catastrophe","bind","error","warning","info","context","ctx","msg","copy","other","structuredClone","build","ZLoggerComposite","_children","log","entry","forEach","logger","ZLogLevel","ZLoggerConsole","FATAL","_logFnMap","_console","CATASTROPHE","msg","error","ERROR","WARNING","warn","log","entry","fn","level","timestamp","created","toLocaleString","payload","message","ZLogEntryBuilder","ZLoggerContext","_context","_forward","log","entry","clone","copy","context","build","noop","ZLoggerSilent","log"],"sources":["../src/log-entry/log-entry.mts","../src/logger/logger-composite.mts","../src/logger/logger-console.mts","../src/logger/logger-context.mts","../src/logger/logger-silent.mts"],"sourcesContent":["/**\n * The log level.\n */\nexport enum ZLogLevel {\n /**\n * A fatal error.\n *\n * Someone's pager is going off at 2:00 in the\n * morning because the nuclear codes have gone off\n * and missiles have been launched.\n */\n CATASTROPHE = 0,\n\n /**\n * A normal error that cause usually be recovered from.\n *\n * May require a fire being put out or some immediate\n * response, but it is not world ending.\n */\n ERROR = 1,\n\n /**\n * Nothing is really wrong.\n *\n * Should probably not be ignored and\n * action should be taken, but it's not\n * serious enough to call the fire\n * department.\n */\n WARNING = 2,\n\n /**\n * Some information that's good to know.\n *\n * Analytic logs are in this zone and general\n * information goes in this zone. Debug as\n * well, goes into this zone.\n *\n * It is normally best to avoid this log level\n * unless it's really important to display.\n */\n INFO = 3,\n}\n\n/**\n * Represents a log entry.\n */\nexport interface IZLogEntry {\n /**\n * The log context.\n *\n * This will usually be a friendly name of a function\n * or class where this log took place.\n */\n context?: string;\n\n /**\n * The log level.\n */\n level: ZLogLevel;\n\n /**\n * The creation of this entry.\n */\n created: Date | string;\n\n /**\n * The log message.\n */\n message: string;\n}\n\n/**\n * Represents a builder for a log entry\n */\nexport class ZLogEntryBuilder {\n private _entry: IZLogEntry;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this._entry = {\n level: ZLogLevel.ERROR,\n message: \"\",\n created: new Date().toJSON(),\n };\n }\n\n /**\n * Sets the log level.\n *\n * @param level -\n * The log level.\n *\n * @returns\n * This object.\n */\n public level(level: ZLogLevel) {\n this._entry.level = level;\n return this;\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe = this.level.bind(this, ZLogLevel.CATASTROPHE);\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error = this.level.bind(this, ZLogLevel.ERROR);\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning = this.level.bind(this, ZLogLevel.WARNING);\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info = this.level.bind(this, ZLogLevel.INFO);\n\n /**\n * Sets the context of the entry.\n *\n * @param ctx -\n * The entry context.\n *\n * @returns\n * This object.\n */\n public context(ctx: string | undefined): this {\n this._entry.context = ctx;\n return this;\n }\n\n /**\n * Sets the message.\n *\n * @param msg -\n * The message to log.\n *\n * @returns\n * This object.\n */\n public message(msg: string): this {\n this._entry.message = msg;\n return this;\n }\n\n /**\n * Copies the other entry into the current entry.\n *\n * @param other -\n * The entry to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZLogEntry): this {\n this._entry = structuredClone(other);\n return this;\n }\n\n /**\n * Returns a copy of the built log entry.\n *\n * @returns\n * The built log entry.\n */\n public build(): IZLogEntry {\n return { ...this._entry };\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to multiple sources.\n */\nexport class ZLoggerComposite implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The collection of child loggers to log to.\n */\n public constructor(private readonly _children: IZLogger[]) {}\n\n /**\n * Logs the entry into every one of the child loggers.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n this._children.forEach((logger) => logger.log(entry));\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogLevel } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to the console.\n */\nexport class ZLoggerConsole implements IZLogger {\n public static readonly FATAL = \"!!FATAL!!\";\n private _logFnMap: any;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param _console -\n * The console to log to.\n */\n public constructor(private _console: Console) {\n this._logFnMap = {\n [ZLogLevel.CATASTROPHE]: (msg: string) => _console.error(msg),\n [ZLogLevel.ERROR]: (msg: string) => _console.error(msg),\n [ZLogLevel.WARNING]: (msg: string) => _console.warn(msg),\n };\n }\n\n /**\n * Logs the entry to the console.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n const fn =\n this._logFnMap[entry.level] || ((msg: string) => this._console.log(msg));\n\n const timestamp = `[${entry.created.toLocaleString()}]`;\n const payload =\n entry.level === ZLogLevel.CATASTROPHE\n ? `: ${ZLoggerConsole.FATAL} - ${entry.message}`\n : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogEntryBuilder } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A logger that sets up a default context in the case that one is not given in the entry.\n */\nexport class ZLoggerContext implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _context -\n * The default context if one is not provided in the entry.\n * @param _forward -\n * The logger to forward to.\n */\n public constructor(\n private _context: string,\n private _forward: IZLogger,\n ) {}\n\n public log(entry: IZLogEntry): void {\n const clone = new ZLogEntryBuilder()\n .copy(entry)\n .context(entry.context || this._context)\n .build();\n return this._forward.log(clone);\n }\n}\n","import { noop } from \"lodash-es\";\n\nimport type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A silent logger. This logger does nothing.\n */\nexport class ZLoggerSilent implements IZLogger {\n public log: (_: IZLogEntry) => void = noop;\n}\n"],"mappings":";;;;;GAGA,IAAO,YAAKA,yBAAAA,WAAAA;;;;;;;GAOT,WAAA,UAAA,iBAAA,KAAA;;;;;;GAQA,WAAA,UAAA,WAAA,KAAA;;;;;;;;GAUA,WAAA,UAAA,aAAA,KAAA;;;;;;;;;;GAYA,WAAA,UAAA,UAAA,KAAA;QArCSA;;;;GAwEZ,IAAaC,mBAAb,MAAaA;CACHC;;;IAKR,cAAqB;AACnB,OAAKA,SAAS;GACZC,OAAK;GACLC,SAAS;GACTC,0BAAS,IAAIC,MAAAA,EAAOC,QAAM;GAC5B;;;;;;;;;;IAYF,MAAaJ,OAAkB;AAC7B,OAAKD,OAAOC,QAAQA;AACpB,SAAO;;;;;;;IAST,cAAqB,KAAKA,MAAMM,KAAK,MAAI,EAAA;;;;;;IAQzC,QAAe,KAAKN,MAAMM,KAAK,MAAI,EAAA;;;;;;IAQnC,UAAiB,KAAKN,MAAMM,KAAK,MAAI,EAAA;;;;;;IAQrC,OAAc,KAAKN,MAAMM,KAAK,MAAI,EAAA;;;;;;;;;IAWlC,QAAeK,KAA+B;AAC5C,OAAKZ,OAAOW,UAAUC;AACtB,SAAO;;;;;;;;;;IAYT,QAAeC,KAAmB;AAChC,OAAKb,OAAOE,UAAUW;AACtB,SAAO;;;;;;;;;;IAYT,KAAYE,OAAyB;AACnC,OAAKf,SAASgB,gBAAgBD,MAAAA;AAC9B,SAAO;;;;;;;IAST,QAA2B;AACzB,SAAO,EAAE,GAAG,KAAKf,QAAO;;;;;;;GClL5B,IAAakB,mBAAb,MAAaA;;;;;;;IAOX,YAAmB,WAAwC;OAAvBC,YAAAA;;;;;;;IAQpC,IAAWE,OAAyB;AAClC,OAAKF,UAAUG,SAASC,WAAWA,OAAOH,IAAIC,MAAAA,CAAAA;;;;;;;GCflD,IAAaI,iBAAb,MAAaA,eAAAA;;CACX,OAAuBC,QAAQ;CACvBC;;;;;;IAQR,YAAmB,UAA2B;OAAnBC,WAAAA;AACzB,OAAKD,YAAY;IACdH,UAAUK,eAAeC,QAAgBF,SAASG,MAAMD,IAAAA;IACxDN,UAAUQ,SAASF,QAAgBF,SAASG,MAAMD,IAAAA;IAClDN,UAAUS,WAAWH,QAAgBF,SAASM,KAAKJ,IAAAA;GACtD;;;;;;;IASF,IAAWM,OAAyB;AASlCC,GAPE,KAAKV,UAAUS,MAAME,YAAYR,QAAgB,KAAKF,SAASO,IAAIL,IAAG,GAOrE,GALe,IAAIM,MAAMI,QAAQC,gBAAc,CAAG,KAEnDL,MAAME,UAAUd,UAAUK,cACtB,KAAKJ,eAAeC,MAAM,KAAKU,MAAMO,YACrC,KAAKP,MAAMO,YACU;;;;;;;GCjC/B,IAAaE,iBAAb,MAAaA;;;;;;;;;;IASX,YACE,UACA,UACA;OAFQC,WAAAA;OACAC,WAAAA;;CAGHC,IAAIC,OAAyB;EAClC,MAAMC,QAAQ,IAAIN,kBAAAA,CACfO,KAAKF,MAAAA,CACLG,QAAQH,MAAMG,WAAW,KAAKN,SAAQ,CACtCO,OAAK;AACR,SAAO,KAAKN,SAASC,IAAIE,MAAAA;;;;;;;GClB7B,IAAaK,gBAAb,MAAaA;CACJC,MAA+BF,UAAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './log-entry/log-entry.mjs';
|
|
2
|
+
export * from './logger/logger.mjs';
|
|
2
3
|
export * from './logger/logger-composite.mjs';
|
|
3
4
|
export * from './logger/logger-console.mjs';
|
|
4
5
|
export * from './logger/logger-context.mjs';
|
|
5
6
|
export * from './logger/logger-silent.mjs';
|
|
6
|
-
export * from './logger/logger.mjs';
|
package/dist/index.js
CHANGED
|
@@ -1,286 +1,219 @@
|
|
|
1
|
-
import { noop } from
|
|
2
|
-
|
|
3
|
-
function _define_property$4(obj, key, value) {
|
|
4
|
-
if (key in obj) {
|
|
5
|
-
Object.defineProperty(obj, key, {
|
|
6
|
-
value: value,
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true
|
|
10
|
-
});
|
|
11
|
-
} else {
|
|
12
|
-
obj[key] = value;
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|
|
1
|
+
import { noop } from "lodash-es";
|
|
2
|
+
//#region src/log-entry/log-entry.mts
|
|
16
3
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
4
|
+
* The log level.
|
|
5
|
+
*/ var ZLogLevel = /* @__PURE__ */ function(ZLogLevel) {
|
|
6
|
+
/**
|
|
7
|
+
* A fatal error.
|
|
8
|
+
*
|
|
9
|
+
* Someone's pager is going off at 2:00 in the
|
|
10
|
+
* morning because the nuclear codes have gone off
|
|
11
|
+
* and missiles have been launched.
|
|
12
|
+
*/ ZLogLevel[ZLogLevel["CATASTROPHE"] = 0] = "CATASTROPHE";
|
|
13
|
+
/**
|
|
14
|
+
* A normal error that cause usually be recovered from.
|
|
15
|
+
*
|
|
16
|
+
* May require a fire being put out or some immediate
|
|
17
|
+
* response, but it is not world ending.
|
|
18
|
+
*/ ZLogLevel[ZLogLevel["ERROR"] = 1] = "ERROR";
|
|
19
|
+
/**
|
|
20
|
+
* Nothing is really wrong.
|
|
21
|
+
*
|
|
22
|
+
* Should probably not be ignored and
|
|
23
|
+
* action should be taken, but it's not
|
|
24
|
+
* serious enough to call the fire
|
|
25
|
+
* department.
|
|
26
|
+
*/ ZLogLevel[ZLogLevel["WARNING"] = 2] = "WARNING";
|
|
27
|
+
/**
|
|
28
|
+
* Some information that's good to know.
|
|
29
|
+
*
|
|
30
|
+
* Analytic logs are in this zone and general
|
|
31
|
+
* information goes in this zone. Debug as
|
|
32
|
+
* well, goes into this zone.
|
|
33
|
+
*
|
|
34
|
+
* It is normally best to avoid this log level
|
|
35
|
+
* unless it's really important to display.
|
|
36
|
+
*/ ZLogLevel[ZLogLevel["INFO"] = 3] = "INFO";
|
|
37
|
+
return ZLogLevel;
|
|
51
38
|
}({});
|
|
52
39
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
function _define_property$3(obj, key, value) {
|
|
150
|
-
if (key in obj) {
|
|
151
|
-
Object.defineProperty(obj, key, {
|
|
152
|
-
value: value,
|
|
153
|
-
enumerable: true,
|
|
154
|
-
configurable: true,
|
|
155
|
-
writable: true
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
obj[key] = value;
|
|
159
|
-
}
|
|
160
|
-
return obj;
|
|
161
|
-
}
|
|
40
|
+
* Represents a builder for a log entry
|
|
41
|
+
*/ var ZLogEntryBuilder = class {
|
|
42
|
+
_entry;
|
|
43
|
+
/**
|
|
44
|
+
* Initializes a new instance of this object.
|
|
45
|
+
*/ constructor() {
|
|
46
|
+
this._entry = {
|
|
47
|
+
level: 1,
|
|
48
|
+
message: "",
|
|
49
|
+
created: (/* @__PURE__ */ new Date()).toJSON()
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sets the log level.
|
|
54
|
+
*
|
|
55
|
+
* @param level -
|
|
56
|
+
* The log level.
|
|
57
|
+
*
|
|
58
|
+
* @returns
|
|
59
|
+
* This object.
|
|
60
|
+
*/ level(level) {
|
|
61
|
+
this._entry.level = level;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets the log level to catastrophe.
|
|
66
|
+
*
|
|
67
|
+
* @returns
|
|
68
|
+
* This object.
|
|
69
|
+
*/ catastrophe = this.level.bind(this, 0);
|
|
70
|
+
/**
|
|
71
|
+
* Sets the log level to error.
|
|
72
|
+
*
|
|
73
|
+
* @returns
|
|
74
|
+
* This object.
|
|
75
|
+
*/ error = this.level.bind(this, 1);
|
|
76
|
+
/**
|
|
77
|
+
* Sets the log level to warning.
|
|
78
|
+
*
|
|
79
|
+
* @returns
|
|
80
|
+
* This object.
|
|
81
|
+
*/ warning = this.level.bind(this, 2);
|
|
82
|
+
/**
|
|
83
|
+
* Sets the log level to info.
|
|
84
|
+
*
|
|
85
|
+
* @returns
|
|
86
|
+
* This object.
|
|
87
|
+
*/ info = this.level.bind(this, 3);
|
|
88
|
+
/**
|
|
89
|
+
* Sets the context of the entry.
|
|
90
|
+
*
|
|
91
|
+
* @param ctx -
|
|
92
|
+
* The entry context.
|
|
93
|
+
*
|
|
94
|
+
* @returns
|
|
95
|
+
* This object.
|
|
96
|
+
*/ context(ctx) {
|
|
97
|
+
this._entry.context = ctx;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sets the message.
|
|
102
|
+
*
|
|
103
|
+
* @param msg -
|
|
104
|
+
* The message to log.
|
|
105
|
+
*
|
|
106
|
+
* @returns
|
|
107
|
+
* This object.
|
|
108
|
+
*/ message(msg) {
|
|
109
|
+
this._entry.message = msg;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Copies the other entry into the current entry.
|
|
114
|
+
*
|
|
115
|
+
* @param other -
|
|
116
|
+
* The entry to copy.
|
|
117
|
+
*
|
|
118
|
+
* @returns
|
|
119
|
+
* This object.
|
|
120
|
+
*/ copy(other) {
|
|
121
|
+
this._entry = structuredClone(other);
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns a copy of the built log entry.
|
|
126
|
+
*
|
|
127
|
+
* @returns
|
|
128
|
+
* The built log entry.
|
|
129
|
+
*/ build() {
|
|
130
|
+
return { ...this._entry };
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/logger/logger-composite.mts
|
|
162
135
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (key in obj) {
|
|
186
|
-
Object.defineProperty(obj, key, {
|
|
187
|
-
value: value,
|
|
188
|
-
enumerable: true,
|
|
189
|
-
configurable: true,
|
|
190
|
-
writable: true
|
|
191
|
-
});
|
|
192
|
-
} else {
|
|
193
|
-
obj[key] = value;
|
|
194
|
-
}
|
|
195
|
-
return obj;
|
|
196
|
-
}
|
|
136
|
+
* Represents a logger that logs to multiple sources.
|
|
137
|
+
*/ var ZLoggerComposite = class {
|
|
138
|
+
_children;
|
|
139
|
+
/**
|
|
140
|
+
* Initializes a new instance of this object.
|
|
141
|
+
*
|
|
142
|
+
* @param _children -
|
|
143
|
+
* The collection of child loggers to log to.
|
|
144
|
+
*/ constructor(_children) {
|
|
145
|
+
this._children = _children;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Logs the entry into every one of the child loggers.
|
|
149
|
+
*
|
|
150
|
+
* @param entry -
|
|
151
|
+
* The entry to log.
|
|
152
|
+
*/ log(entry) {
|
|
153
|
+
this._children.forEach((logger) => logger.log(entry));
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/logger/logger-console.mts
|
|
197
158
|
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
_define_property$2(ZLoggerConsole, "FATAL", "!!FATAL!!");
|
|
228
|
-
|
|
229
|
-
function _define_property$1(obj, key, value) {
|
|
230
|
-
if (key in obj) {
|
|
231
|
-
Object.defineProperty(obj, key, {
|
|
232
|
-
value: value,
|
|
233
|
-
enumerable: true,
|
|
234
|
-
configurable: true,
|
|
235
|
-
writable: true
|
|
236
|
-
});
|
|
237
|
-
} else {
|
|
238
|
-
obj[key] = value;
|
|
239
|
-
}
|
|
240
|
-
return obj;
|
|
241
|
-
}
|
|
159
|
+
* Represents a logger that logs to the console.
|
|
160
|
+
*/ var ZLoggerConsole = class ZLoggerConsole {
|
|
161
|
+
_console;
|
|
162
|
+
static FATAL = "!!FATAL!!";
|
|
163
|
+
_logFnMap;
|
|
164
|
+
/**
|
|
165
|
+
* Initializes a new instance of this object.
|
|
166
|
+
*
|
|
167
|
+
* @param _console -
|
|
168
|
+
* The console to log to.
|
|
169
|
+
*/ constructor(_console) {
|
|
170
|
+
this._console = _console;
|
|
171
|
+
this._logFnMap = {
|
|
172
|
+
[ZLogLevel.CATASTROPHE]: (msg) => _console.error(msg),
|
|
173
|
+
[ZLogLevel.ERROR]: (msg) => _console.error(msg),
|
|
174
|
+
[ZLogLevel.WARNING]: (msg) => _console.warn(msg)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Logs the entry to the console.
|
|
179
|
+
*
|
|
180
|
+
* @param entry -
|
|
181
|
+
* The entry to log.
|
|
182
|
+
*/ log(entry) {
|
|
183
|
+
(this._logFnMap[entry.level] || ((msg) => this._console.log(msg)))(`${`[${entry.created.toLocaleString()}]`}${entry.level === ZLogLevel.CATASTROPHE ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`}`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/logger/logger-context.mts
|
|
242
188
|
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (key in obj) {
|
|
266
|
-
Object.defineProperty(obj, key, {
|
|
267
|
-
value: value,
|
|
268
|
-
enumerable: true,
|
|
269
|
-
configurable: true,
|
|
270
|
-
writable: true
|
|
271
|
-
});
|
|
272
|
-
} else {
|
|
273
|
-
obj[key] = value;
|
|
274
|
-
}
|
|
275
|
-
return obj;
|
|
276
|
-
}
|
|
189
|
+
* A logger that sets up a default context in the case that one is not given in the entry.
|
|
190
|
+
*/ var ZLoggerContext = class {
|
|
191
|
+
_context;
|
|
192
|
+
_forward;
|
|
193
|
+
/**
|
|
194
|
+
* Initializes a new instance of this object.
|
|
195
|
+
*
|
|
196
|
+
* @param _context -
|
|
197
|
+
* The default context if one is not provided in the entry.
|
|
198
|
+
* @param _forward -
|
|
199
|
+
* The logger to forward to.
|
|
200
|
+
*/ constructor(_context, _forward) {
|
|
201
|
+
this._context = _context;
|
|
202
|
+
this._forward = _forward;
|
|
203
|
+
}
|
|
204
|
+
log(entry) {
|
|
205
|
+
const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
|
|
206
|
+
return this._forward.log(clone);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/logger/logger-silent.mts
|
|
277
211
|
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
212
|
+
* A silent logger. This logger does nothing.
|
|
213
|
+
*/ var ZLoggerSilent = class {
|
|
214
|
+
log = noop;
|
|
215
|
+
};
|
|
216
|
+
//#endregion
|
|
285
217
|
export { ZLogEntryBuilder, ZLogLevel, ZLoggerComposite, ZLoggerConsole, ZLoggerContext, ZLoggerSilent };
|
|
286
|
-
|
|
218
|
+
|
|
219
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/log-entry/log-entry.mts","../src/logger/logger-composite.mts","../src/logger/logger-console.mts","../src/logger/logger-context.mts","../src/logger/logger-silent.mts"],"sourcesContent":["/**\n * The log level.\n */\nexport enum ZLogLevel {\n /**\n * A fatal error.\n *\n * Someone's pager is going off at 2:00 in the\n * morning because the nuclear codes have gone off\n * and missiles have been launched.\n */\n CATASTROPHE = 0,\n\n /**\n * A normal error that cause usually be recovered from.\n *\n * May require a fire being put out or some immediate\n * response, but it is not world ending.\n */\n ERROR = 1,\n\n /**\n * Nothing is really wrong.\n *\n * Should probably not be ignored and\n * action should be taken, but it's not\n * serious enough to call the fire\n * department.\n */\n WARNING = 2,\n\n /**\n * Some information that's good to know.\n *\n * Analytic logs are in this zone and general\n * information goes in this zone. Debug as\n * well, goes into this zone.\n *\n * It is normally best to avoid this log level\n * unless it's really important to display.\n */\n INFO = 3,\n}\n\n/**\n * Represents a log entry.\n */\nexport interface IZLogEntry {\n /**\n * The log context.\n *\n * This will usually be a friendly name of a function\n * or class where this log took place.\n */\n context?: string;\n\n /**\n * The log level.\n */\n level: ZLogLevel;\n\n /**\n * The creation of this entry.\n */\n created: Date | string;\n\n /**\n * The log message.\n */\n message: string;\n}\n\n/**\n * Represents a builder for a log entry\n */\nexport class ZLogEntryBuilder {\n private _entry: IZLogEntry;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this._entry = {\n level: ZLogLevel.ERROR,\n message: \"\",\n created: new Date().toJSON(),\n };\n }\n\n /**\n * Sets the log level.\n *\n * @param level -\n * The log level.\n *\n * @returns\n * This object.\n */\n public level(level: ZLogLevel) {\n this._entry.level = level;\n return this;\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe = this.level.bind(this, ZLogLevel.CATASTROPHE);\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error = this.level.bind(this, ZLogLevel.ERROR);\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning = this.level.bind(this, ZLogLevel.WARNING);\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info = this.level.bind(this, ZLogLevel.INFO);\n\n /**\n * Sets the context of the entry.\n *\n * @param ctx -\n * The entry context.\n *\n * @returns\n * This object.\n */\n public context(ctx: string | undefined): this {\n this._entry.context = ctx;\n return this;\n }\n\n /**\n * Sets the message.\n *\n * @param msg -\n * The message to log.\n *\n * @returns\n * This object.\n */\n public message(msg: string): this {\n this._entry.message = msg;\n return this;\n }\n\n /**\n * Copies the other entry into the current entry.\n *\n * @param other -\n * The entry to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZLogEntry): this {\n this._entry = structuredClone(other);\n return this;\n }\n\n /**\n * Returns a copy of the built log entry.\n *\n * @returns\n * The built log entry.\n */\n public build(): IZLogEntry {\n return { ...this._entry };\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to multiple sources.\n */\nexport class ZLoggerComposite implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The collection of child loggers to log to.\n */\n public constructor(private readonly _children: IZLogger[]) {}\n\n /**\n * Logs the entry into every one of the child loggers.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n this._children.forEach((logger) => logger.log(entry));\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogLevel } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to the console.\n */\nexport class ZLoggerConsole implements IZLogger {\n public static readonly FATAL = \"!!FATAL!!\";\n private _logFnMap: any;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param _console -\n * The console to log to.\n */\n public constructor(private _console: Console) {\n this._logFnMap = {\n [ZLogLevel.CATASTROPHE]: (msg: string) => _console.error(msg),\n [ZLogLevel.ERROR]: (msg: string) => _console.error(msg),\n [ZLogLevel.WARNING]: (msg: string) => _console.warn(msg),\n };\n }\n\n /**\n * Logs the entry to the console.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n const fn =\n this._logFnMap[entry.level] || ((msg: string) => this._console.log(msg));\n\n const timestamp = `[${entry.created.toLocaleString()}]`;\n const payload =\n entry.level === ZLogLevel.CATASTROPHE\n ? `: ${ZLoggerConsole.FATAL} - ${entry.message}`\n : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogEntryBuilder } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A logger that sets up a default context in the case that one is not given in the entry.\n */\nexport class ZLoggerContext implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _context -\n * The default context if one is not provided in the entry.\n * @param _forward -\n * The logger to forward to.\n */\n public constructor(\n private _context: string,\n private _forward: IZLogger,\n ) {}\n\n public log(entry: IZLogEntry): void {\n const clone = new ZLogEntryBuilder()\n .copy(entry)\n .context(entry.context || this._context)\n .build();\n return this._forward.log(clone);\n }\n}\n","import { noop } from \"lodash-es\";\nimport type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A silent logger. This logger does nothing.\n */\nexport class ZLoggerSilent implements IZLogger {\n public log: (_: IZLogEntry) => void = noop;\n}\n"],"names":["ZLogLevel","ZLogEntryBuilder","level","_entry","context","ctx","message","msg","copy","other","structuredClone","build","_define_property","catastrophe","bind","error","warning","info","created","Date","toJSON","ZLoggerComposite","log","entry","_children","forEach","logger","ZLoggerConsole","fn","_logFnMap","_console","timestamp","toLocaleString","payload","CATASTROPHE","FATAL","ERROR","WARNING","warn","ZLoggerContext","clone","_context","_forward","ZLoggerSilent","noop"],"mappings":";;;;;;;;;;;;;;;AAAA;;IAGO,IAAKA,SAAAA,iBAAAA,SAAAA,SAAAA,EAAAA;AACV;;;;;;AAMC,MAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,CAAA,CAAA,GAAA,aAAA;AAGD;;;;;AAKC,MAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAA;AAGD;;;;;;;AAOC,MAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAA;AAGD;;;;;;;;;AASC,MAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAA;AArCSA,IAAAA,OAAAA,SAAAA;AAuCX,CAAA,CAAA,EAAA;AA8BD;;AAEC,IACM,MAAMC,gBAAAA,CAAAA;AAcX;;;;;;;;MASOC,KAAAA,CAAMA,KAAgB,EAAE;AAC7B,QAAA,IAAI,CAACC,MAAM,CAACD,KAAK,GAAGA,KAAAA;AACpB,QAAA,OAAO,IAA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W,GAAG,CAAC3B,GAAAA,GAAgBuB,QAAAA,CAASf,KAAK,CAACR,GAAAA,CAAAA;YACzD,CAACP,SAAAA,CAAUoC,KAAK,GAAG,CAAC7B,GAAAA,GAAgBuB,QAAAA,CAASf,KAAK,CAACR,GAAAA,CAAAA;YACnD,CAACP,SAAAA,CAAUqC,OAAO,GAAG,CAAC9B,GAAAA,GAAgBuB,QAAAA,CAASQ,IAAI,CAAC/B,GAAAA;AACtD,SAAA;AACF,IAAA;AAmBF;AAlCEK,kBAAA,CADWe,gBACYQ,OAAAA,EAAQ,WAAA,CAAA;;;;;;;;;;;;;;;ACJjC;;AAEC,IACM,MAAMI,cAAAA,CAAAA;AAcJjB,IAAAA,GAAAA,CAAIC,KAAiB,EAAQ;AAClC,QAAA,MAAMiB,KAAAA,GAAQ,IAAIvC,gBAAAA,EAAAA,CACfO,IAAI,CAACe,KAAAA,CAAAA,CACLnB,OAAO,CAACmB,KAAAA,CAAMnB,OAAO,IAAI,IAAI,CAACqC,QAAQ,EACtC9B,KAAK,EAAA;AACR,QAAA,OAAO,IAAI,CAAC+B,QAAQ,CAACpB,GAAG,CAACkB,KAAAA,CAAAA;AAC3B,IAAA;AAnBA;;;;;;;AAOC,MACD,YACE,QAAwB,EAChBE,QAAkB,CAC1B;;;aAFQD,QAAAA,GAAAA,QAAAA;aACAC,QAAAA,GAAAA,QAAAA;AACP,IAAA;AASL;;;;;;;;;;;;;;;ACxBA;;AAEC,IACM,MAAMC,aAAAA,CAAAA;;AACX,QAAA,gBAAA,CAAA,IAAA,EAAOrB,KAAAA,EAA+BsB,IAAAA,CAAAA;;AACxC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["ZLogLevel","ZLogEntryBuilder","_entry","level","message","created","Date","toJSON","catastrophe","bind","error","warning","info","context","ctx","msg","copy","other","structuredClone","build","ZLoggerComposite","_children","log","entry","forEach","logger","ZLogLevel","ZLoggerConsole","FATAL","_logFnMap","_console","CATASTROPHE","msg","error","ERROR","WARNING","warn","log","entry","fn","level","timestamp","created","toLocaleString","payload","message","ZLogEntryBuilder","ZLoggerContext","_context","_forward","log","entry","clone","copy","context","build","noop","ZLoggerSilent","log"],"sources":["../src/log-entry/log-entry.mts","../src/logger/logger-composite.mts","../src/logger/logger-console.mts","../src/logger/logger-context.mts","../src/logger/logger-silent.mts"],"sourcesContent":["/**\n * The log level.\n */\nexport enum ZLogLevel {\n /**\n * A fatal error.\n *\n * Someone's pager is going off at 2:00 in the\n * morning because the nuclear codes have gone off\n * and missiles have been launched.\n */\n CATASTROPHE = 0,\n\n /**\n * A normal error that cause usually be recovered from.\n *\n * May require a fire being put out or some immediate\n * response, but it is not world ending.\n */\n ERROR = 1,\n\n /**\n * Nothing is really wrong.\n *\n * Should probably not be ignored and\n * action should be taken, but it's not\n * serious enough to call the fire\n * department.\n */\n WARNING = 2,\n\n /**\n * Some information that's good to know.\n *\n * Analytic logs are in this zone and general\n * information goes in this zone. Debug as\n * well, goes into this zone.\n *\n * It is normally best to avoid this log level\n * unless it's really important to display.\n */\n INFO = 3,\n}\n\n/**\n * Represents a log entry.\n */\nexport interface IZLogEntry {\n /**\n * The log context.\n *\n * This will usually be a friendly name of a function\n * or class where this log took place.\n */\n context?: string;\n\n /**\n * The log level.\n */\n level: ZLogLevel;\n\n /**\n * The creation of this entry.\n */\n created: Date | string;\n\n /**\n * The log message.\n */\n message: string;\n}\n\n/**\n * Represents a builder for a log entry\n */\nexport class ZLogEntryBuilder {\n private _entry: IZLogEntry;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this._entry = {\n level: ZLogLevel.ERROR,\n message: \"\",\n created: new Date().toJSON(),\n };\n }\n\n /**\n * Sets the log level.\n *\n * @param level -\n * The log level.\n *\n * @returns\n * This object.\n */\n public level(level: ZLogLevel) {\n this._entry.level = level;\n return this;\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe = this.level.bind(this, ZLogLevel.CATASTROPHE);\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error = this.level.bind(this, ZLogLevel.ERROR);\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning = this.level.bind(this, ZLogLevel.WARNING);\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info = this.level.bind(this, ZLogLevel.INFO);\n\n /**\n * Sets the context of the entry.\n *\n * @param ctx -\n * The entry context.\n *\n * @returns\n * This object.\n */\n public context(ctx: string | undefined): this {\n this._entry.context = ctx;\n return this;\n }\n\n /**\n * Sets the message.\n *\n * @param msg -\n * The message to log.\n *\n * @returns\n * This object.\n */\n public message(msg: string): this {\n this._entry.message = msg;\n return this;\n }\n\n /**\n * Copies the other entry into the current entry.\n *\n * @param other -\n * The entry to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZLogEntry): this {\n this._entry = structuredClone(other);\n return this;\n }\n\n /**\n * Returns a copy of the built log entry.\n *\n * @returns\n * The built log entry.\n */\n public build(): IZLogEntry {\n return { ...this._entry };\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to multiple sources.\n */\nexport class ZLoggerComposite implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The collection of child loggers to log to.\n */\n public constructor(private readonly _children: IZLogger[]) {}\n\n /**\n * Logs the entry into every one of the child loggers.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n this._children.forEach((logger) => logger.log(entry));\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogLevel } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * Represents a logger that logs to the console.\n */\nexport class ZLoggerConsole implements IZLogger {\n public static readonly FATAL = \"!!FATAL!!\";\n private _logFnMap: any;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param _console -\n * The console to log to.\n */\n public constructor(private _console: Console) {\n this._logFnMap = {\n [ZLogLevel.CATASTROPHE]: (msg: string) => _console.error(msg),\n [ZLogLevel.ERROR]: (msg: string) => _console.error(msg),\n [ZLogLevel.WARNING]: (msg: string) => _console.warn(msg),\n };\n }\n\n /**\n * Logs the entry to the console.\n *\n * @param entry -\n * The entry to log.\n */\n public log(entry: IZLogEntry): void {\n const fn =\n this._logFnMap[entry.level] || ((msg: string) => this._console.log(msg));\n\n const timestamp = `[${entry.created.toLocaleString()}]`;\n const payload =\n entry.level === ZLogLevel.CATASTROPHE\n ? `: ${ZLoggerConsole.FATAL} - ${entry.message}`\n : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport { ZLogEntryBuilder } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A logger that sets up a default context in the case that one is not given in the entry.\n */\nexport class ZLoggerContext implements IZLogger {\n /**\n * Initializes a new instance of this object.\n *\n * @param _context -\n * The default context if one is not provided in the entry.\n * @param _forward -\n * The logger to forward to.\n */\n public constructor(\n private _context: string,\n private _forward: IZLogger,\n ) {}\n\n public log(entry: IZLogEntry): void {\n const clone = new ZLogEntryBuilder()\n .copy(entry)\n .context(entry.context || this._context)\n .build();\n return this._forward.log(clone);\n }\n}\n","import { noop } from \"lodash-es\";\n\nimport type { IZLogEntry } from \"../log-entry/log-entry.mjs\";\nimport type { IZLogger } from \"./logger.mjs\";\n\n/**\n * A silent logger. This logger does nothing.\n */\nexport class ZLoggerSilent implements IZLogger {\n public log: (_: IZLogEntry) => void = noop;\n}\n"],"mappings":";;;;GAGA,IAAO,YAAKA,yBAAAA,WAAAA;;;;;;;GAOT,WAAA,UAAA,iBAAA,KAAA;;;;;;GAQA,WAAA,UAAA,WAAA,KAAA;;;;;;;;GAUA,WAAA,UAAA,aAAA,KAAA;;;;;;;;;;GAYA,WAAA,UAAA,UAAA,KAAA;QArCSA;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YAAYR,QAAgB,KAAKF,SAASO,IAAIL,IAAG,GAOrE,GALe,IAAIM,MAAMI,QAAQC,gBAAc,CAAG,KAEnDL,MAAME,UAAUd,UAAUK,cACtB,KAAKJ,eAAeC,MAAM,KAAKU,MAAMO,YACrC,KAAKP,MAAMO,YACU;;;;;;;GCjC/B,IAAaE,iBAAb,MAAaA;;;;;;;;;;IASX,YACE,UACA,UACA;OAFQC,WAAAA;OACAC,WAAAA;;CAGHC,IAAIC,OAAyB;EAClC,MAAMC,QAAQ,IAAIN,kBAAAA,CACfO,KAAKF,MAAAA,CACLG,QAAQH,MAAMG,WAAW,KAAKN,SAAQ,CACtCO,OAAK;AACR,SAAO,KAAKN,SAASC,IAAIE,MAAAA;;;;;;;GClB7B,IAAaK,gBAAb,MAAaA;CACJC,MAA+BF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/lumberjacky-log",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "A standard log interface between different logging standards.",
|
|
5
5
|
"author": "Anthony Bonta",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"lodash-es": "^4.17.23"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zthun/janitor-build-config": "^
|
|
38
|
-
"@zthun/janitor-ts-config": "^
|
|
37
|
+
"@zthun/janitor-build-config": "^20.0.2",
|
|
38
|
+
"@zthun/janitor-ts-config": "^20.0.0",
|
|
39
39
|
"typescript": "~5.9.3",
|
|
40
|
-
"vite": "^
|
|
41
|
-
"vitest": "^4.
|
|
40
|
+
"vite": "^8.0.3",
|
|
41
|
+
"vitest": "^4.1.2",
|
|
42
42
|
"vitest-mock-extended": "^3.1.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"dist"
|
|
46
46
|
],
|
|
47
47
|
"sideEffects": false,
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "04c207e6dcd5a19938bda163d8b9c3bd4d92b87c"
|
|
49
49
|
}
|