@vvlad1973/simple-logger 1.2.2 → 2.0.1
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/CHANGELOG.md +143 -0
- package/README.md +91 -41
- package/dist/__test__/simple-logger.test.js +54 -101
- package/dist/__test__/simple-logger.test.js.map +1 -1
- package/dist/classes/simple-logger.d.ts +125 -0
- package/dist/classes/simple-logger.js +290 -0
- package/dist/classes/simple-logger.js.map +1 -0
- package/dist/constants/constants.d.ts +9 -0
- package/dist/constants/constants.js +10 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/helpers/helpers.d.ts +31 -0
- package/dist/helpers/helpers.js +81 -0
- package/dist/helpers/helpers.js.map +1 -0
- package/dist/helpers/validators.d.ts +17 -0
- package/dist/helpers/validators.js +27 -0
- package/dist/helpers/validators.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/types/simple-logger.types.d.ts +27 -0
- package/dist/types/simple-logger.types.js +2 -0
- package/dist/types/simple-logger.types.js.map +1 -0
- package/docs/assets/highlight.css +9 -2
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/SimpleLogger.html +27 -15
- package/docs/index.html +51 -22
- package/docs/interfaces/ExternalLogger.html +10 -0
- package/docs/interfaces/LogFn.html +1 -0
- package/docs/interfaces/LoggerOptions.html +5 -0
- package/docs/modules.html +1 -1
- package/docs/types/LoggerFactory.html +1 -0
- package/docs/types/LoggerLevel.html +1 -1
- package/docs/types/PreparedLogCall.html +1 -0
- package/docs/variables/LoggerLevels.html +1 -0
- package/package.json +20 -7
- package/src/__test__/simple-logger.test.ts +67 -55
- package/src/classes/simple-logger.ts +354 -0
- package/src/constants/constants.ts +9 -0
- package/src/helpers/helpers.ts +92 -0
- package/src/helpers/validators.ts +36 -0
- package/src/index.ts +7 -2
- package/src/types/simple-logger.types.ts +40 -0
- package/docs/media/index.html +0 -39
- package/docs/types/ExternalLogger.html +0 -1
- package/src/simple-logger.ts +0 -190
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LoggerLevel | @vvlad1973/simple-logger -
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LoggerLevel | @vvlad1973/simple-logger - v2.0.0</title><meta name="description" content="Documentation for @vvlad1973/simple-logger"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@vvlad1973/simple-logger - v2.0.0</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@vvlad1973/simple-logger</a></li><li><a href="LoggerLevel.html">LoggerLevel</a></li></ul><h1>Type Alias LoggerLevel</h1></div><div class="tsd-signature"><span class="tsd-kind-type-alias">LoggerLevel</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-keyword">typeof</span> <a href="../variables/LoggerLevels.html" class="tsd-signature-type tsd-kind-variable">LoggerLevels</a><span class="tsd-signature-symbol">[</span><span class="tsd-signature-keyword">keyof</span> <span class="tsd-signature-keyword">typeof</span> <a href="../variables/LoggerLevels.html" class="tsd-signature-type tsd-kind-variable">LoggerLevels</a><span class="tsd-signature-symbol">]</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/vvlad1973/vvlad1973-simple-logger/blob/25adff29c925b307b1be754d5e14b30812eddba4/src/types/simple-logger.types.ts#L3">types/simple-logger.types.ts:3</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@vvlad1973/simple-logger - v2.0.0</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>PreparedLogCall | @vvlad1973/simple-logger - v2.0.0</title><meta name="description" content="Documentation for @vvlad1973/simple-logger"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@vvlad1973/simple-logger - v2.0.0</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@vvlad1973/simple-logger</a></li><li><a href="PreparedLogCall.html">PreparedLogCall</a></li></ul><h1>Type Alias PreparedLogCall</h1></div><div class="tsd-signature"><span class="tsd-kind-type-alias">PreparedLogCall</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-symbol">...</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">]</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">object</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">?</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-symbol">...</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">]</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">null</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/vvlad1973/vvlad1973-simple-logger/blob/25adff29c925b307b1be754d5e14b30812eddba4/src/types/simple-logger.types.ts#L37">types/simple-logger.types.ts:37</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@vvlad1973/simple-logger - v2.0.0</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LoggerLevels | @vvlad1973/simple-logger - v2.0.0</title><meta name="description" content="Documentation for @vvlad1973/simple-logger"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@vvlad1973/simple-logger - v2.0.0</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@vvlad1973/simple-logger</a></li><li><a href="LoggerLevels.html">LoggerLevels</a></li></ul><h1>Variable LoggerLevels<code class="tsd-tag">Const</code></h1></div><div class="tsd-signature"><span class="tsd-kind-variable">LoggerLevels</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{</span><br/> <span class="tsd-kind-property">DEBUG</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"debug"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">ERROR</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"error"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">FATAL</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"fatal"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">INFO</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"info"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">SILENT</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"silent"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">TRACE</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"trace"</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">WARN</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"warn"</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span><span class="tsd-signature-symbol"> = ...</span></div><div class="tsd-type-declaration"><h4>Type declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">DEBUG</span><a id="__typedebug" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"debug"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">ERROR</span><a id="__typeerror" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"error"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">FATAL</span><a id="__typefatal" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"fatal"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">INFO</span><a id="__typeinfo" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"info"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">SILENT</span><a id="__typesilent" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"silent"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">TRACE</span><a id="__typetrace" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"trace"</span></h5></li><li class="tsd-parameter"><h5><code class="tsd-tag">Readonly</code><span class="tsd-kind-property">WARN</span><a id="__typewarn" class="tsd-anchor"></a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">"warn"</span></h5></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/vvlad1973/vvlad1973-simple-logger/blob/25adff29c925b307b1be754d5e14b30812eddba4/src/constants/constants.ts#L1">constants/constants.ts:1</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@vvlad1973/simple-logger - v2.0.0</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/package.json
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvlad1973/simple-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "npm run build && node --loader ts-node/esm --test",
|
|
9
9
|
"build": "tsc",
|
|
10
|
-
"doc": "npx typedoc"
|
|
10
|
+
"doc": "npx typedoc",
|
|
11
|
+
"changelog": "npx gen-changelog",
|
|
12
|
+
"release": "npm run changelog && git add CHANGELOG.md && commit-and-tag-version",
|
|
13
|
+
"release:alpha": "npm run changelog && git add CHANGELOG.md && commit-and-tag-version --prerelease alpha",
|
|
14
|
+
"release:beta": "npm run changelog && git add CHANGELOG.md && commit-and-tag-version --prerelease beta",
|
|
15
|
+
"release:rc": "npm run changelog && git add CHANGELOG.md && commit-and-tag-version --prerelease rc"
|
|
11
16
|
},
|
|
12
17
|
"author": "Vladislav Vnukovskiy <vvlad1973@gmail.com>",
|
|
13
18
|
"license": "MIT with Commercial Use",
|
|
14
19
|
"description": "A simple logging utility for JavaScript applications, providing customizable log levels and flexible external logger integration.",
|
|
15
20
|
"devDependencies": {
|
|
16
|
-
"@types/node": "^
|
|
21
|
+
"@types/node": "^22.15.3",
|
|
22
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
23
|
+
"@vvlad1973/gen-changelog": "^1.0.2",
|
|
17
24
|
"ts-node": "^10.9.2",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
25
|
+
"typedoc": "^0.27.9",
|
|
26
|
+
"typescript": "^5.8.3",
|
|
27
|
+
"vitest": "^3.1.2"
|
|
20
28
|
},
|
|
21
29
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"vvlad1973-utils": "^2.
|
|
30
|
+
"chalk": "^5.4.1",
|
|
31
|
+
"vvlad1973-utils": "^2.7.0"
|
|
32
|
+
},
|
|
33
|
+
"commit-and-tag-version": {
|
|
34
|
+
"skip": {
|
|
35
|
+
"changelog": true
|
|
36
|
+
}
|
|
24
37
|
}
|
|
25
38
|
}
|
|
@@ -1,69 +1,81 @@
|
|
|
1
|
-
import { describe, it,
|
|
2
|
-
import SimpleLogger from '../simple-logger.js';
|
|
3
|
-
|
|
4
|
-
type ExternalLoggerMock = {
|
|
5
|
-
trace: ReturnType<typeof vi.fn>;
|
|
6
|
-
debug: ReturnType<typeof vi.fn>;
|
|
7
|
-
info: ReturnType<typeof vi.fn>;
|
|
8
|
-
warn: ReturnType<typeof vi.fn>;
|
|
9
|
-
error: ReturnType<typeof vi.fn>;
|
|
10
|
-
fatal: ReturnType<typeof vi.fn>;
|
|
11
|
-
silent: ReturnType<typeof vi.fn>;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function createExternalLoggerMock(): ExternalLoggerMock {
|
|
15
|
-
return {
|
|
16
|
-
trace: vi.fn(),
|
|
17
|
-
debug: vi.fn(),
|
|
18
|
-
info: vi.fn(),
|
|
19
|
-
warn: vi.fn(),
|
|
20
|
-
error: vi.fn(),
|
|
21
|
-
fatal: vi.fn(),
|
|
22
|
-
silent: vi.fn(),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import SimpleLogger from '../classes/simple-logger.js';
|
|
3
|
+
import { ExternalLogger } from '../types/simple-logger.types.js';
|
|
25
4
|
|
|
26
5
|
describe('SimpleLogger', () => {
|
|
27
|
-
let
|
|
28
|
-
let externalLoggerMock: ExternalLoggerMock;
|
|
6
|
+
let consoleSpy: ReturnType<typeof vi.spyOn>;
|
|
29
7
|
|
|
30
8
|
beforeEach(() => {
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
consoleSpy.mockRestore();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should log using console when no external logger is provided', () => {
|
|
17
|
+
const logger = new SimpleLogger();
|
|
18
|
+
logger.info('test message');
|
|
19
|
+
expect(consoleSpy).toHaveBeenCalledOnce();
|
|
20
|
+
expect(consoleSpy.mock.calls[0][0]).toMatch(/test message/);
|
|
33
21
|
});
|
|
34
22
|
|
|
35
|
-
it('should
|
|
36
|
-
logger
|
|
37
|
-
logger.
|
|
38
|
-
logger.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
it('should not log below current level', () => {
|
|
24
|
+
const logger = new SimpleLogger(null, { level: 'warn' });
|
|
25
|
+
logger.info('should not log');
|
|
26
|
+
logger.warn('should log');
|
|
27
|
+
expect(consoleSpy).toHaveBeenCalledOnce();
|
|
28
|
+
expect(consoleSpy.mock.calls[0][0]).toMatch(/should log/);
|
|
29
|
+
});
|
|
42
30
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
expect(
|
|
47
|
-
expect(externalLoggerMock.warn).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(externalLoggerMock.warn).toHaveBeenCalledWith('warn message');
|
|
49
|
-
expect(externalLoggerMock.error).toHaveBeenCalledTimes(1);
|
|
50
|
-
expect(externalLoggerMock.error).toHaveBeenCalledWith('error message');
|
|
51
|
-
expect(externalLoggerMock.fatal).toHaveBeenCalledTimes(1);
|
|
52
|
-
expect(externalLoggerMock.fatal).toHaveBeenCalledWith('fatal message');
|
|
31
|
+
it('should respect msgPrefix', () => {
|
|
32
|
+
const logger = new SimpleLogger(null, { msgPrefix: '[PREFIX]' });
|
|
33
|
+
logger.info('message');
|
|
34
|
+
expect(consoleSpy.mock.calls[0][0]).toMatch(/\[PREFIX\]/);
|
|
53
35
|
});
|
|
54
36
|
|
|
55
|
-
it('should
|
|
56
|
-
|
|
37
|
+
it('should use external logger methods if provided', () => {
|
|
38
|
+
const external: ExternalLogger = {
|
|
39
|
+
info: vi.fn(),
|
|
40
|
+
level: 'info',
|
|
41
|
+
};
|
|
42
|
+
const logger = new SimpleLogger(external);
|
|
43
|
+
logger.info('external log');
|
|
44
|
+
expect(external.info).toHaveBeenCalledOnce();
|
|
45
|
+
expect(external.info).toHaveBeenCalledWith('external log');
|
|
46
|
+
});
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
it('should fallback to console for invalid external logger', () => {
|
|
49
|
+
const logger = new SimpleLogger({} as ExternalLogger);
|
|
50
|
+
logger.info('fallback');
|
|
51
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
52
|
+
});
|
|
62
53
|
|
|
63
|
-
|
|
54
|
+
it('should create child logger with merged bindings', () => {
|
|
55
|
+
const logger = new SimpleLogger(null, { bindings: { user: 'A' } });
|
|
56
|
+
const child = logger.child({ request: '123' });
|
|
57
|
+
|
|
58
|
+
child.info('child message');
|
|
59
|
+
|
|
60
|
+
expect(consoleSpy.mock.calls.length).toBe(1);
|
|
61
|
+
const output = consoleSpy.mock.calls[0][0];
|
|
62
|
+
|
|
63
|
+
expect(output).toMatch(/user=A/);
|
|
64
|
+
expect(output).toMatch(/request=123/);
|
|
65
|
+
expect(output).toMatch(/child message/);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
it('should call .child if external logger supports it', () => {
|
|
71
|
+
const childFn = vi.fn(() => ({
|
|
72
|
+
info: vi.fn(),
|
|
73
|
+
level: 'info',
|
|
74
|
+
}));
|
|
75
|
+
const external = { level: 'info', child: childFn, info: vi.fn() };
|
|
76
|
+
const logger = new SimpleLogger(external);
|
|
77
|
+
const child = logger.child({ traceId: 'xyz' });
|
|
78
|
+
child.info('from child');
|
|
79
|
+
expect(childFn).toHaveBeenCalledWith({ traceId: 'xyz' });
|
|
68
80
|
});
|
|
69
81
|
});
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for simple logging with various logging levels.
|
|
3
|
+
* @module SimpleLogger
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import util from 'util';
|
|
7
|
+
import { getCallerName } from 'vvlad1973-utils';
|
|
8
|
+
import { hasChild, isValidLogger } from '../helpers/validators.js';
|
|
9
|
+
import {
|
|
10
|
+
extractContext,
|
|
11
|
+
extractMessage,
|
|
12
|
+
colorizeLevel,
|
|
13
|
+
prepareLogCall,
|
|
14
|
+
} from '../helpers/helpers.js';
|
|
15
|
+
import { LoggerLevels } from '../constants/constants.js';
|
|
16
|
+
import {
|
|
17
|
+
ExternalLogger,
|
|
18
|
+
LogFn,
|
|
19
|
+
LoggerFactory,
|
|
20
|
+
LoggerLevel,
|
|
21
|
+
LoggerOptions,
|
|
22
|
+
} from '../types/simple-logger.types.js';
|
|
23
|
+
|
|
24
|
+
export default class SimpleLogger {
|
|
25
|
+
private currentLevelIndex = Object.values(LoggerLevels).indexOf(
|
|
26
|
+
LoggerLevels.INFO
|
|
27
|
+
);
|
|
28
|
+
private logger: ExternalLogger | Console = console;
|
|
29
|
+
private bindings: Record<string, unknown> = {};
|
|
30
|
+
private msgPrefix?: string;
|
|
31
|
+
private enabled = true;
|
|
32
|
+
isExternal = false;
|
|
33
|
+
|
|
34
|
+
static readonly noop: LogFn = () => {};
|
|
35
|
+
|
|
36
|
+
trace: LogFn = SimpleLogger.noop;
|
|
37
|
+
debug: LogFn = SimpleLogger.noop;
|
|
38
|
+
info: LogFn = SimpleLogger.noop;
|
|
39
|
+
warn: LogFn = SimpleLogger.noop;
|
|
40
|
+
error: LogFn = SimpleLogger.noop;
|
|
41
|
+
fatal: LogFn = SimpleLogger.noop;
|
|
42
|
+
silent: LogFn = SimpleLogger.noop;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Initializes a new instance of the SimpleLogger class.
|
|
46
|
+
*
|
|
47
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
48
|
+
* @param {LoggerOptions} [options={}] - Options for the logger, such as the logging level and bindings.
|
|
49
|
+
*/
|
|
50
|
+
constructor(
|
|
51
|
+
externalLogger?: ExternalLogger | LoggerFactory | null,
|
|
52
|
+
options: LoggerOptions = {}
|
|
53
|
+
) {
|
|
54
|
+
this.initLogger(externalLogger, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the effective logging level based on the provided logger and explicit level.
|
|
59
|
+
*
|
|
60
|
+
* @param {ExternalLogger | Console} logger - The logger to resolve the level for.
|
|
61
|
+
* @param {LoggerLevel} [explicitLevel] - The explicit logging level to use, if provided.
|
|
62
|
+
* @return {LoggerLevel} The resolved effective logging level.
|
|
63
|
+
*/
|
|
64
|
+
private resolveEffectiveLevel(
|
|
65
|
+
logger: ExternalLogger | Console,
|
|
66
|
+
explicitLevel?: LoggerLevel
|
|
67
|
+
): LoggerLevel {
|
|
68
|
+
const levels = Object.values(LoggerLevels);
|
|
69
|
+
if (explicitLevel) return explicitLevel;
|
|
70
|
+
if (
|
|
71
|
+
logger &&
|
|
72
|
+
typeof logger === 'object' &&
|
|
73
|
+
'level' in logger &&
|
|
74
|
+
typeof (logger as any).level === 'string'
|
|
75
|
+
) {
|
|
76
|
+
const lvl = (logger as any).level.toLowerCase();
|
|
77
|
+
if (levels.includes(lvl as LoggerLevel)) return lvl as LoggerLevel;
|
|
78
|
+
}
|
|
79
|
+
return levels[this.currentLevelIndex];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Initializes the logger with the provided external logger and options.
|
|
84
|
+
*
|
|
85
|
+
* Handles different cases for the external logger, including:
|
|
86
|
+
* - No external logger provided (falls back to console)
|
|
87
|
+
* - External logger is a factory function (e.g. pino)
|
|
88
|
+
* - External logger is invalid or console (falls back to console)
|
|
89
|
+
* - External logger is provided without parameters
|
|
90
|
+
* - External logger has a .child() method
|
|
91
|
+
* - External logger does not have a .child() method (uses directly)
|
|
92
|
+
*
|
|
93
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
94
|
+
* @param {LoggerOptions} options - Options for the logger, such as the logging level and bindings.
|
|
95
|
+
* @return {void}
|
|
96
|
+
*/
|
|
97
|
+
private initLogger(
|
|
98
|
+
externalLogger?: ExternalLogger | LoggerFactory | null,
|
|
99
|
+
options: LoggerOptions = {}
|
|
100
|
+
): void {
|
|
101
|
+
const {
|
|
102
|
+
level,
|
|
103
|
+
bindings = {},
|
|
104
|
+
msgPrefix,
|
|
105
|
+
transport,
|
|
106
|
+
...restOptions
|
|
107
|
+
} = options;
|
|
108
|
+
|
|
109
|
+
const hasParams = level || msgPrefix || Object.keys(bindings).length > 0;
|
|
110
|
+
const effectiveBindings = {
|
|
111
|
+
...bindings,
|
|
112
|
+
...(msgPrefix ? { msgPrefix } : {}),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.bindings = effectiveBindings;
|
|
116
|
+
this.msgPrefix = msgPrefix;
|
|
117
|
+
|
|
118
|
+
// CASE 1: логгер не передан
|
|
119
|
+
if (!externalLogger) {
|
|
120
|
+
this.logger = console;
|
|
121
|
+
this.isExternal = false;
|
|
122
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// CASE 2: логгер — фабрика (например, pino)
|
|
127
|
+
if (typeof externalLogger === 'function') {
|
|
128
|
+
this.logger = externalLogger({
|
|
129
|
+
level,
|
|
130
|
+
...restOptions,
|
|
131
|
+
...(transport ? { transport } : {}),
|
|
132
|
+
});
|
|
133
|
+
this.isExternal = true;
|
|
134
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// CASE 3: логгер есть, но он невалиден (нет методов)
|
|
139
|
+
if (!isValidLogger(externalLogger) || externalLogger === console) {
|
|
140
|
+
console.warn(
|
|
141
|
+
'Invalid or console logger passed, falling back to internal console.'
|
|
142
|
+
);
|
|
143
|
+
this.logger = console;
|
|
144
|
+
this.isExternal = false;
|
|
145
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// CASE 4: логгер передан без параметров
|
|
150
|
+
if (!hasParams) {
|
|
151
|
+
this.logger = externalLogger;
|
|
152
|
+
this.isExternal = true;
|
|
153
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// CASE 5: логгер с .child()
|
|
158
|
+
if (hasChild(externalLogger)) {
|
|
159
|
+
this.logger = externalLogger.child({
|
|
160
|
+
...effectiveBindings,
|
|
161
|
+
...restOptions,
|
|
162
|
+
...(transport ? { transport } : {}),
|
|
163
|
+
});
|
|
164
|
+
this.isExternal = true;
|
|
165
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// CASE 6: логгер без .child — используем напрямую, только применим level
|
|
170
|
+
this.logger = externalLogger;
|
|
171
|
+
this.isExternal = true;
|
|
172
|
+
|
|
173
|
+
if (typeof externalLogger.level === 'string') {
|
|
174
|
+
externalLogger.level = this.resolveEffectiveLevel(this.logger, level);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Updates the logging methods based on the current logging level and external logger configuration.
|
|
182
|
+
*
|
|
183
|
+
* Iterates over the available logging levels and sets the corresponding logging method to either call the external log method or the internal pretty format log method, depending on the logger configuration.
|
|
184
|
+
*
|
|
185
|
+
* @return {void}
|
|
186
|
+
*/
|
|
187
|
+
private updateLoggingMethods(): void {
|
|
188
|
+
const levels = Object.values(LoggerLevels);
|
|
189
|
+
|
|
190
|
+
levels.forEach((level, index) => {
|
|
191
|
+
if (this.enabled && this.currentLevelIndex <= index) {
|
|
192
|
+
this[level] = (...args: unknown[]) => {
|
|
193
|
+
if (this.isExternal) {
|
|
194
|
+
this.callExternalLogMethod(level, args);
|
|
195
|
+
} else {
|
|
196
|
+
this.prettyFormatLog(level, args);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
} else {
|
|
200
|
+
this[level] = SimpleLogger.noop;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Calls the external log method for the specified level with the provided arguments.
|
|
207
|
+
*
|
|
208
|
+
* @param {LoggerLevel} level - The logging level to use for the external log method.
|
|
209
|
+
* @param {unknown[]} args - The arguments to pass to the external log method.
|
|
210
|
+
* @return {void}
|
|
211
|
+
*/
|
|
212
|
+
private callExternalLogMethod(level: LoggerLevel, args: unknown[]): void {
|
|
213
|
+
const method = (this.logger as ExternalLogger)[level];
|
|
214
|
+
if (typeof method !== 'function') return;
|
|
215
|
+
|
|
216
|
+
const prepared = prepareLogCall(args);
|
|
217
|
+
|
|
218
|
+
if (prepared !== null) {
|
|
219
|
+
(method as (...args: unknown[]) => void)(...prepared);
|
|
220
|
+
} else {
|
|
221
|
+
console.warn(`Invalid log arguments for "${level}"`, args);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Formats and logs a message with the specified level and arguments.
|
|
227
|
+
*
|
|
228
|
+
* @param {LoggerLevel} level - The logging level to use for the log message.
|
|
229
|
+
* @param {unknown[]} args - The arguments to use when formatting the log message.
|
|
230
|
+
* @return {void}
|
|
231
|
+
*/
|
|
232
|
+
private prettyFormatLog(level: LoggerLevel, args: unknown[]): void {
|
|
233
|
+
const time = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
234
|
+
const levelStr = colorizeLevel(level, level.toUpperCase().padEnd(5));
|
|
235
|
+
const context = extractContext(args);
|
|
236
|
+
const { msg, rest } = extractMessage(args);
|
|
237
|
+
const fullMsg = util.format(msg, ...rest);
|
|
238
|
+
|
|
239
|
+
const ctx = Object.entries({ ...this.bindings, ...context })
|
|
240
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
241
|
+
.join(' ');
|
|
242
|
+
|
|
243
|
+
const prefix = `[${time}] ${levelStr}`;
|
|
244
|
+
const contextStr = ctx ? ` (${ctx})` : '';
|
|
245
|
+
const msgPrefixStr = this.msgPrefix ? ` ${this.msgPrefix}` : '';
|
|
246
|
+
|
|
247
|
+
console.log(`${prefix}${contextStr}:${msgPrefixStr} ${fullMsg}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Retrieves the current logging level.
|
|
252
|
+
*
|
|
253
|
+
* @return {LoggerLevel} The current logging level.
|
|
254
|
+
*/
|
|
255
|
+
public getLevel(): LoggerLevel {
|
|
256
|
+
return Object.values(LoggerLevels)[this.currentLevelIndex];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Sets the logging level.
|
|
261
|
+
*
|
|
262
|
+
* @param {LoggerLevel} level - The logging level to set.
|
|
263
|
+
* @return {void}
|
|
264
|
+
*/
|
|
265
|
+
public setLevel(level: LoggerLevel): void {
|
|
266
|
+
const index = Object.values(LoggerLevels).indexOf(level);
|
|
267
|
+
if (index !== -1) {
|
|
268
|
+
this.currentLevelIndex = index;
|
|
269
|
+
if (typeof (this.logger as ExternalLogger).level === 'string') {
|
|
270
|
+
(this.logger as ExternalLogger).level = level;
|
|
271
|
+
}
|
|
272
|
+
this.updateLoggingMethods();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Enables the logger.
|
|
278
|
+
*
|
|
279
|
+
* @return {void}
|
|
280
|
+
*/
|
|
281
|
+
public enable(): void {
|
|
282
|
+
this.enabled = true;
|
|
283
|
+
this.updateLoggingMethods();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Disables the logger.
|
|
288
|
+
*
|
|
289
|
+
* @return {void} Nothing is returned.
|
|
290
|
+
*/
|
|
291
|
+
public disable(): void {
|
|
292
|
+
this.enabled = false;
|
|
293
|
+
this.updateLoggingMethods();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Creates a new child logger with the merged bindings.
|
|
298
|
+
*
|
|
299
|
+
* If the external logger supports the `child` method, it will be used to create the child logger.
|
|
300
|
+
* Otherwise, a new SimpleLogger instance will be created with the merged bindings.
|
|
301
|
+
*
|
|
302
|
+
* @param {Record<string, unknown>} newBindings - The new bindings to merge with the existing bindings.
|
|
303
|
+
* @return {SimpleLogger} The new child logger instance.
|
|
304
|
+
*/
|
|
305
|
+
public child(newBindings: Record<string, unknown>): SimpleLogger {
|
|
306
|
+
const merged = { ...this.bindings, ...newBindings };
|
|
307
|
+
|
|
308
|
+
if (
|
|
309
|
+
this.isExternal &&
|
|
310
|
+
typeof this.logger === 'object' &&
|
|
311
|
+
this.logger !== null
|
|
312
|
+
) {
|
|
313
|
+
const logger = this.logger as ExternalLogger;
|
|
314
|
+
const childFn = logger.child;
|
|
315
|
+
|
|
316
|
+
if (typeof childFn === 'function') {
|
|
317
|
+
const childLogger = childFn.call(logger, merged);
|
|
318
|
+
return new SimpleLogger(childLogger, {
|
|
319
|
+
level: this.getLevel(),
|
|
320
|
+
bindings: merged,
|
|
321
|
+
msgPrefix: this.msgPrefix,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return new SimpleLogger(this.logger as ExternalLogger, {
|
|
327
|
+
level: this.getLevel(),
|
|
328
|
+
bindings: merged,
|
|
329
|
+
msgPrefix: this.msgPrefix,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Logs the start of a function.
|
|
335
|
+
*
|
|
336
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
337
|
+
* @return {void}
|
|
338
|
+
*/
|
|
339
|
+
public logFunctionStart(name?: string): void {
|
|
340
|
+
const caller = name || getCallerName();
|
|
341
|
+
this.trace(`Function start: ${caller}`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Logs the end of a function.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
348
|
+
* @return {void}
|
|
349
|
+
*/
|
|
350
|
+
public logFunctionEnd(name?: string): void {
|
|
351
|
+
const caller = name || getCallerName();
|
|
352
|
+
this.trace(`Function end: ${caller}`);
|
|
353
|
+
}
|
|
354
|
+
}
|