@alwatr/logger 3.0.0 → 3.2.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/CHANGELOG.md +20 -0
- package/dist/define-package.d.ts +16 -0
- package/dist/define-package.d.ts.map +1 -0
- package/dist/logger.d.ts +16 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/main.cjs +6 -6
- package/dist/main.cjs.map +4 -4
- package/dist/main.d.ts +3 -16
- package/dist/main.d.ts.map +1 -1
- package/dist/main.mjs +6 -6
- package/dist/main.mjs.map +4 -4
- package/dist/type.d.ts +8 -0
- package/dist/type.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@3.1.0...@alwatr/logger@3.2.0) (2024-01-08)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **logger:** defaultDebugMode ([bab9f7c](https://github.com/Alwatr/nanolib/commit/bab9f7c7b26fc2f50476ebc74d484a4b39c9dbda)) by @AliMD
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **logger:** debugMode in definePackage ([9799320](https://github.com/Alwatr/nanolib/commit/97993203d76db57e55b31bef485ea77cfd32a64c)) by @njfamirm
|
|
15
|
+
|
|
16
|
+
# [3.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@3.0.1...@alwatr/logger@3.1.0) (2024-01-06)
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **logger:** definePackage ([dfd090e](https://github.com/Alwatr/nanolib/commit/dfd090ebd691c9a589370094d49f950524f71369)) by @AliMD
|
|
21
|
+
|
|
22
|
+
## [3.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@3.0.0...@alwatr/logger@3.0.1) (2024-01-03)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
25
|
+
|
|
6
26
|
# 3.0.0 (2024-01-03)
|
|
7
27
|
|
|
8
28
|
### Bug Fixes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AlwatrLogger } from './type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Global define package for managing package versions to prevent version conflicts and return package level logger.
|
|
4
|
+
* @param packageName package name including scope. e.g. `@scope/package-name`
|
|
5
|
+
* @param version package version (optional)
|
|
6
|
+
* @returns AlwatrLogger for the package
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const logger = definePackage('@scope/package-name', __package_version__);
|
|
11
|
+
*
|
|
12
|
+
* logger.logMethodArgs?.('myMethod', {a, b});
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function definePackage(packageName: string, version?: string, debugMode?: boolean): AlwatrLogger;
|
|
16
|
+
//# sourceMappingURL=define-package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-package.d.ts","sourceRoot":"","sources":["../src/define-package.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,SAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,YAAY,CAKpG"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AlwatrLogger } from './type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a logger function for fancy console debug with custom scope.
|
|
4
|
+
*
|
|
5
|
+
* - **color** is optional and automatically select from internal fancy color list.
|
|
6
|
+
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {createLogger} from 'https://esm.run/@alwatr/logger';
|
|
12
|
+
* const logger = createLogger('logger/demo');
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const createLogger: (domain: string, debugMode?: boolean) => AlwatrLogger;
|
|
16
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AA2D5C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WAAY,MAAM,0BAAiC,YAsD3E,CAAC"}
|
package/dist/main.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* @alwatr/logger v3.
|
|
2
|
-
"use strict";var
|
|
3
|
-
%s\x1B[33m.%s() Accident \`%s\`!${
|
|
4
|
-
%s\x1B[31m.%s() Error \`%s\`${
|
|
5
|
-
`,e):console.error.bind(console,"%c%s%c.%s() Error `%s`\n",
|
|
6
|
-
%s${
|
|
1
|
+
/* @alwatr/logger v3.2.0 */
|
|
2
|
+
"use strict";var f=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var _=(e,o)=>{for(var n in o)f(e,n,{get:o[n],enumerable:!0})},A=(e,o,n,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let c of m(o))!x.call(e,c)&&c!==n&&f(e,c,{get:()=>o[c],enumerable:!(r=u(o,c))||r.enumerable});return e};var C=e=>A(f({},"__esModule",{value:!0}),e);var L={};_(L,{createLogger:()=>d,definePackage:()=>w});module.exports=C(L);var p=require("@alwatr/dedupe"),t=require("@alwatr/platform-info");(0,p.definePackage)("@alwatr/logger","3.2.0");var y=t.platformInfo.development||(t.platformInfo.isCli?process.env.DEBUG!==void 0&&process.env.DEBUG!=="":typeof localStorage<"u"&&localStorage.getItem("debug")==="1"),b=t.platformInfo.isCli?["0;36","0;35","0;34","0;33","0;32"]:["#35b997","#f05561","#ee224a","#91c13e","#22af4b","#f0e995","#0fe995","#0f89ca","#08b9a5","#fee851","#ee573d","#f9df30","#1da2dc","#f05123","#ee2524"],i=0,$=()=>{let e=b[i];return i++,i>=b.length&&(i=0),e},s={scope:t.platformInfo.isCli?"\x1B[{{color}}m":"color: {{color}};",reset:t.platformInfo.isCli?"\x1B[0m":"color: inherit;"},l=t.platformInfo.isCli?"%s%s%s":"%c%s%c",h=e=>{e=e.trim();let o=e.charAt(0);return o!=="["&&o!=="{"&&o!=="<"&&(e="["+e+"]"),e},d=(e,o=y)=>{let n=$(),r=s.scope.replace("{{color}}",n);e=h(e);let c={debugMode:o,banner:t.platformInfo.isCli?console.log.bind(console,`\x1B[1;37;45m {{{ %s }}} ${s.reset}`):console.log.bind(console,"%c%s","font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;"),accident:t.platformInfo.isCli?console.warn.bind(console,`${r}⚠️
|
|
3
|
+
%s\x1B[33m.%s() Accident \`%s\`!${s.reset}`,e):console.warn.bind(console,"%c%s%c.%s() Accident `%s`!",r,e,s.reset),error:t.platformInfo.isCli?console.error.bind(console,`${r}❌
|
|
4
|
+
%s\x1B[31m.%s() Error \`%s\`${s.reset}
|
|
5
|
+
`,e):console.error.bind(console,"%c%s%c.%s() Error `%s`\n",r,e,s.reset)};return o?{...c,logProperty:console.debug.bind(console,l+".%s = %o;",r,e,s.reset),logMethod:console.debug.bind(console,l+".%s();",r,e,s.reset),logModule:console.debug.bind(console,l+"/%s.js;",r,e,s.reset),logMethodArgs:console.debug.bind(console,l+".%s(%o);",r,e,s.reset),logMethodFull:console.debug.bind(console,l+".%s(%o) => %o",r,e,s.reset),logOther:console.debug.bind(console,l,r,e,s.reset),incident:t.platformInfo.isCli?console.log.bind(console,`${r}🚸
|
|
6
|
+
%s${s.reset}.%s() Incident \`%s\`!${s.reset}`,e):console.log.bind(console,"%c%s%c.%s() Incident `%s`!",r,e,"color: orange;"),time:g=>console.time(e+"."+g+" duration time"),timeEnd:g=>console.timeEnd(e+"."+g+" duration time")}:c};var a=require("@alwatr/dedupe");function w(e,o="v?",n){let r=d(`{${e}}`,n);return r.logMethodArgs?.("define-package",{packageName:e,version:o}),(0,a.definePackage)(e,o),r}0&&(module.exports={createLogger,definePackage});
|
|
7
7
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts"],
|
|
4
|
-
"sourcesContent": ["import {definePackage} from '@alwatr/dedupe';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\ndefinePackage('@alwatr/logger', __package_version__);\n\
|
|
5
|
-
"mappings": ";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,
|
|
6
|
-
"names": ["main_exports", "__export", "createLogger", "
|
|
3
|
+
"sources": ["../src/main.ts", "../src/logger.ts", "../src/define-package.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './logger';\nexport * from './define-package';\nexport * from './type';\n", "import {definePackage} from '@alwatr/dedupe';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\ndefinePackage('@alwatr/logger', __package_version__);\n\nconst defaultDebugMode =\n platformInfo.development ||\n (platformInfo.isCli\n ? process.env.DEBUG !== undefined && process.env.DEBUG !== ''\n : typeof localStorage !== 'undefined' && localStorage.getItem('debug') === '1');\n\n/**\n * Color list storage for logger.\n */\nconst colorList = platformInfo.isCli\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted\n : [\n '#35b997',\n '#f05561',\n '#ee224a',\n '#91c13e',\n '#22af4b',\n '#f0e995',\n '#0fe995',\n '#0f89ca',\n '#08b9a5',\n '#fee851',\n '#ee573d',\n '#f9df30',\n '#1da2dc',\n '#f05123',\n '#ee2524',\n ];\n\nlet _colorIndex = 0;\nconst _getNextColor = (): string => {\n const color = colorList[_colorIndex];\n _colorIndex++;\n if (_colorIndex >= colorList.length) {\n _colorIndex = 0;\n }\n return color;\n};\n\nconst _style = {\n scope: platformInfo.isCli ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: platformInfo.isCli ? '\\x1b[0m' : 'color: inherit;',\n};\n\nconst _keySection = platformInfo.isCli ? '%s%s%s' : '%c%s%c';\n\nconst _sanitizeDomain = (domain: string): string => {\n domain = domain.trim();\n const first = domain.charAt(0);\n if (first !== '[' && first !== '{' && first !== '<') {\n domain = '[' + domain + ']';\n }\n return domain;\n};\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - **color** is optional and automatically select from internal fancy color list.\n * - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`\n *\n * Example:\n *\n * ```ts\n * import {createLogger} from 'https://esm.run/@alwatr/logger';\n * const logger = createLogger('logger/demo');\n * ```\n */\nexport const createLogger = (domain: string, debugMode = defaultDebugMode): AlwatrLogger => {\n const color = _getNextColor();\n const styleScope = _style.scope.replace('{{color}}', color);\n domain = _sanitizeDomain(domain);\n\n /**\n * Required logger object, accident, error always reported even when the devMode is false.\n */\n const requiredItems: AlwatrLogger = {\n debugMode,\n\n banner: platformInfo.isCli\n ? console.log.bind(console, `\\x1b[1;37;45m {{{ %s }}} ${_style.reset}`)\n : console.log.bind(\n console,\n '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;',\n ),\n\n accident: platformInfo.isCli\n ? console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${_style.reset}`, domain)\n : console.warn.bind(console, '%c%s%c.%s() Accident `%s`!', styleScope, domain, _style.reset),\n\n error: platformInfo.isCli\n ? console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${_style.reset}\\n`, domain)\n : console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, domain, _style.reset),\n };\n\n if (!debugMode) {\n return requiredItems;\n }\n // else\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, _keySection + '.%s = %o;', styleScope, domain, _style.reset),\n\n logMethod: console.debug.bind(console, _keySection + '.%s();', styleScope, domain, _style.reset),\n\n logModule: console.debug.bind(console, _keySection + '/%s.js;', styleScope, domain, _style.reset),\n\n logMethodArgs: console.debug.bind(console, _keySection + '.%s(%o);', styleScope, domain, _style.reset),\n\n logMethodFull: console.debug.bind(console, _keySection + '.%s(%o) => %o', styleScope, domain, _style.reset),\n\n logOther: console.debug.bind(console, _keySection, styleScope, domain, _style.reset),\n\n incident: platformInfo.isCli\n ? console.log.bind(console, `${styleScope}🚸\\n%s${_style.reset}.%s() Incident \\`%s\\`!${_style.reset}`, domain)\n : console.log.bind(console, '%c%s%c.%s() Incident `%s`!', styleScope, domain, 'color: orange;'),\n\n time: (label: string) => console.time(domain + '.' + label + ' duration time'),\n timeEnd: (label: string) => console.timeEnd(domain + '.' + label + ' duration time'),\n } as const;\n};\n", "import {definePackage as definePackage_} from '@alwatr/dedupe';\n\nimport {createLogger} from './logger.js';\n\nimport type {AlwatrLogger} from './type.js';\n\n/**\n * Global define package for managing package versions to prevent version conflicts and return package level logger.\n * @param packageName package name including scope. e.g. `@scope/package-name`\n * @param version package version (optional)\n * @returns AlwatrLogger for the package\n *\n * @example\n * ```typescript\n * const logger = definePackage('@scope/package-name', __package_version__);\n *\n * logger.logMethodArgs?.('myMethod', {a, b});\n * ```\n */\nexport function definePackage(packageName: string, version = 'v?', debugMode?: boolean): AlwatrLogger {\n const logger = createLogger(`{${packageName}}`, debugMode);\n logger.logMethodArgs?.('define-package', {packageName, version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AAqBC,EAAU,KAAMC,EAAmC,CACpG,IAAMC,EAASC,EAAa,IAAIJ,CAAW,IAAKE,CAAS,EACzD,OAAAC,EAAO,gBAAgB,iBAAkB,CAAC,YAAAH,EAAa,QAAAC,CAAO,CAAC,KAC/D,EAAAI,eAAeL,EAAaC,CAAO,EAC5BE,CACT",
|
|
6
|
+
"names": ["main_exports", "__export", "createLogger", "definePackage", "__toCommonJS", "import_dedupe", "import_platform_info", "defaultDebugMode", "colorList", "_colorIndex", "_getNextColor", "color", "_style", "_keySection", "_sanitizeDomain", "domain", "first", "createLogger", "debugMode", "styleScope", "requiredItems", "label", "import_dedupe", "definePackage", "packageName", "version", "debugMode", "logger", "createLogger", "definePackage_"]
|
|
7
7
|
}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
* Create a logger function for fancy console debug with custom scope.
|
|
5
|
-
*
|
|
6
|
-
* - **color** is optional and automatically select from internal fancy color list.
|
|
7
|
-
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
8
|
-
*
|
|
9
|
-
* Example:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* import {createLogger} from 'https://esm.run/@alwatr/logger';
|
|
13
|
-
* const logger = createLogger('logger/demo');
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare const createLogger: (domain: string, debugMode_?: boolean) => AlwatrLogger;
|
|
1
|
+
export * from './logger';
|
|
2
|
+
export * from './define-package';
|
|
3
|
+
export * from './type';
|
|
17
4
|
//# sourceMappingURL=main.d.ts.map
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC"}
|
package/dist/main.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* @alwatr/logger v3.
|
|
2
|
-
import{definePackage as b}from"@alwatr/dedupe";import{platformInfo as
|
|
3
|
-
%s\x1B[33m.%s() Accident \`%s\`!${
|
|
4
|
-
%s\x1B[31m.%s() Error \`%s\`${
|
|
5
|
-
`,e):console.error.bind(console,"%c%s%c.%s() Error `%s`\n",
|
|
6
|
-
%s${
|
|
1
|
+
/* @alwatr/logger v3.2.0 */
|
|
2
|
+
import{definePackage as b}from"@alwatr/dedupe";import{platformInfo as s}from"@alwatr/platform-info";b("@alwatr/logger","3.2.0");var p=s.development||(s.isCli?process.env.DEBUG!==void 0&&process.env.DEBUG!=="":typeof localStorage<"u"&&localStorage.getItem("debug")==="1"),f=s.isCli?["0;36","0;35","0;34","0;33","0;32"]:["#35b997","#f05561","#ee224a","#91c13e","#22af4b","#f0e995","#0fe995","#0f89ca","#08b9a5","#fee851","#ee573d","#f9df30","#1da2dc","#f05123","#ee2524"],c=0,a=()=>{let e=f[c];return c++,c>=f.length&&(c=0),e},r={scope:s.isCli?"\x1B[{{color}}m":"color: {{color}};",reset:s.isCli?"\x1B[0m":"color: inherit;"},n=s.isCli?"%s%s%s":"%c%s%c",u=e=>{e=e.trim();let t=e.charAt(0);return t!=="["&&t!=="{"&&t!=="<"&&(e="["+e+"]"),e},d=(e,t=p)=>{let l=a(),o=r.scope.replace("{{color}}",l);e=u(e);let g={debugMode:t,banner:s.isCli?console.log.bind(console,`\x1B[1;37;45m {{{ %s }}} ${r.reset}`):console.log.bind(console,"%c%s","font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;"),accident:s.isCli?console.warn.bind(console,`${o}⚠️
|
|
3
|
+
%s\x1B[33m.%s() Accident \`%s\`!${r.reset}`,e):console.warn.bind(console,"%c%s%c.%s() Accident `%s`!",o,e,r.reset),error:s.isCli?console.error.bind(console,`${o}❌
|
|
4
|
+
%s\x1B[31m.%s() Error \`%s\`${r.reset}
|
|
5
|
+
`,e):console.error.bind(console,"%c%s%c.%s() Error `%s`\n",o,e,r.reset)};return t?{...g,logProperty:console.debug.bind(console,n+".%s = %o;",o,e,r.reset),logMethod:console.debug.bind(console,n+".%s();",o,e,r.reset),logModule:console.debug.bind(console,n+"/%s.js;",o,e,r.reset),logMethodArgs:console.debug.bind(console,n+".%s(%o);",o,e,r.reset),logMethodFull:console.debug.bind(console,n+".%s(%o) => %o",o,e,r.reset),logOther:console.debug.bind(console,n,o,e,r.reset),incident:s.isCli?console.log.bind(console,`${o}🚸
|
|
6
|
+
%s${r.reset}.%s() Incident \`%s\`!${r.reset}`,e):console.log.bind(console,"%c%s%c.%s() Incident `%s`!",o,e,"color: orange;"),time:i=>console.time(e+"."+i+" duration time"),timeEnd:i=>console.timeEnd(e+"."+i+" duration time")}:g};import{definePackage as m}from"@alwatr/dedupe";function $(e,t="v?",l){let o=d(`{${e}}`,l);return o.logMethodArgs?.("define-package",{packageName:e,version:t}),m(e,t),o}export{d as createLogger,$ as definePackage};
|
|
7
7
|
//# sourceMappingURL=main.mjs.map
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import {definePackage} from '@alwatr/dedupe';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\ndefinePackage('@alwatr/logger', __package_version__);\n\
|
|
5
|
-
"mappings": ";AAAA,OAAQ,iBAAAA,MAAoB,iBAC5B,OAAQ,gBAAAC,MAAmB,wBAI3BD,EAAc,iBAAkB,OAAmB,
|
|
6
|
-
"names": ["definePackage", "platformInfo", "
|
|
3
|
+
"sources": ["../src/logger.ts", "../src/define-package.ts"],
|
|
4
|
+
"sourcesContent": ["import {definePackage} from '@alwatr/dedupe';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\ndefinePackage('@alwatr/logger', __package_version__);\n\nconst defaultDebugMode =\n platformInfo.development ||\n (platformInfo.isCli\n ? process.env.DEBUG !== undefined && process.env.DEBUG !== ''\n : typeof localStorage !== 'undefined' && localStorage.getItem('debug') === '1');\n\n/**\n * Color list storage for logger.\n */\nconst colorList = platformInfo.isCli\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted\n : [\n '#35b997',\n '#f05561',\n '#ee224a',\n '#91c13e',\n '#22af4b',\n '#f0e995',\n '#0fe995',\n '#0f89ca',\n '#08b9a5',\n '#fee851',\n '#ee573d',\n '#f9df30',\n '#1da2dc',\n '#f05123',\n '#ee2524',\n ];\n\nlet _colorIndex = 0;\nconst _getNextColor = (): string => {\n const color = colorList[_colorIndex];\n _colorIndex++;\n if (_colorIndex >= colorList.length) {\n _colorIndex = 0;\n }\n return color;\n};\n\nconst _style = {\n scope: platformInfo.isCli ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: platformInfo.isCli ? '\\x1b[0m' : 'color: inherit;',\n};\n\nconst _keySection = platformInfo.isCli ? '%s%s%s' : '%c%s%c';\n\nconst _sanitizeDomain = (domain: string): string => {\n domain = domain.trim();\n const first = domain.charAt(0);\n if (first !== '[' && first !== '{' && first !== '<') {\n domain = '[' + domain + ']';\n }\n return domain;\n};\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - **color** is optional and automatically select from internal fancy color list.\n * - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`\n *\n * Example:\n *\n * ```ts\n * import {createLogger} from 'https://esm.run/@alwatr/logger';\n * const logger = createLogger('logger/demo');\n * ```\n */\nexport const createLogger = (domain: string, debugMode = defaultDebugMode): AlwatrLogger => {\n const color = _getNextColor();\n const styleScope = _style.scope.replace('{{color}}', color);\n domain = _sanitizeDomain(domain);\n\n /**\n * Required logger object, accident, error always reported even when the devMode is false.\n */\n const requiredItems: AlwatrLogger = {\n debugMode,\n\n banner: platformInfo.isCli\n ? console.log.bind(console, `\\x1b[1;37;45m {{{ %s }}} ${_style.reset}`)\n : console.log.bind(\n console,\n '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;',\n ),\n\n accident: platformInfo.isCli\n ? console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${_style.reset}`, domain)\n : console.warn.bind(console, '%c%s%c.%s() Accident `%s`!', styleScope, domain, _style.reset),\n\n error: platformInfo.isCli\n ? console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${_style.reset}\\n`, domain)\n : console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, domain, _style.reset),\n };\n\n if (!debugMode) {\n return requiredItems;\n }\n // else\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, _keySection + '.%s = %o;', styleScope, domain, _style.reset),\n\n logMethod: console.debug.bind(console, _keySection + '.%s();', styleScope, domain, _style.reset),\n\n logModule: console.debug.bind(console, _keySection + '/%s.js;', styleScope, domain, _style.reset),\n\n logMethodArgs: console.debug.bind(console, _keySection + '.%s(%o);', styleScope, domain, _style.reset),\n\n logMethodFull: console.debug.bind(console, _keySection + '.%s(%o) => %o', styleScope, domain, _style.reset),\n\n logOther: console.debug.bind(console, _keySection, styleScope, domain, _style.reset),\n\n incident: platformInfo.isCli\n ? console.log.bind(console, `${styleScope}🚸\\n%s${_style.reset}.%s() Incident \\`%s\\`!${_style.reset}`, domain)\n : console.log.bind(console, '%c%s%c.%s() Incident `%s`!', styleScope, domain, 'color: orange;'),\n\n time: (label: string) => console.time(domain + '.' + label + ' duration time'),\n timeEnd: (label: string) => console.timeEnd(domain + '.' + label + ' duration time'),\n } as const;\n};\n", "import {definePackage as definePackage_} from '@alwatr/dedupe';\n\nimport {createLogger} from './logger.js';\n\nimport type {AlwatrLogger} from './type.js';\n\n/**\n * Global define package for managing package versions to prevent version conflicts and return package level logger.\n * @param packageName package name including scope. e.g. `@scope/package-name`\n * @param version package version (optional)\n * @returns AlwatrLogger for the package\n *\n * @example\n * ```typescript\n * const logger = definePackage('@scope/package-name', __package_version__);\n *\n * logger.logMethodArgs?.('myMethod', {a, b});\n * ```\n */\nexport function definePackage(packageName: string, version = 'v?', debugMode?: boolean): AlwatrLogger {\n const logger = createLogger(`{${packageName}}`, debugMode);\n logger.logMethodArgs?.('define-package', {packageName, version});\n definePackage_(packageName, version);\n return logger;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAQ,iBAAAA,MAAoB,iBAC5B,OAAQ,gBAAAC,MAAmB,wBAI3BD,EAAc,iBAAkB,OAAmB,EAEnD,IAAME,EACJD,EAAa,cACZA,EAAa,MACV,QAAQ,IAAI,QAAU,QAAa,QAAQ,IAAI,QAAU,GACzD,OAAO,aAAiB,KAAe,aAAa,QAAQ,OAAO,IAAM,KAKzEE,EAAYF,EAAa,MAC3B,CAAC,OAAQ,OAAQ,OAAQ,OAAQ,MAAM,EACvC,CACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,SACF,EAEEG,EAAc,EACZC,EAAgB,IAAc,CAClC,IAAMC,EAAQH,EAAUC,CAAW,EACnC,OAAAA,IACIA,GAAeD,EAAU,SAC3BC,EAAc,GAETE,CACT,EAEMC,EAAS,CACb,MAAON,EAAa,MAAQ,kBAAoB,oBAChD,MAAOA,EAAa,MAAQ,UAAY,iBAC1C,EAEMO,EAAcP,EAAa,MAAQ,SAAW,SAE9CQ,EAAmBC,GAA2B,CAClDA,EAASA,EAAO,KAAK,EACrB,IAAMC,EAAQD,EAAO,OAAO,CAAC,EAC7B,OAAIC,IAAU,KAAOA,IAAU,KAAOA,IAAU,MAC9CD,EAAS,IAAMA,EAAS,KAEnBA,CACT,EAea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P,EAAO,KAAK,yBAAyBA,EAAO,KAAK,GAAIG,CAAM,EAC3G,QAAQ,IAAI,KAAK,QAAS,6BAA8BI,EAAYJ,EAAQ,gBAAgB,EAEhG,KAAOM,GAAkB,QAAQ,KAAKN,EAAS,IAAMM,EAAQ,gBAAgB,EAC7E,QAAUA,GAAkB,QAAQ,QAAQN,EAAS,IAAMM,EAAQ,gBAAgB,CACrF,EAxBSD,CAyBX,ECjIA,OAAQ,iBAAiBE,MAAqB,iBAmBvC,SAASC,EAAcC,EAAqBC,EAAU,KAAMC,EAAmC,CACpG,IAAMC,EAASC,EAAa,IAAIJ,CAAW,IAAKE,CAAS,EACzD,OAAAC,EAAO,gBAAgB,iBAAkB,CAAC,YAAAH,EAAa,QAAAC,CAAO,CAAC,EAC/DH,EAAeE,EAAaC,CAAO,EAC5BE,CACT",
|
|
6
|
+
"names": ["definePackage", "platformInfo", "defaultDebugMode", "colorList", "_colorIndex", "_getNextColor", "color", "_style", "_keySection", "_sanitizeDomain", "domain", "first", "createLogger", "debugMode", "styleScope", "requiredItems", "label", "definePackage_", "definePackage", "packageName", "version", "debugMode", "logger", "createLogger"]
|
|
7
7
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the AlwatrLogger interface.
|
|
3
|
+
* The AlwatrLogger provides methods for logging various types of information.
|
|
4
|
+
*/
|
|
1
5
|
export interface AlwatrLogger {
|
|
6
|
+
/**
|
|
7
|
+
* Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
|
|
8
|
+
*/
|
|
9
|
+
debugMode: boolean;
|
|
2
10
|
/**
|
|
3
11
|
* `console.debug` property change.
|
|
4
12
|
*
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"type.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;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/logger",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@alwatr/dedupe": "^0.1
|
|
70
|
-
"@alwatr/platform-info": "^1.1.
|
|
69
|
+
"@alwatr/dedupe": "^1.0.1",
|
|
70
|
+
"@alwatr/platform-info": "^1.1.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@alwatr/nano-build": "^1.3.0",
|
|
74
74
|
"@alwatr/prettier-config": "^1.0.4",
|
|
75
75
|
"@alwatr/tsconfig-base": "^1.1.0",
|
|
76
|
-
"@types/node": "^20.10.
|
|
76
|
+
"@types/node": "^20.10.7",
|
|
77
77
|
"typescript": "^5.3.3"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "5bbfd315996b6052e35b42b2d00b9bef1249ab16"
|
|
80
80
|
}
|