@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 CHANGED
@@ -1,295 +1,225 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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
- * The log level.
22
- */ var ZLogLevel = /*#__PURE__*/ function(ZLogLevel) {
23
- /**
24
- * A fatal error.
25
- *
26
- * Someone's pager is going off at 2:00 in the
27
- * morning because the nuclear codes have gone off
28
- * and missiles have been launched.
29
- */ ZLogLevel[ZLogLevel["CATASTROPHE"] = 0] = "CATASTROPHE";
30
- /**
31
- * A normal error that cause usually be recovered from.
32
- *
33
- * May require a fire being put out or some immediate
34
- * response, but it is not world ending.
35
- */ ZLogLevel[ZLogLevel["ERROR"] = 1] = "ERROR";
36
- /**
37
- * Nothing is really wrong.
38
- *
39
- * Should probably not be ignored and
40
- * action should be taken, but it's not
41
- * serious enough to call the fire
42
- * department.
43
- */ ZLogLevel[ZLogLevel["WARNING"] = 2] = "WARNING";
44
- /**
45
- * Some information that's good to know.
46
- *
47
- * Analytic logs are in this zone and general
48
- * information goes in this zone. Debug as
49
- * well, goes into this zone.
50
- *
51
- * It is normally best to avoid this log level
52
- * unless it's really important to display.
53
- */ ZLogLevel[ZLogLevel["INFO"] = 3] = "INFO";
54
- return ZLogLevel;
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
- * Represents a builder for a log entry
58
- */ class ZLogEntryBuilder {
59
- /**
60
- * Sets the log level.
61
- *
62
- * @param level -
63
- * The log level.
64
- *
65
- * @returns
66
- * This object.
67
- */ level(level) {
68
- this._entry.level = level;
69
- return this;
70
- }
71
- /**
72
- * Sets the context of the entry.
73
- *
74
- * @param ctx -
75
- * The entry context.
76
- *
77
- * @returns
78
- * This object.
79
- */ context(ctx) {
80
- this._entry.context = ctx;
81
- return this;
82
- }
83
- /**
84
- * Sets the message.
85
- *
86
- * @param msg -
87
- * The message to log.
88
- *
89
- * @returns
90
- * This object.
91
- */ message(msg) {
92
- this._entry.message = msg;
93
- return this;
94
- }
95
- /**
96
- * Copies the other entry into the current entry.
97
- *
98
- * @param other -
99
- * The entry to copy.
100
- *
101
- * @returns
102
- * This object.
103
- */ copy(other) {
104
- this._entry = structuredClone(other);
105
- return this;
106
- }
107
- /**
108
- * Returns a copy of the built log entry.
109
- *
110
- * @returns
111
- * The built log entry.
112
- */ build() {
113
- return {
114
- ...this._entry
115
- };
116
- }
117
- /**
118
- * Initializes a new instance of this object.
119
- */ constructor(){
120
- _define_property$4(this, "_entry", void 0);
121
- /**
122
- * Sets the log level to catastrophe.
123
- *
124
- * @returns
125
- * This object.
126
- */ _define_property$4(this, "catastrophe", this.level.bind(this, 0));
127
- /**
128
- * Sets the log level to error.
129
- *
130
- * @returns
131
- * This object.
132
- */ _define_property$4(this, "error", this.level.bind(this, 1));
133
- /**
134
- * Sets the log level to warning.
135
- *
136
- * @returns
137
- * This object.
138
- */ _define_property$4(this, "warning", this.level.bind(this, 2));
139
- /**
140
- * Sets the log level to info.
141
- *
142
- * @returns
143
- * This object.
144
- */ _define_property$4(this, "info", this.level.bind(this, 3));
145
- this._entry = {
146
- level: 1,
147
- message: "",
148
- created: new Date().toJSON()
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
- * Represents a logger that logs to multiple sources.
168
- */ class ZLoggerComposite {
169
- /**
170
- * Logs the entry into every one of the child loggers.
171
- *
172
- * @param entry -
173
- * The entry to log.
174
- */ log(entry) {
175
- this._children.forEach((logger)=>logger.log(entry));
176
- }
177
- /**
178
- * Initializes a new instance of this object.
179
- *
180
- * @param _children -
181
- * The collection of child loggers to log to.
182
- */ constructor(_children){
183
- _define_property$3(this, "_children", void 0);
184
- this._children = _children;
185
- }
186
- }
187
-
188
- function _define_property$2(obj, key, value) {
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
- * Represents a logger that logs to the console.
203
- */ class ZLoggerConsole {
204
- /**
205
- * Logs the entry to the console.
206
- *
207
- * @param entry -
208
- * The entry to log.
209
- */ log(entry) {
210
- const fn = this._logFnMap[entry.level] || ((msg)=>this._console.log(msg));
211
- const timestamp = `[${entry.created.toLocaleString()}]`;
212
- const payload = entry.level === ZLogLevel.CATASTROPHE ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;
213
- fn(`${timestamp}${payload}`);
214
- }
215
- /**
216
- * Initializes a new instance of this object.
217
- *
218
- * @param _console -
219
- * The console to log to.
220
- */ constructor(_console){
221
- _define_property$2(this, "_console", void 0);
222
- _define_property$2(this, "_logFnMap", void 0);
223
- this._console = _console;
224
- this._logFnMap = {
225
- [ZLogLevel.CATASTROPHE]: (msg)=>_console.error(msg),
226
- [ZLogLevel.ERROR]: (msg)=>_console.error(msg),
227
- [ZLogLevel.WARNING]: (msg)=>_console.warn(msg)
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
- * A logger that sets up a default context in the case that one is not given in the entry.
248
- */ class ZLoggerContext {
249
- log(entry) {
250
- const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
251
- return this._forward.log(clone);
252
- }
253
- /**
254
- * Initializes a new instance of this object.
255
- *
256
- * @param _context -
257
- * The default context if one is not provided in the entry.
258
- * @param _forward -
259
- * The logger to forward to.
260
- */ constructor(_context, _forward){
261
- _define_property$1(this, "_context", void 0);
262
- _define_property$1(this, "_forward", void 0);
263
- this._context = _context;
264
- this._forward = _forward;
265
- }
266
- }
267
-
268
- function _define_property(obj, key, value) {
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
- * A silent logger. This logger does nothing.
283
- */ class ZLoggerSilent {
284
- constructor(){
285
- _define_property(this, "log", lodashEs.noop);
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
- //# sourceMappingURL=index.cjs.map
224
+
225
+ //# sourceMappingURL=index.cjs.map
@@ -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,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,MA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,CAACD,SAAS,GAAG;YACf,CAAC7B,SAAAA,CAAUkC,WAAW,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,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,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;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 'lodash-es';
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
- * The log level.
18
- */ var ZLogLevel = /*#__PURE__*/ function(ZLogLevel) {
19
- /**
20
- * A fatal error.
21
- *
22
- * Someone's pager is going off at 2:00 in the
23
- * morning because the nuclear codes have gone off
24
- * and missiles have been launched.
25
- */ ZLogLevel[ZLogLevel["CATASTROPHE"] = 0] = "CATASTROPHE";
26
- /**
27
- * A normal error that cause usually be recovered from.
28
- *
29
- * May require a fire being put out or some immediate
30
- * response, but it is not world ending.
31
- */ ZLogLevel[ZLogLevel["ERROR"] = 1] = "ERROR";
32
- /**
33
- * Nothing is really wrong.
34
- *
35
- * Should probably not be ignored and
36
- * action should be taken, but it's not
37
- * serious enough to call the fire
38
- * department.
39
- */ ZLogLevel[ZLogLevel["WARNING"] = 2] = "WARNING";
40
- /**
41
- * Some information that's good to know.
42
- *
43
- * Analytic logs are in this zone and general
44
- * information goes in this zone. Debug as
45
- * well, goes into this zone.
46
- *
47
- * It is normally best to avoid this log level
48
- * unless it's really important to display.
49
- */ ZLogLevel[ZLogLevel["INFO"] = 3] = "INFO";
50
- return ZLogLevel;
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
- * Represents a builder for a log entry
54
- */ class ZLogEntryBuilder {
55
- /**
56
- * Sets the log level.
57
- *
58
- * @param level -
59
- * The log level.
60
- *
61
- * @returns
62
- * This object.
63
- */ level(level) {
64
- this._entry.level = level;
65
- return this;
66
- }
67
- /**
68
- * Sets the context of the entry.
69
- *
70
- * @param ctx -
71
- * The entry context.
72
- *
73
- * @returns
74
- * This object.
75
- */ context(ctx) {
76
- this._entry.context = ctx;
77
- return this;
78
- }
79
- /**
80
- * Sets the message.
81
- *
82
- * @param msg -
83
- * The message to log.
84
- *
85
- * @returns
86
- * This object.
87
- */ message(msg) {
88
- this._entry.message = msg;
89
- return this;
90
- }
91
- /**
92
- * Copies the other entry into the current entry.
93
- *
94
- * @param other -
95
- * The entry to copy.
96
- *
97
- * @returns
98
- * This object.
99
- */ copy(other) {
100
- this._entry = structuredClone(other);
101
- return this;
102
- }
103
- /**
104
- * Returns a copy of the built log entry.
105
- *
106
- * @returns
107
- * The built log entry.
108
- */ build() {
109
- return {
110
- ...this._entry
111
- };
112
- }
113
- /**
114
- * Initializes a new instance of this object.
115
- */ constructor(){
116
- _define_property$4(this, "_entry", void 0);
117
- /**
118
- * Sets the log level to catastrophe.
119
- *
120
- * @returns
121
- * This object.
122
- */ _define_property$4(this, "catastrophe", this.level.bind(this, 0));
123
- /**
124
- * Sets the log level to error.
125
- *
126
- * @returns
127
- * This object.
128
- */ _define_property$4(this, "error", this.level.bind(this, 1));
129
- /**
130
- * Sets the log level to warning.
131
- *
132
- * @returns
133
- * This object.
134
- */ _define_property$4(this, "warning", this.level.bind(this, 2));
135
- /**
136
- * Sets the log level to info.
137
- *
138
- * @returns
139
- * This object.
140
- */ _define_property$4(this, "info", this.level.bind(this, 3));
141
- this._entry = {
142
- level: 1,
143
- message: "",
144
- created: new Date().toJSON()
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
- * Represents a logger that logs to multiple sources.
164
- */ class ZLoggerComposite {
165
- /**
166
- * Logs the entry into every one of the child loggers.
167
- *
168
- * @param entry -
169
- * The entry to log.
170
- */ log(entry) {
171
- this._children.forEach((logger)=>logger.log(entry));
172
- }
173
- /**
174
- * Initializes a new instance of this object.
175
- *
176
- * @param _children -
177
- * The collection of child loggers to log to.
178
- */ constructor(_children){
179
- _define_property$3(this, "_children", void 0);
180
- this._children = _children;
181
- }
182
- }
183
-
184
- function _define_property$2(obj, key, value) {
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
- * Represents a logger that logs to the console.
199
- */ class ZLoggerConsole {
200
- /**
201
- * Logs the entry to the console.
202
- *
203
- * @param entry -
204
- * The entry to log.
205
- */ log(entry) {
206
- const fn = this._logFnMap[entry.level] || ((msg)=>this._console.log(msg));
207
- const timestamp = `[${entry.created.toLocaleString()}]`;
208
- const payload = entry.level === ZLogLevel.CATASTROPHE ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;
209
- fn(`${timestamp}${payload}`);
210
- }
211
- /**
212
- * Initializes a new instance of this object.
213
- *
214
- * @param _console -
215
- * The console to log to.
216
- */ constructor(_console){
217
- _define_property$2(this, "_console", void 0);
218
- _define_property$2(this, "_logFnMap", void 0);
219
- this._console = _console;
220
- this._logFnMap = {
221
- [ZLogLevel.CATASTROPHE]: (msg)=>_console.error(msg),
222
- [ZLogLevel.ERROR]: (msg)=>_console.error(msg),
223
- [ZLogLevel.WARNING]: (msg)=>_console.warn(msg)
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
- * A logger that sets up a default context in the case that one is not given in the entry.
244
- */ class ZLoggerContext {
245
- log(entry) {
246
- const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
247
- return this._forward.log(clone);
248
- }
249
- /**
250
- * Initializes a new instance of this object.
251
- *
252
- * @param _context -
253
- * The default context if one is not provided in the entry.
254
- * @param _forward -
255
- * The logger to forward to.
256
- */ constructor(_context, _forward){
257
- _define_property$1(this, "_context", void 0);
258
- _define_property$1(this, "_forward", void 0);
259
- this._context = _context;
260
- this._forward = _forward;
261
- }
262
- }
263
-
264
- function _define_property(obj, key, value) {
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
- * A silent logger. This logger does nothing.
279
- */ class ZLoggerSilent {
280
- constructor(){
281
- _define_property(this, "log", noop);
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
- //# sourceMappingURL=index.js.map
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,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D,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;;;;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/lumberjacky-log",
3
- "version": "4.0.4",
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": "^19.5.6",
38
- "@zthun/janitor-ts-config": "^19.5.3",
37
+ "@zthun/janitor-build-config": "^20.0.2",
38
+ "@zthun/janitor-ts-config": "^20.0.0",
39
39
  "typescript": "~5.9.3",
40
- "vite": "^7.3.1",
41
- "vitest": "^4.0.18",
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": "6360cc764970a138ea108e60f64167da51e21dbf"
48
+ "gitHead": "04c207e6dcd5a19938bda163d8b9c3bd4d92b87c"
49
49
  }