@alwatr/logger 0.24.0 → 0.25.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 CHANGED
@@ -3,6 +3,18 @@
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
+ # [0.25.0](https://github.com/AliMD/alwatr/compare/v0.24.1...v0.25.0) (2022-12-07)
7
+
8
+ ### Features
9
+
10
+ - **logger:** log incident in production mode ([c9b6c56](https://github.com/AliMD/alwatr/commit/c9b6c56182750444b1cced3343b02eea6a9f24c5))
11
+
12
+ ## [0.24.1](https://github.com/AliMD/alwatr/compare/v0.24.0...v0.24.1) (2022-12-01)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **logger:** optimize for browserify builds ([7afdc1c](https://github.com/AliMD/alwatr/commit/7afdc1cb5baf9b66dedcdc251595c02a79a163b2))
17
+
6
18
  # [0.24.0](https://github.com/AliMD/alwatr/compare/v0.23.0...v0.24.0) (2022-11-28)
7
19
 
8
20
  ### Bug Fixes
package/logger.d.ts CHANGED
@@ -24,5 +24,5 @@ export declare const style: {
24
24
  * const logger = createLogger('logger/demo');
25
25
  * ```
26
26
  */
27
- export declare const createLogger: (scope: string, color?: string, debug?: boolean) => AlwatrLogger;
27
+ export declare const createLogger: (scope: string, color?: string | null, debug?: boolean) => AlwatrLogger;
28
28
  //# sourceMappingURL=logger.d.ts.map
package/logger.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,CAAC;AAItB;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;GAA0C,CAAC;AA8E5E,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UACd,MAAM,UACN,MAAM,sBAEd,YA6DF,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,CAAC;AAItB;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;GAA0C,CAAC;AA8E5E,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,UAAU,MAAM,GAAG,IAAI,UAAU,OAAO,KAAG,YA8DpF,CAAC"}
package/logger.js CHANGED
@@ -1,9 +1,10 @@
1
+ var _a, _b, _c, _d, _e, _f;
1
2
  const isBrowser = typeof process === 'undefined';
2
3
  /**
3
4
  * Define `globalThis.Alwatr.registeredList`
4
5
  */
5
- export const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];
6
- globalThis.Alwatr ?? (globalThis.Alwatr = { registeredList: alwatrRegisteredList });
6
+ export const alwatrRegisteredList = ((_a = globalThis.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
7
+ (_b = globalThis.Alwatr) !== null && _b !== void 0 ? _b : (globalThis.Alwatr = { registeredList: alwatrRegisteredList });
7
8
  alwatrRegisteredList.push({
8
9
  name: '@alwatr/logger',
9
10
  version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
@@ -40,10 +41,10 @@ const getNextColor = () => {
40
41
  return color;
41
42
  };
42
43
  const debugString = isBrowser
43
- ? globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim()
44
- : globalThis.process?.env?.ALWATR_DEBUG?.trim();
44
+ ? (_d = (_c = globalThis.localStorage) === null || _c === void 0 ? void 0 : _c.getItem('ALWATR_DEBUG')) === null || _d === void 0 ? void 0 : _d.trim()
45
+ : (_f = (_e = process === null || process === void 0 ? void 0 : process.env) === null || _e === void 0 ? void 0 : _e.ALWATR_DEBUG) === null || _f === void 0 ? void 0 : _f.trim();
45
46
  const getDebugState = (scope) => {
46
- if (debugString == null && isBrowser === false && globalThis.process.env.NODE_ENV !== 'production') {
47
+ if (debugString == null && isBrowser === false && process.env.NODE_ENV !== 'production') {
47
48
  return true;
48
49
  }
49
50
  // prettier-ignore
@@ -80,8 +81,10 @@ export const style = {
80
81
  * const logger = createLogger('logger/demo');
81
82
  * ```
82
83
  */
83
- export const createLogger = (scope, color = getNextColor(), debug = getDebugState(scope)) => {
84
+ export const createLogger = (scope, color, debug) => {
84
85
  scope = scope.trim();
86
+ color !== null && color !== void 0 ? color : (color = getNextColor());
87
+ debug !== null && debug !== void 0 ? debug : (debug = getDebugState(scope));
85
88
  const first = scope.charAt(0);
86
89
  if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {
87
90
  scope = '[' + scope + ']';
@@ -97,6 +100,9 @@ export const createLogger = (scope, color = getNextColor(), debug = getDebugStat
97
100
  debug,
98
101
  color,
99
102
  scope,
103
+ incident: isBrowser
104
+ ? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')
105
+ : console.log.bind(console, `${styleScope}🚸\n%s${style.reset}.%s() Incident \`%s\` %s!${style.reset}`, scope),
100
106
  accident: isBrowser
101
107
  ? console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, scope, style.reset)
102
108
  : console.warn.bind(console, `${styleScope}⚠️\n%s\x1b[33m.%s() Accident \`%s\` %s!${style.reset}`, scope),
@@ -111,7 +117,6 @@ export const createLogger = (scope, color = getNextColor(), debug = getDebugStat
111
117
  logMethod: empty,
112
118
  logMethodArgs: empty,
113
119
  logMethodFull: empty,
114
- incident: empty,
115
120
  logOther: empty,
116
121
  };
117
122
  }
@@ -122,9 +127,6 @@ export const createLogger = (scope, color = getNextColor(), debug = getDebugStat
122
127
  logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),
123
128
  logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),
124
129
  logMethodFull: console.debug.bind(console, keySection + '.%s(%o) => %o', styleScope, scope, style.reset),
125
- incident: isBrowser
126
- ? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')
127
- : console.log.bind(console, `${styleScope}🚸\n%s${style.reset}.%s() Incident \`%s\` %s!${style.reset}`, scope),
128
130
  logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),
129
131
  };
130
132
  };
package/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAGA,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC,MAAM,EAAE,cAAc,IAAI,EAAE,CAAC;AAC5E,UAAU,CAAC,MAAM,KAAjB,UAAU,CAAC,MAAM,GAAK,EAAC,cAAc,EAAE,oBAAoB,EAAC,EAAC;AAE7D,oBAAoB,CAAC,IAAI,CAAC;IACxB,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,oBAAoB,EAAE,mDAAmD;CACnF,CAAC,CAAC;AAEH;;GAEG;AACH,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,MAAM,SAAS,GAAG,SAAS;IACzB,CAAC,CAAC;QACA,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;KACV;IACD,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,wBAAwB;AAEtE,MAAM,YAAY,GAAG,GAAW,EAAE;IAChC,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAA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,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAEnG,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAExG,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;KAClF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {AlwatrLogger} from './type.js';\nexport {AlwatrLogger};\n\nconst isBrowser = typeof process === 'undefined';\n\n/**\n * Define `globalThis.Alwatr.registeredList`\n */\nexport const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];\nglobalThis.Alwatr ??= {registeredList: alwatrRegisteredList};\n\nalwatrRegisteredList.push({\n name: '@alwatr/logger',\n version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.\n});\n\n/**\n * Color list storage for logger.\n */\nlet colorIndex = 0;\nconst colorList = isBrowser\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 : ['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted\n\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 debugString = isBrowser\n ? globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim()\n : process?.env?.ALWATR_DEBUG?.trim();\n\nconst getDebugState = (scope: string): boolean => {\n if (debugString == null && isBrowser === false && process.env.NODE_ENV !== 'production') {\n return true;\n }\n\n // prettier-ignore\n if (\n debugString == null ||\n debugString == ''\n ) {\n return false;\n }\n\n // prettier-ignore\n if (\n debugString === scope ||\n debugString === '*' ||\n (\n debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`\n scope.indexOf(debugString.replaceAll('*', '')) !== -1\n ) ||\n (\n debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`\n scope.indexOf(debugString.replaceAll('*', '')) === 0\n )\n ) {\n return true;\n }\n\n // else\n return false;\n};\n\nexport const style = {\n scope: isBrowser ? 'color: {{color}};' : '\\x1b[{{color}}m',\n reset: isBrowser ? 'color: inherit;' : '\\x1b[0m',\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 = (scope: string, color?: string | null, debug?: boolean): AlwatrLogger => {\n scope = scope.trim();\n color ??= getNextColor();\n debug ??= getDebugState(scope);\n\n const first = scope.charAt(0);\n if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {\n scope = '[' + scope + ']';\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const empty = (): void => {};\n\n const keySection = isBrowser ? '%c%s%c' : '%s%s%s';\n const styleScope = style.scope.replaceAll('{{color}}', color);\n\n /**\n * Required logger object, accident, error always reported even when the debug is false.\n */\n const requiredItems = {\n debug,\n color,\n scope,\n\n incident: isBrowser\n ? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')\n : console.log.bind(console, `${styleScope}🚸\\n%s${style.reset}.%s() Incident \\`%s\\` %s!${style.reset}`, scope),\n\n accident: isBrowser\n ? console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, scope, style.reset)\n : console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\` %s!${style.reset}`, scope),\n\n error: isBrowser\n ? console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, scope, style.reset)\n : console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style.reset}\\n`, scope),\n };\n\n if (!debug) {\n return {\n ...requiredItems,\n logProperty: empty,\n logMethod: empty,\n logMethodArgs: empty,\n logMethodFull: empty,\n logOther: empty,\n };\n }\n\n // else if debug is true for this scope\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),\n\n logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),\n\n logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),\n\n logMethodFull: console.debug.bind(console, keySection + '.%s(%o) => %o', styleScope, scope, style.reset),\n\n logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/logger",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
5
5
  "keywords": [
6
6
  "log",
@@ -34,5 +34,5 @@
34
34
  "dependencies": {
35
35
  "tslib": "~2.4.1"
36
36
  },
37
- "gitHead": "4240c5bbb8b7552e9adfdc7e914c7b09b74cd206"
37
+ "gitHead": "03cf3c146f075309527bcf1e762a589696d0ce1d"
38
38
  }
package/type.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable no-var */\nexport interface GlobalAlwatr {\n registeredList: Array<{\n name: string;\n version: string;\n }>;\n}\n\ndeclare global {\n var Alwatr: GlobalAlwatr;\n var ALWATR_DEBUG: string | undefined;\n\n /**\n * @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!\n */\n interface CallableFunction {\n bind<T, A0, A1, A2, A3, A4, A extends unknown[], R>(\n this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, arg4: A4, ...args: A) => R,\n thisArg: T,\n arg0: A0,\n arg1: A1,\n arg2: A2,\n arg3: A3,\n arg4: A4\n ): (...args: A) => R;\n }\n}\n\nexport interface AlwatrLogger {\n /**\n * Debug state for current scope base on localStorage `ALWATR_LOG` pattern.\n */\n readonly debug: boolean;\n\n /**\n * Color picked for current scope.\n */\n readonly color: string;\n\n /**\n * Scope defined for this logger.\n */\n readonly scope: string;\n\n /**\n * `console.debug` property change.\n *\n * Example:\n *\n * ```ts\n * logger.logProperty('name', 'ali');\n * ```\n */\n logProperty(property: string, value: unknown): void;\n\n /**\n * `console.debug` function or method calls.\n *\n * Example:\n *\n * ```ts\n * function myMethod () {\n * logger.logMethod('myMethod');\n * }\n * ```\n */\n logMethod(method: string): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function myMethod (a: number, b: number) {\n * logger.logMethodArgs('myMethod', {a, b});\n * }\n * ```\n */\n logMethodArgs(method: string, args: Record<string, unknown> | string | number | boolean): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function add (a: number, b: number): number {\n * const result = a + b;\n * logger.logMethodFull('add', {a, b}, result);\n * return result;\n * }\n * ```\n */\n logMethodFull(method: string, args: Record<string, unknown> | string | number | boolean, result: unknown): void;\n\n /**\n * `console.log` an event or expected accident. (not warn or error)\n *\n * Example:\n *\n * ```ts\n * logger.incident('fetch', 'abort_signal', 'aborted signal received', {url: '/test.json'});\n * ```\n */\n incident(method: string, code: string, desc: string, ...args: unknown[]): void;\n\n /**\n * `console.warn` an unexpected accident or error that you handled.\n *\n * Example:\n *\n * ```ts\n * logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {url: '/test.json'});\n * ```\n */\n accident(method: string, code: string, desc: string, ...args: unknown[]): void;\n\n /**\n * `console.error` an unexpected error.\n *\n * Example:\n *\n * ```ts\n * try {\n * ...\n * }\n * catch (err) {\n * logger.error('myMethod', 'error_code', (err as Error).stack || err, {a: 1, b: 2});\n * }\n * ```\n */\n error(method: string, code: string, errorStack: string | unknown, ...args: unknown[]): void;\n\n /**\n * Simple `console.debug` with styled scope.\n *\n * Example:\n *\n * ```ts\n * logger.logOther('foo:', 'bar', {a: 1});\n * ```\n */\n logOther(...args: unknown[]): void;\n}\n"]}