@zthun/lumberjacky-log 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Lumberjacky Log
2
+
3
+ This is the root log framework that includes the interfaces and cross framework loggers that can be used without the
4
+ need of any framework.
5
+
6
+ ## Usage
7
+
8
+ ```sh
9
+ npm install @zthun/lumberjacky-log
10
+ yarn add @zthun/lumberjacky-log
11
+ ```
12
+
13
+ There are 3 loggers that are added in this package that are given to you by default.
14
+
15
+ | Logger | Description |
16
+ | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
17
+ | Console | Basic console logger that uses the lumberjacky interface |
18
+ | Composite | Composite logger that logs to multiple sources |
19
+ | Silent | Silent logger used for unit tests |
20
+ | Context | Special logger that includes context information for logging. This is framework dependant. Basic console logging doesn't use this. |
package/dist/index.cjs ADDED
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const lodash = require("lodash");
4
+ var ZLogLevel = /* @__PURE__ */ ((ZLogLevel2) => {
5
+ ZLogLevel2[ZLogLevel2["CATASTROPHE"] = 0] = "CATASTROPHE";
6
+ ZLogLevel2[ZLogLevel2["ERROR"] = 1] = "ERROR";
7
+ ZLogLevel2[ZLogLevel2["WARNING"] = 2] = "WARNING";
8
+ ZLogLevel2[ZLogLevel2["INFO"] = 3] = "INFO";
9
+ return ZLogLevel2;
10
+ })(ZLogLevel || {});
11
+ class ZLogEntryBuilder {
12
+ /**
13
+ * Initializes a new instance of this object.
14
+ */
15
+ constructor() {
16
+ this.catastrophe = this.level.bind(
17
+ this,
18
+ 0
19
+ /* CATASTROPHE */
20
+ );
21
+ this.error = this.level.bind(
22
+ this,
23
+ 1
24
+ /* ERROR */
25
+ );
26
+ this.warning = this.level.bind(
27
+ this,
28
+ 2
29
+ /* WARNING */
30
+ );
31
+ this.info = this.level.bind(
32
+ this,
33
+ 3
34
+ /* INFO */
35
+ );
36
+ this._entry = {
37
+ level: 1,
38
+ message: "",
39
+ created: (/* @__PURE__ */ new Date()).toJSON()
40
+ };
41
+ }
42
+ /**
43
+ * Sets the log level.
44
+ *
45
+ * @param level -
46
+ * The log level.
47
+ *
48
+ * @returns
49
+ * This object.
50
+ */
51
+ level(level) {
52
+ this._entry.level = level;
53
+ return this;
54
+ }
55
+ /**
56
+ * Sets the context of the entry.
57
+ *
58
+ * @param ctx -
59
+ * The entry context.
60
+ *
61
+ * @returns
62
+ * This object.
63
+ */
64
+ context(ctx) {
65
+ this._entry.context = ctx;
66
+ return this;
67
+ }
68
+ /**
69
+ * Sets the message.
70
+ *
71
+ * @param msg -
72
+ * The message to log.
73
+ *
74
+ * @returns
75
+ * This object.
76
+ */
77
+ message(msg) {
78
+ this._entry.message = msg;
79
+ return this;
80
+ }
81
+ /**
82
+ * Copies the other entry into the current entry.
83
+ *
84
+ * @param other -
85
+ * The entry to copy.
86
+ *
87
+ * @returns
88
+ * This object.
89
+ */
90
+ copy(other) {
91
+ this._entry = structuredClone(other);
92
+ return this;
93
+ }
94
+ /**
95
+ * Returns a copy of the built log entry.
96
+ *
97
+ * @returns
98
+ * The built log entry.
99
+ */
100
+ build() {
101
+ return { ...this._entry };
102
+ }
103
+ }
104
+ class ZLoggerComposite {
105
+ /**
106
+ * Initializes a new instance of this object.
107
+ *
108
+ * @param _children -
109
+ * The collection of child loggers to log to.
110
+ */
111
+ constructor(_children) {
112
+ this._children = _children;
113
+ }
114
+ /**
115
+ * Logs the entry into every one of the child loggers.
116
+ *
117
+ * @param entry -
118
+ * The entry to log.
119
+ */
120
+ log(entry) {
121
+ this._children.forEach((logger) => logger.log(entry));
122
+ }
123
+ }
124
+ const _ZLoggerConsole = class _ZLoggerConsole {
125
+ /**
126
+ * Initializes a new instance of this object.
127
+ *
128
+ * @param _console -
129
+ * The console to log to.
130
+ */
131
+ constructor(_console) {
132
+ this._console = _console;
133
+ this._logFnMap = {
134
+ [ZLogLevel.CATASTROPHE]: (msg) => _console.error(msg),
135
+ [ZLogLevel.ERROR]: (msg) => _console.error(msg),
136
+ [ZLogLevel.WARNING]: (msg) => _console.warn(msg)
137
+ };
138
+ }
139
+ /**
140
+ * Logs the entry to the console.
141
+ *
142
+ * @param entry -
143
+ * The entry to log.
144
+ */
145
+ log(entry) {
146
+ const fn = this._logFnMap[entry.level] || ((msg) => this._console.log(msg));
147
+ const timestamp = `[${entry.created.toLocaleString()}]`;
148
+ const payload = entry.level === ZLogLevel.CATASTROPHE ? `: ${_ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;
149
+ fn(`${timestamp}${payload}`);
150
+ }
151
+ };
152
+ _ZLoggerConsole.FATAL = "!!FATAL!!";
153
+ let ZLoggerConsole = _ZLoggerConsole;
154
+ class ZLoggerContext {
155
+ /**
156
+ * Initializes a new instance of this object.
157
+ *
158
+ * @param _context -
159
+ * The default context if one is not provided in the entry.
160
+ * @param _forward -
161
+ * The logger to forward to.
162
+ */
163
+ constructor(_context, _forward) {
164
+ this._context = _context;
165
+ this._forward = _forward;
166
+ }
167
+ log(entry) {
168
+ const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
169
+ return this._forward.log(clone);
170
+ }
171
+ }
172
+ class ZLoggerSilent {
173
+ constructor() {
174
+ this.log = lodash.noop;
175
+ }
176
+ }
177
+ exports.ZLogEntryBuilder = ZLogEntryBuilder;
178
+ exports.ZLogLevel = ZLogLevel;
179
+ exports.ZLoggerComposite = ZLoggerComposite;
180
+ exports.ZLoggerConsole = ZLoggerConsole;
181
+ exports.ZLoggerContext = ZLoggerContext;
182
+ exports.ZLoggerSilent = ZLoggerSilent;
183
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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 { IZLogEntry } from '../log-entry/log-entry.mjs';\nimport { 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 { IZLogEntry, ZLogLevel } from '../log-entry/log-entry.mjs';\nimport { 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 = 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 ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import { IZLogEntry, ZLogEntryBuilder } from '../log-entry/log-entry.mjs';\nimport { 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';\nimport { IZLogEntry } from '../log-entry/log-entry.mjs';\nimport { 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","noop"],"mappings":";;;AAGY,IAAA,8BAAAA,eAAL;AAQLA,aAAAA,WAAA,iBAAc,CAAd,IAAA;AAQAA,aAAAA,WAAA,WAAQ,CAAR,IAAA;AAUAA,aAAAA,WAAA,aAAU,CAAV,IAAA;AAYAA,aAAAA,WAAA,UAAO,CAAP,IAAA;AAtCUA,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;AAwEL,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAMrB,cAAc;AA4BrB,SAAO,cAAc,KAAK,MAAM;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA;AAQ3C,SAAO,QAAQ,KAAK,MAAM;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA;AAQrC,SAAO,UAAU,KAAK,MAAM;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA;AAQvC,SAAO,O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,SAAS,MAAM,GAAG;AAAA,MAC5D,CAAC,UAAU,KAAK,GAAG,CAAC,QAAgB,SAAS,MAAM,GAAG;AAAA,MACtD,CAAC,UAAU,OAAO,GAAG,CAAC,QAAgB,SAAS,KAAK,GAAG;AAAA,IAAA;AAAA,EAE3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAI,OAAyB;AAC5B,UAAA,KAAK,KAAK,UAAU,MAAM,KAAK,MAAM,CAAC,QAAgB,KAAK,SAAS,IAAI,GAAG;AAEjF,UAAM,YAAY,IAAI,MAAM,QAAQ,gBAAgB;AACpD,UAAM,UACJ,MAAM,UAAU,UAAU,cAAc,KAAK,gBAAe,KAAK,MAAM,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO;AAC7G,OAAG,GAAG,SAAS,GAAG,OAAO,EAAE;AAAA,EAC7B;AACF;AA/BE,gBAAuB,QAAQ;AAD1B,IAAM,iBAAN;ACAA,MAAM,eAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvC,YACG,UACA,UACR;AAFQ,SAAA,WAAA;AACA,SAAA,WAAA;AAAA,EACP;AAAA,EAEI,IAAI,OAAyB;AAClC,UAAM,QAAQ,IAAI,mBACf,KAAK,KAAK,EACV,QAAQ,MAAM,WAAW,KAAK,QAAQ,EACtC,MAAM;AACF,WAAA,KAAK,SAAS,IAAI,KAAK;AAAA,EAChC;AACF;ACpBO,MAAM,cAAkC;AAAA,EAAxC,cAAA;AACL,SAAO,MAA+BC;EAAA;AACxC;;;;;;;"}
@@ -0,0 +1,6 @@
1
+ export * from './log-entry/log-entry.mjs';
2
+ export * from './logger/logger-composite.mjs';
3
+ export * from './logger/logger-console.mjs';
4
+ export * from './logger/logger-context.mjs';
5
+ export * from './logger/logger-silent.mjs';
6
+ export * from './logger/logger.mjs';
package/dist/index.js ADDED
@@ -0,0 +1,183 @@
1
+ import { noop } from "lodash";
2
+ var ZLogLevel = /* @__PURE__ */ ((ZLogLevel2) => {
3
+ ZLogLevel2[ZLogLevel2["CATASTROPHE"] = 0] = "CATASTROPHE";
4
+ ZLogLevel2[ZLogLevel2["ERROR"] = 1] = "ERROR";
5
+ ZLogLevel2[ZLogLevel2["WARNING"] = 2] = "WARNING";
6
+ ZLogLevel2[ZLogLevel2["INFO"] = 3] = "INFO";
7
+ return ZLogLevel2;
8
+ })(ZLogLevel || {});
9
+ class ZLogEntryBuilder {
10
+ /**
11
+ * Initializes a new instance of this object.
12
+ */
13
+ constructor() {
14
+ this.catastrophe = this.level.bind(
15
+ this,
16
+ 0
17
+ /* CATASTROPHE */
18
+ );
19
+ this.error = this.level.bind(
20
+ this,
21
+ 1
22
+ /* ERROR */
23
+ );
24
+ this.warning = this.level.bind(
25
+ this,
26
+ 2
27
+ /* WARNING */
28
+ );
29
+ this.info = this.level.bind(
30
+ this,
31
+ 3
32
+ /* INFO */
33
+ );
34
+ this._entry = {
35
+ level: 1,
36
+ message: "",
37
+ created: (/* @__PURE__ */ new Date()).toJSON()
38
+ };
39
+ }
40
+ /**
41
+ * Sets the log level.
42
+ *
43
+ * @param level -
44
+ * The log level.
45
+ *
46
+ * @returns
47
+ * This object.
48
+ */
49
+ level(level) {
50
+ this._entry.level = level;
51
+ return this;
52
+ }
53
+ /**
54
+ * Sets the context of the entry.
55
+ *
56
+ * @param ctx -
57
+ * The entry context.
58
+ *
59
+ * @returns
60
+ * This object.
61
+ */
62
+ context(ctx) {
63
+ this._entry.context = ctx;
64
+ return this;
65
+ }
66
+ /**
67
+ * Sets the message.
68
+ *
69
+ * @param msg -
70
+ * The message to log.
71
+ *
72
+ * @returns
73
+ * This object.
74
+ */
75
+ message(msg) {
76
+ this._entry.message = msg;
77
+ return this;
78
+ }
79
+ /**
80
+ * Copies the other entry into the current entry.
81
+ *
82
+ * @param other -
83
+ * The entry to copy.
84
+ *
85
+ * @returns
86
+ * This object.
87
+ */
88
+ copy(other) {
89
+ this._entry = structuredClone(other);
90
+ return this;
91
+ }
92
+ /**
93
+ * Returns a copy of the built log entry.
94
+ *
95
+ * @returns
96
+ * The built log entry.
97
+ */
98
+ build() {
99
+ return { ...this._entry };
100
+ }
101
+ }
102
+ class ZLoggerComposite {
103
+ /**
104
+ * Initializes a new instance of this object.
105
+ *
106
+ * @param _children -
107
+ * The collection of child loggers to log to.
108
+ */
109
+ constructor(_children) {
110
+ this._children = _children;
111
+ }
112
+ /**
113
+ * Logs the entry into every one of the child loggers.
114
+ *
115
+ * @param entry -
116
+ * The entry to log.
117
+ */
118
+ log(entry) {
119
+ this._children.forEach((logger) => logger.log(entry));
120
+ }
121
+ }
122
+ const _ZLoggerConsole = class _ZLoggerConsole {
123
+ /**
124
+ * Initializes a new instance of this object.
125
+ *
126
+ * @param _console -
127
+ * The console to log to.
128
+ */
129
+ constructor(_console) {
130
+ this._console = _console;
131
+ this._logFnMap = {
132
+ [ZLogLevel.CATASTROPHE]: (msg) => _console.error(msg),
133
+ [ZLogLevel.ERROR]: (msg) => _console.error(msg),
134
+ [ZLogLevel.WARNING]: (msg) => _console.warn(msg)
135
+ };
136
+ }
137
+ /**
138
+ * Logs the entry to the console.
139
+ *
140
+ * @param entry -
141
+ * The entry to log.
142
+ */
143
+ log(entry) {
144
+ const fn = this._logFnMap[entry.level] || ((msg) => this._console.log(msg));
145
+ const timestamp = `[${entry.created.toLocaleString()}]`;
146
+ const payload = entry.level === ZLogLevel.CATASTROPHE ? `: ${_ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;
147
+ fn(`${timestamp}${payload}`);
148
+ }
149
+ };
150
+ _ZLoggerConsole.FATAL = "!!FATAL!!";
151
+ let ZLoggerConsole = _ZLoggerConsole;
152
+ class ZLoggerContext {
153
+ /**
154
+ * Initializes a new instance of this object.
155
+ *
156
+ * @param _context -
157
+ * The default context if one is not provided in the entry.
158
+ * @param _forward -
159
+ * The logger to forward to.
160
+ */
161
+ constructor(_context, _forward) {
162
+ this._context = _context;
163
+ this._forward = _forward;
164
+ }
165
+ log(entry) {
166
+ const clone = new ZLogEntryBuilder().copy(entry).context(entry.context || this._context).build();
167
+ return this._forward.log(clone);
168
+ }
169
+ }
170
+ class ZLoggerSilent {
171
+ constructor() {
172
+ this.log = noop;
173
+ }
174
+ }
175
+ export {
176
+ ZLogEntryBuilder,
177
+ ZLogLevel,
178
+ ZLoggerComposite,
179
+ ZLoggerConsole,
180
+ ZLoggerContext,
181
+ ZLoggerSilent
182
+ };
183
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 { IZLogEntry } from '../log-entry/log-entry.mjs';\nimport { 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 { IZLogEntry, ZLogLevel } from '../log-entry/log-entry.mjs';\nimport { 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 = 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 ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import { IZLogEntry, ZLogEntryBuilder } from '../log-entry/log-entry.mjs';\nimport { 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';\nimport { IZLogEntry } from '../log-entry/log-entry.mjs';\nimport { 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"],"mappings":";AAGY,IAAA,8BAAAA,eAAL;AAQLA,aAAAA,WAAA,iBAAc,CAAd,IAAA;AAQA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V,QAAQ,MAAM,WAAW,KAAK,QAAQ,EACtC,MAAM;AACF,WAAA,KAAK,SAAS,IAAI,KAAK;AAAA,EAChC;AACF;ACpBO,MAAM,cAAkC;AAAA,EAAxC,cAAA;AACL,SAAO,MAA+B;AAAA,EAAA;AACxC;"}
@@ -18,7 +18,7 @@ export declare enum ZLogLevel {
18
18
  */
19
19
  ERROR = 1,
20
20
  /**
21
- * Nothing is really totally wrong.
21
+ * Nothing is really wrong.
22
22
  *
23
23
  * Should probably not be ignored and
24
24
  * action should be taken, but it's not
@@ -1,5 +1,6 @@
1
- import { IZLogEntry } from '../log-entry/log-entry';
2
- import { IZLogger } from './logger';
1
+ import { IZLogEntry } from '../log-entry/log-entry.mjs';
2
+ import { IZLogger } from './logger.mjs';
3
+
3
4
  /**
4
5
  * Represents a logger that logs to multiple sources.
5
6
  */
@@ -1,5 +1,6 @@
1
- import { IZLogEntry } from '../log-entry/log-entry';
2
- import { IZLogger } from './logger';
1
+ import { IZLogEntry } from '../log-entry/log-entry.mjs';
2
+ import { IZLogger } from './logger.mjs';
3
+
3
4
  /**
4
5
  * Represents a logger that logs to the console.
5
6
  */
@@ -1,5 +1,6 @@
1
- import { IZLogEntry } from '../log-entry/log-entry';
2
- import { IZLogger } from './logger';
1
+ import { IZLogEntry } from '../log-entry/log-entry.mjs';
2
+ import { IZLogger } from './logger.mjs';
3
+
3
4
  /**
4
5
  * A logger that sets up a default context in the case that one is not given in the entry.
5
6
  */
@@ -1,5 +1,6 @@
1
- import { IZLogEntry } from '../log-entry/log-entry';
2
- import { IZLogger } from './logger';
1
+ import { IZLogEntry } from '../log-entry/log-entry.mjs';
2
+ import { IZLogger } from './logger.mjs';
3
+
3
4
  /**
4
5
  * A silent logger. This logger does nothing.
5
6
  */
@@ -1,9 +1,10 @@
1
- import { IZLogEntry } from '../log-entry/log-entry';
1
+ import { IZLogEntry } from '../log-entry/log-entry.mjs';
2
+
2
3
  /**
3
4
  * Represents a service that manages log entries.
4
5
  *
5
6
  * Logging is a fire and forget operation. If it fails,
6
- * you move on. Logging should never stop the operation of the
7
+ * you move on. Logging should never stop the operation of an
7
8
  * app.
8
9
  */
9
10
  export interface IZLogger {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/lumberjacky-log",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "description": "A standard log interface between different logging standards.",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -9,11 +9,23 @@
9
9
  "url": "https://github.com/zthun/lumberjacky",
10
10
  "directory": "packages/lumberjacky-log"
11
11
  },
12
- "main": "./dist/lib/index.js",
13
- "module": "./dist/lib/index.esm.js",
14
- "types": "./dist/types/index.d.ts",
12
+ "keywords": [
13
+ "lumberjacky",
14
+ "logging",
15
+ "log",
16
+ "console"
17
+ ],
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "type": "module",
22
+ "exports": {
23
+ "require": "./dist/index.cjs",
24
+ "import": "./dist/index.js",
25
+ "types": "./dist/index.d.ts"
26
+ },
15
27
  "scripts": {
16
- "build": "microbundle --format esm,cjs --tsconfig tsconfig.prod.json"
28
+ "build": "vite build"
17
29
  },
18
30
  "publishConfig": {
19
31
  "access": "public"
@@ -22,14 +34,14 @@
22
34
  "lodash": "^4.17.21"
23
35
  },
24
36
  "devDependencies": {
25
- "microbundle": "^0.15.1",
26
- "typescript": "^5.2.2",
27
- "vitest": "^0.34.4",
28
- "vitest-mock-extended": "^1.2.1"
37
+ "typescript": "^5.5.3",
38
+ "vite": "^5.3.4",
39
+ "vitest": "^2.0.4",
40
+ "vitest-mock-extended": "^1.3.2"
29
41
  },
30
42
  "files": [
31
43
  "dist"
32
44
  ],
33
45
  "sideEffects": false,
34
- "gitHead": "76cfa12ba3e64e4dac6f11190cec104a62ac3718"
46
+ "gitHead": "f9e7fc0542c1240bc3e81be84d187667fe967102"
35
47
  }
@@ -1,2 +0,0 @@
1
- import{noop as t}from"lodash";function n(){return n=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},n.apply(this,arguments)}var e;!function(t){t[t.CATASTROPHE=0]="CATASTROPHE",t[t.ERROR=1]="ERROR",t[t.WARNING=2]="WARNING",t[t.INFO=3]="INFO"}(e||(e={}));var r=/*#__PURE__*/function(){function t(){this._entry=void 0,this.catastrophe=this.level.bind(this,e.CATASTROPHE),this.error=this.level.bind(this,e.ERROR),this.warning=this.level.bind(this,e.WARNING),this.info=this.level.bind(this,e.INFO),this._entry={level:e.ERROR,message:"",created:(new Date).toJSON()}}var r=t.prototype;return r.level=function(t){return this._entry.level=t,this},r.context=function(t){return this._entry.context=t,this},r.message=function(t){return this._entry.message=t,this},r.copy=function(t){return this._entry=structuredClone(t),this},r.build=function(){return n({},this._entry)},t}(),i=/*#__PURE__*/function(){function t(t){this._children=void 0,this._children=t}return t.prototype.log=function(t){this._children.forEach(function(n){return n.log(t)})},t}(),o=/*#__PURE__*/function(){function t(t){var n;this._console=void 0,this._logFnMap=void 0,this._console=t,this._logFnMap=((n={})[e.CATASTROPHE]=function(n){return t.error(n)},n[e.ERROR]=function(n){return t.error(n)},n[e.WARNING]=function(n){return t.warn(n)},n)}return t.prototype.log=function(n){var r=this;(this._logFnMap[n.level]||function(t){return r._console.log(t)})("["+n.created.toLocaleString()+"]"+(n.level===e.CATASTROPHE?": "+t.FATAL+" - "+n.message:": "+n.message))},t}();o.FATAL="!!FATAL!!";var s=/*#__PURE__*/function(){function t(t,n){this._context=void 0,this._forward=void 0,this._context=t,this._forward=n}return t.prototype.log=function(t){var n=(new r).copy(t).context(t.context||this._context).build();return this._forward.log(n)},t}(),c=function(){this.log=t};export{r as ZLogEntryBuilder,e as ZLogLevel,i as ZLoggerComposite,o as ZLoggerConsole,s as ZLoggerContext,c as ZLoggerSilent};
2
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../src/log-entry/log-entry.ts","../../src/logger/logger-composite.ts","../../src/logger/logger-console.ts","../../src/logger/logger-context.ts","../../src/logger/logger-silent.ts"],"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 totally 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 { IZLogEntry } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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 { IZLogEntry, ZLogLevel } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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 = 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 ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import { IZLogEntry, ZLogEntryBuilder } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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';\nimport { IZLogEntry } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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","this","_entry","catastrophe","level","bind","CATASTROPHE","error","ERROR","warning","WARNING","info","INFO","message","created","Date","toJSON","_proto","prototype","context","ctx","msg","copy","other","structuredClone","build","_extends","ZLoggerComposite","_children","log","entry","forEach","logger","ZLoggerConsole","_console","_this$_logFnMap","_logFnMap","warn","_this","toLocaleString","FATAL","ZLoggerContext","_context","_forward","clone","ZLoggerSilent","noop"],"mappings":"kQAGY,IAAAA,GAAZ,SAAYA,GAQVA,EAAAA,EAAA,YAAA,GAAA,cAQAA,EAAAA,EAAA,MAAA,GAAA,QAUAA,EAAAA,EAAA,QAAA,GAAA,UAYAA,EAAAA,EAAA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A,CAAAA,GACXpC,EAAUO,aAAc,SAACe,GAAgB,OAAAa,EAAS3B,MAAMc,EAAI,EAAAc,EAC5DpC,EAAUS,OAAQ,SAACa,GAAgB,OAAAa,EAAS3B,MAAMc,EAAI,EAAAc,EACtDpC,EAAUW,SAAU,SAACW,GAAgB,OAAAa,EAASG,KAAKhB,EAAI,EAAAc,EAE5D,QAACF,EAAAf,UAQMW,IAAA,SAAIC,GAAiB,IAAAQ,EAC1BrC,MAAWA,KAAKmC,UAAUN,EAAM1B,QAAW,SAACiB,UAAgBiB,EAAKJ,SAASL,IAAIR,EAAI,OAE5DS,EAAMhB,QAAQyB,sBAElCT,EAAM1B,QAAUL,EAAUO,YAAmB2B,KAAAA,EAAeO,MAAK,MAAMV,EAAMjB,aAAiBiB,EAAMjB,SAExG,EAACoB,CAAA,CArBD,GAVWA,EACYO,MAAQ,YCDpB,IAAAC,eASX,WAAA,SAAAA,EACUC,EACAC,GAAkB1C,KADlByC,cACAC,EAAAA,KAAAA,gBADA1C,KAAQyC,SAARA,EACAzC,KAAQ0C,SAARA,CACP,QAACF,EAAAvB,UAEGW,IAAA,SAAIC,GACT,IAAMc,GAAQ,IAAI5C,GACfsB,KAAKQ,GACLX,QAAQW,EAAMX,SAAWlB,KAAKyC,UAC9BjB,QACH,YAAYkB,SAASd,IAAIe,EAC3B,EAACH,CAAA,CAXD,GCRWI,EAAa,WAAA5C,KACjB4B,IAA+BiB,CAAI"}
package/dist/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- var t,e=require("lodash");function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(t[r]=o[r])}return t},o.apply(this,arguments)}exports.ZLogLevel=void 0,(t=exports.ZLogLevel||(exports.ZLogLevel={}))[t.CATASTROPHE=0]="CATASTROPHE",t[t.ERROR=1]="ERROR",t[t.WARNING=2]="WARNING",t[t.INFO=3]="INFO";var r=/*#__PURE__*/function(){function t(){this._entry=void 0,this.catastrophe=this.level.bind(this,exports.ZLogLevel.CATASTROPHE),this.error=this.level.bind(this,exports.ZLogLevel.ERROR),this.warning=this.level.bind(this,exports.ZLogLevel.WARNING),this.info=this.level.bind(this,exports.ZLogLevel.INFO),this._entry={level:exports.ZLogLevel.ERROR,message:"",created:(new Date).toJSON()}}var e=t.prototype;return e.level=function(t){return this._entry.level=t,this},e.context=function(t){return this._entry.context=t,this},e.message=function(t){return this._entry.message=t,this},e.copy=function(t){return this._entry=structuredClone(t),this},e.build=function(){return o({},this._entry)},t}(),n=/*#__PURE__*/function(){function t(t){this._children=void 0,this._children=t}return t.prototype.log=function(t){this._children.forEach(function(e){return e.log(t)})},t}(),i=/*#__PURE__*/function(){function t(t){var e;this._console=void 0,this._logFnMap=void 0,this._console=t,this._logFnMap=((e={})[exports.ZLogLevel.CATASTROPHE]=function(e){return t.error(e)},e[exports.ZLogLevel.ERROR]=function(e){return t.error(e)},e[exports.ZLogLevel.WARNING]=function(e){return t.warn(e)},e)}return t.prototype.log=function(e){var o=this;(this._logFnMap[e.level]||function(t){return o._console.log(t)})("["+e.created.toLocaleString()+"]"+(e.level===exports.ZLogLevel.CATASTROPHE?": "+t.FATAL+" - "+e.message:": "+e.message))},t}();i.FATAL="!!FATAL!!";var s=/*#__PURE__*/function(){function t(t,e){this._context=void 0,this._forward=void 0,this._context=t,this._forward=e}return t.prototype.log=function(t){var e=(new r).copy(t).context(t.context||this._context).build();return this._forward.log(e)},t}();exports.ZLogEntryBuilder=r,exports.ZLoggerComposite=n,exports.ZLoggerConsole=i,exports.ZLoggerContext=s,exports.ZLoggerSilent=function(){this.log=e.noop};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/log-entry/log-entry.ts","../../src/logger/logger-composite.ts","../../src/logger/logger-console.ts","../../src/logger/logger-context.ts","../../src/logger/logger-silent.ts"],"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 totally 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 { IZLogEntry } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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 { IZLogEntry, ZLogLevel } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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 = 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 ? `: ${ZLoggerConsole.FATAL} - ${entry.message}` : `: ${entry.message}`;\n fn(`${timestamp}${payload}`);\n }\n}\n","import { IZLogEntry, ZLogEntryBuilder } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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';\nimport { IZLogEntry } from '../log-entry/log-entry';\nimport { IZLogger } from './logger';\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","this","_entry","catastrophe","level","bind","CATASTROPHE","error","ERROR","warning","WARNING","info","INFO","message","created","Date","toJSON","_proto","prototype","context","ctx","msg","copy","other","structuredClone","build","_extends","ZLoggerComposite","_children","log","entry","forEach","logger","ZLoggerConsole","_console","_this$_logFnMap","_logFnMap","warn","_this","toLocaleString","FATAL","ZLoggerContext","_context","_forward","clone","noop"],"mappings":"IAGYA,0PAAAA,QAAAA,eAAAA,GAAAA,EAAAA,QAASA,YAATA,QAASA,UAuCpB,KA/BCA,EAAA,YAAA,GAAA,cAQAA,EAAAA,EAAA,MAAA,GAAA,QAUAA,EAAAA,EAAA,QAAA,GAAA,UAYAA,EAAAA,EAAA,KAAA,GAAA,OAkCW,IAAAC,eAAgB,WAM3B,SAAAA,IAAAC,KALQC,YAAM,EAAAD,KAiCPE,YAAcF,KAAKG,MAAMC,KAAKJ,KAAMF,QAAAA,UAAUO,aAQ9CC,KAAAA,M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C,QAAAA,UAAUW,SAAU,SAACW,GAAgB,OAAAa,EAASG,KAAKhB,EAAI,EAAAc,EAE5D,QAACF,EAAAf,UAQMW,IAAA,SAAIC,GAAiB,IAAAQ,EAC1BrC,MAAWA,KAAKmC,UAAUN,EAAM1B,QAAW,SAACiB,UAAgBiB,EAAKJ,SAASL,IAAIR,EAAI,OAE5DS,EAAMhB,QAAQyB,sBAElCT,EAAM1B,QAAUL,kBAAUO,YAAmB2B,KAAAA,EAAeO,MAAK,MAAMV,EAAMjB,aAAiBiB,EAAMjB,SAExG,EAACoB,CAAA,CArBD,GAVWA,EACYO,MAAQ,YCDpB,IAAAC,eASX,WAAA,SAAAA,EACUC,EACAC,GAAkB1C,KADlByC,cACAC,EAAAA,KAAAA,gBADA1C,KAAQyC,SAARA,EACAzC,KAAQ0C,SAARA,CACP,QAACF,EAAAvB,UAEGW,IAAA,SAAIC,GACT,IAAMc,GAAQ,IAAI5C,GACfsB,KAAKQ,GACLX,QAAQW,EAAMX,SAAWlB,KAAKyC,UAC9BjB,QACH,YAAYkB,SAASd,IAAIe,EAC3B,EAACH,CAAA,CAXD,iICRwB,WAAAxC,KACjB4B,IAA+BgB,EAAIA,IAAA"}
@@ -1,6 +0,0 @@
1
- export * from './log-entry/log-entry';
2
- export * from './logger/logger';
3
- export * from './logger/logger-composite';
4
- export * from './logger/logger-console';
5
- export * from './logger/logger-context';
6
- export * from './logger/logger-silent';