@zthun/lumberjacky-log 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Anthony Bonta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
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 r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},n.apply(this,arguments)}var r;!function(t){t[t.CATASTROPHE=0]="CATASTROPHE",t[t.ERROR=1]="ERROR",t[t.WARNING=2]="WARNING",t[t.INFO=3]="INFO"}(r||(r={}));var e=/*#__PURE__*/function(){function t(){this._entry=void 0,this._entry={context:"",level:r.ERROR,message:"",created:(new Date).toJSON()}}var e=t.prototype;return e.catastrophe=function(){return this._entry.level=r.CATASTROPHE,this},e.error=function(){return this._entry.level=r.ERROR,this},e.warning=function(){return this._entry.level=r.WARNING,this},e.info=function(){return this._entry.level=r.INFO,this},e.context=function(t){return this._entry.context=t,this},e.message=function(t){return this._entry.message=t,this},e.build=function(){return n({},this._entry)},t}(),o=/*#__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}(),i=/*#__PURE__*/function(){function t(t){var n;this._console=void 0,this._logFnMap=void 0,this._console=t,this._logFnMap=((n={})[r.CATASTROPHE]=function(n){return t.error(n)},n[r.ERROR]=function(n){return t.error(n)},n[r.WARNING]=function(n){return t.warn(n)},n)}return t.prototype.log=function(n){var e=this;(this._logFnMap[n.level]||function(t){return e._console.log(t)})("["+n.created.toLocaleString()+"]"+(n.level===r.CATASTROPHE?": "+t.FATAL+" - "+n.message:": "+n.message))},t}();i.FATAL="!!FATAL!!";var s=function(){this.log=t};export{e as ZLogEntryBuilder,r as ZLogLevel,o as ZLoggerComposite,i as ZLoggerConsole,s as ZLoggerSilent};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
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-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 context: '',\n level: ZLogLevel.ERROR,\n message: '',\n created: new Date().toJSON()\n };\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe(): this {\n this._entry.level = ZLogLevel.CATASTROPHE;\n return this;\n }\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error(): this {\n this._entry.level = ZLogLevel.ERROR;\n return this;\n }\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning(): this {\n this._entry.level = ZLogLevel.WARNING;\n return this;\n }\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info(): this {\n this._entry.level = ZLogLevel.INFO;\n return this;\n }\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): 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 * 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 { 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","_entry","this","context","level","ERROR","message","created","Date","toJSON","_proto","prototype","catastrophe","CATASTROPHE","error","warning","WARNING","info","INFO","ctx","msg","build","_extends","ZLoggerComposite","_children","log","entry","forEach","logger","ZLoggerConsole","_console","_this$_logFnMap","_logFnMap","warn","_this","toLocaleString","FATAL","ZLoggerSilent","noop"],"mappings":"kQAGY,IAAAA,GAAZ,S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SAARA,EACzB5B,KAAK8B,YAASD,EAAAA,CAAAA,GACXhC,EAAUc,aAAc,SAACO,GAAgB,OAAAU,EAAShB,MAAMM,EAAI,EAAAW,EAC5DhC,EAAUM,OAAQ,SAACe,GAAgB,OAAAU,EAAShB,MAAMM,EAAI,EAAAW,EACtDhC,EAAUiB,SAAU,SAACI,GAAgB,OAAAU,EAASG,KAAKb,EAAI,EAAAW,EAE5D,QAACF,EAAAlB,UAQMc,IAAA,SAAIC,GAAiB,IAAAQ,EAC1BhC,MAAWA,KAAK8B,UAAUN,EAAMtB,QAAW,SAACgB,UAAgBc,EAAKJ,SAASL,IAAIL,EAAI,OAE5DM,EAAMnB,QAAQ4B,sBAElCT,EAAMtB,QAAUL,EAAUc,YAAmBgB,KAAAA,EAAeO,MAAK,MAAMV,EAAMpB,aAAiBoB,EAAMpB,SAExG,EAACuB,CAAA,CArBD,GAVWA,EACYO,MAAQ,YCApB,IAAAC,EAAa,WAAAnC,KACjBuB,IAA+Ba,CAAI"}
@@ -0,0 +1,2 @@
1
+ var e,t=require("lodash");function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},o.apply(this,arguments)}exports.ZLogLevel=void 0,(e=exports.ZLogLevel||(exports.ZLogLevel={}))[e.CATASTROPHE=0]="CATASTROPHE",e[e.ERROR=1]="ERROR",e[e.WARNING=2]="WARNING",e[e.INFO=3]="INFO";var r=/*#__PURE__*/function(){function e(){this._entry=void 0,this._entry={context:"",level:exports.ZLogLevel.ERROR,message:"",created:(new Date).toJSON()}}var t=e.prototype;return t.catastrophe=function(){return this._entry.level=exports.ZLogLevel.CATASTROPHE,this},t.error=function(){return this._entry.level=exports.ZLogLevel.ERROR,this},t.warning=function(){return this._entry.level=exports.ZLogLevel.WARNING,this},t.info=function(){return this._entry.level=exports.ZLogLevel.INFO,this},t.context=function(e){return this._entry.context=e,this},t.message=function(e){return this._entry.message=e,this},t.build=function(){return o({},this._entry)},e}(),n=/*#__PURE__*/function(){function e(e){this._children=void 0,this._children=e}return e.prototype.log=function(e){this._children.forEach(function(t){return t.log(e)})},e}(),i=/*#__PURE__*/function(){function e(e){var t;this._console=void 0,this._logFnMap=void 0,this._console=e,this._logFnMap=((t={})[exports.ZLogLevel.CATASTROPHE]=function(t){return e.error(t)},t[exports.ZLogLevel.ERROR]=function(t){return e.error(t)},t[exports.ZLogLevel.WARNING]=function(t){return e.warn(t)},t)}return e.prototype.log=function(t){var o=this;(this._logFnMap[t.level]||function(e){return o._console.log(e)})("["+t.created.toLocaleString()+"]"+(t.level===exports.ZLogLevel.CATASTROPHE?": "+e.FATAL+" - "+t.message:": "+t.message))},e}();i.FATAL="!!FATAL!!",exports.ZLogEntryBuilder=r,exports.ZLoggerComposite=n,exports.ZLoggerConsole=i,exports.ZLoggerSilent=function(){this.log=t.noop};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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-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 context: '',\n level: ZLogLevel.ERROR,\n message: '',\n created: new Date().toJSON()\n };\n }\n\n /**\n * Sets the log level to catastrophe.\n *\n * @returns\n * This object.\n */\n public catastrophe(): this {\n this._entry.level = ZLogLevel.CATASTROPHE;\n return this;\n }\n\n /**\n * Sets the log level to error.\n *\n * @returns\n * This object.\n */\n public error(): this {\n this._entry.level = ZLogLevel.ERROR;\n return this;\n }\n\n /**\n * Sets the log level to warning.\n *\n * @returns\n * This object.\n */\n public warning(): this {\n this._entry.level = ZLogLevel.WARNING;\n return this;\n }\n\n /**\n * Sets the log level to info.\n *\n * @returns\n * This object.\n */\n public info(): this {\n this._entry.level = ZLogLevel.INFO;\n return this;\n }\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): 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 * 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 { 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","_entry","this","context","level","ERROR","message","created","Date","toJSON","_proto","prototype","catastrophe","CATASTROPHE","error","warning","WARNING","info","INFO","ctx","msg","build","_extends","ZLoggerComposite","_children","log","entry","forEach","logger","ZLoggerConsole","_console","_this$_logFnMap","_logFnMap","warn","_this","toLocaleString","FATAL","noop"],"mappings":"IAGYA,0PAAAA,QAAAA,eAAAA,GAAAA,EAAAA,QAASA,YAATA,QAASA,UAuCpB,CAAA,IA/BCA,EAAA,YAAA,GAAA,cAQAA,EAAAA,EAAA,MAAA,GAAA,QAUAA,EAAAA,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MAAMM,EAAI,EAAAW,EAC5DhC,QAASA,UAACM,OAAQ,SAACe,GAAgB,OAAAU,EAAShB,MAAMM,EAAI,EAAAW,EACtDhC,QAAAA,UAAUiB,SAAU,SAACI,GAAgB,OAAAU,EAASG,KAAKb,EAAI,EAAAW,EAE5D,QAACF,EAAAlB,UAQMc,IAAA,SAAIC,GAAiB,IAAAQ,EAC1BhC,MAAWA,KAAK8B,UAAUN,EAAMtB,QAAW,SAACgB,UAAgBc,EAAKJ,SAASL,IAAIL,EAAI,OAE5DM,EAAMnB,QAAQ4B,sBAElCT,EAAMtB,QAAUL,kBAAUc,YAAmBgB,KAAAA,EAAeO,MAAK,MAAMV,EAAMpB,aAAiBoB,EAAMpB,SAExG,EAACuB,CAAA,CArBD,GAVWA,EACYO,MAAQ,iHCAP,WAAAlC,KACjBuB,IAA+BY,EAAIA,IAAA"}
@@ -0,0 +1,5 @@
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-silent';
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The log level.
3
+ */
4
+ export declare enum ZLogLevel {
5
+ /**
6
+ * A fatal error.
7
+ *
8
+ * Someone's pager is going off at 2:00 in the
9
+ * morning because the nuclear codes have gone off
10
+ * and missiles have been launched.
11
+ */
12
+ CATASTROPHE = 0,
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
+ */
19
+ ERROR = 1,
20
+ /**
21
+ * Nothing is really totally 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
+ */
28
+ WARNING = 2,
29
+ /**
30
+ * Some information that's good to know.
31
+ *
32
+ * Analytic logs are in this zone and general
33
+ * information goes in this zone. Debug as
34
+ * well, goes into this zone.
35
+ *
36
+ * It is normally best to avoid this log level
37
+ * unless it's really important to display.
38
+ */
39
+ INFO = 3
40
+ }
41
+ /**
42
+ * Represents a log entry.
43
+ */
44
+ export interface IZLogEntry {
45
+ /**
46
+ * The log context.
47
+ *
48
+ * This will usually be a friendly name of a function
49
+ * or class where this log took place.
50
+ */
51
+ context: string;
52
+ /**
53
+ * The log level.
54
+ */
55
+ level: ZLogLevel;
56
+ /**
57
+ * The creation of this entry.
58
+ */
59
+ created: Date | string;
60
+ /**
61
+ * The log message.
62
+ */
63
+ message: string;
64
+ }
65
+ /**
66
+ * Represents a builder for a log entry
67
+ */
68
+ export declare class ZLogEntryBuilder {
69
+ private _entry;
70
+ /**
71
+ * Initializes a new instance of this object.
72
+ */
73
+ constructor();
74
+ /**
75
+ * Sets the log level to catastrophe.
76
+ *
77
+ * @returns
78
+ * This object.
79
+ */
80
+ catastrophe(): this;
81
+ /**
82
+ * Sets the log level to error.
83
+ *
84
+ * @returns
85
+ * This object.
86
+ */
87
+ error(): this;
88
+ /**
89
+ * Sets the log level to warning.
90
+ *
91
+ * @returns
92
+ * This object.
93
+ */
94
+ warning(): this;
95
+ /**
96
+ * Sets the log level to info.
97
+ *
98
+ * @returns
99
+ * This object.
100
+ */
101
+ info(): this;
102
+ /**
103
+ * Sets the context of the entry.
104
+ *
105
+ * @param ctx -
106
+ * The entry context.
107
+ *
108
+ * @returns
109
+ * This object.
110
+ */
111
+ context(ctx: string): this;
112
+ /**
113
+ * Sets the message.
114
+ *
115
+ * @param msg -
116
+ * The message to log.
117
+ *
118
+ * @returns
119
+ * This object.
120
+ */
121
+ message(msg: string): this;
122
+ /**
123
+ * Returns a copy of the built log entry.
124
+ *
125
+ * @returns
126
+ * The built log entry.
127
+ */
128
+ build(): IZLogEntry;
129
+ }
@@ -0,0 +1,22 @@
1
+ import { IZLogEntry } from '../log-entry/log-entry';
2
+ import { IZLogger } from './logger';
3
+ /**
4
+ * Represents a logger that logs to multiple sources.
5
+ */
6
+ export declare class ZLoggerComposite implements IZLogger {
7
+ private readonly _children;
8
+ /**
9
+ * Initializes a new instance of this object.
10
+ *
11
+ * @param _children -
12
+ * The collection of child loggers to log to.
13
+ */
14
+ constructor(_children: IZLogger[]);
15
+ /**
16
+ * Logs the entry into every one of the child loggers.
17
+ *
18
+ * @param entry -
19
+ * The entry to log.
20
+ */
21
+ log(entry: IZLogEntry): void;
22
+ }
@@ -0,0 +1,24 @@
1
+ import { IZLogEntry } from '../log-entry/log-entry';
2
+ import { IZLogger } from './logger';
3
+ /**
4
+ * Represents a logger that logs to the console.
5
+ */
6
+ export declare class ZLoggerConsole implements IZLogger {
7
+ private _console;
8
+ static readonly FATAL = "!!FATAL!!";
9
+ private _logFnMap;
10
+ /**
11
+ * Initializes a new instance of this object.
12
+ *
13
+ * @param _console -
14
+ * The console to log to.
15
+ */
16
+ constructor(_console: Console);
17
+ /**
18
+ * Logs the entry to the console.
19
+ *
20
+ * @param entry -
21
+ * The entry to log.
22
+ */
23
+ log(entry: IZLogEntry): void;
24
+ }
@@ -0,0 +1,8 @@
1
+ import { IZLogEntry } from '../log-entry/log-entry';
2
+ import { IZLogger } from './logger';
3
+ /**
4
+ * A silent logger. This logger does nothing.
5
+ */
6
+ export declare class ZLoggerSilent implements IZLogger {
7
+ log: (_: IZLogEntry) => void;
8
+ }
@@ -0,0 +1,17 @@
1
+ import { IZLogEntry } from '../log-entry/log-entry';
2
+ /**
3
+ * Represents a service that manages log entries.
4
+ *
5
+ * Logging is a fire and forget operation. If it fails,
6
+ * you move on. Logging should never stop the operation of the
7
+ * app.
8
+ */
9
+ export interface IZLogger {
10
+ /**
11
+ * Inserts a log entry.
12
+ *
13
+ * @param entry -
14
+ * The log entry.
15
+ */
16
+ log(entry: IZLogEntry): void;
17
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@zthun/lumberjacky-log",
3
+ "version": "1.1.0",
4
+ "description": "A standard log interface between different logging standards.",
5
+ "author": "Anthony Bonta",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zthun/lumberjacky",
10
+ "directory": "packages/lumberjacky-log"
11
+ },
12
+ "main": "./dist/lib/index.js",
13
+ "module": "./dist/lib/index.esm.js",
14
+ "types": "./dist/types/index.d.ts",
15
+ "scripts": {
16
+ "build": "microbundle --format esm,cjs --tsconfig tsconfig.prod.json"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "lodash": "^4.17.21"
23
+ },
24
+ "devDependencies": {
25
+ "microbundle": "^0.15.1",
26
+ "typescript": "^5.2.2",
27
+ "vitest": "^0.34.3",
28
+ "vitest-mock-extended": "^1.2.1"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "sideEffects": false,
34
+ "gitHead": "7e0c69a4f88247949f75f4d0736e2878a8ce179e"
35
+ }