@xylabs/logger 2.13.4 → 2.13.5

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.
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -20,10 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- LoggerStub: () => LoggerStub
23
+ getFunctionName: () => getFunctionName
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/Logger.ts
28
- var LoggerStub = 1;
28
+ var import_error = require("@xylabs/error");
29
+ var getFunctionName = (depth = 2) => {
30
+ try {
31
+ throw Error();
32
+ } catch (ex) {
33
+ return (0, import_error.handleError)(ex, (error) => {
34
+ let newIndex = void 0;
35
+ const stackParts = error.stack?.split("\n")[depth].split(" ");
36
+ const funcName = stackParts?.find((item, index) => {
37
+ if (item.length > 0 && item !== "at") {
38
+ if (item === "new") {
39
+ newIndex = index;
40
+ }
41
+ return item;
42
+ }
43
+ }) ?? "<unknown>";
44
+ return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName;
45
+ });
46
+ }
47
+ };
29
48
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Logger.ts"],"sourcesContent":["export * from './Logger'\n","export type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\n//to satisfy export\nexport const LoggerStub = 1\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,IAAM,aAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Logger.ts"],"sourcesContent":["export * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw Error()\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined = undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,MAAM;AAAA,EACd,SAAS,IAAI;AACX,eAAO,0BAAY,IAAI,CAAC,UAAU;AAChC,UAAI,WAA+B;AACnC,YAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AAC5D,YAAM,WACJ,YAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC,KAAK;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,aAAa,WAAW,CAAC,CAAC,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,6 +1,25 @@
1
1
  // src/Logger.ts
2
- var LoggerStub = 1;
2
+ import { handleError } from "@xylabs/error";
3
+ var getFunctionName = (depth = 2) => {
4
+ try {
5
+ throw Error();
6
+ } catch (ex) {
7
+ return handleError(ex, (error) => {
8
+ let newIndex = void 0;
9
+ const stackParts = error.stack?.split("\n")[depth].split(" ");
10
+ const funcName = stackParts?.find((item, index) => {
11
+ if (item.length > 0 && item !== "at") {
12
+ if (item === "new") {
13
+ newIndex = index;
14
+ }
15
+ return item;
16
+ }
17
+ }) ?? "<unknown>";
18
+ return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName;
19
+ });
20
+ }
21
+ };
3
22
  export {
4
- LoggerStub
23
+ getFunctionName
5
24
  };
6
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Logger.ts"],"sourcesContent":["export type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\n//to satisfy export\nexport const LoggerStub = 1\n"],"mappings":";AAeO,IAAM,aAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/Logger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw Error()\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined = undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,MAAM;AAAA,EACd,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AAChC,UAAI,WAA+B;AACnC,YAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AAC5D,YAAM,WACJ,YAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC,KAAK;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,aAAa,WAAW,CAAC,CAAC,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -0,0 +1,14 @@
1
+ import { Logger } from './Logger';
2
+ export declare class IdLogger implements Logger {
3
+ private _id?;
4
+ private _logger;
5
+ constructor(logger: Logger, id?: () => string);
6
+ set id(id: string);
7
+ debug(message?: unknown): void;
8
+ error(message?: unknown): void;
9
+ info(message?: unknown): void;
10
+ log(message?: unknown): void;
11
+ warn(message?: unknown): void;
12
+ private generate;
13
+ }
14
+ //# sourceMappingURL=IdLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAKjB"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -10,5 +10,5 @@ export interface Logger {
10
10
  log: LogFunction;
11
11
  warn: LogFunction;
12
12
  }
13
- export declare const LoggerStub = 1;
13
+ export declare const getFunctionName: (depth?: number) => string;
14
14
  //# sourceMappingURL=Logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAGD,eAAO,MAAM,UAAU,IAAI,CAAA"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
@@ -20,14 +20,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- LoggerStub: () => LoggerStub
23
+ getFunctionName: () => getFunctionName
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/Logger.ts
28
- var LoggerStub = 1;
28
+ var import_error = require("@xylabs/error");
29
+ var getFunctionName = (depth = 2) => {
30
+ try {
31
+ throw Error();
32
+ } catch (ex) {
33
+ return (0, import_error.handleError)(ex, (error) => {
34
+ var _a;
35
+ let newIndex = void 0;
36
+ const stackParts = (_a = error.stack) == null ? void 0 : _a.split("\n")[depth].split(" ");
37
+ const funcName = (stackParts == null ? void 0 : stackParts.find((item, index) => {
38
+ if (item.length > 0 && item !== "at") {
39
+ if (item === "new") {
40
+ newIndex = index;
41
+ }
42
+ return item;
43
+ }
44
+ })) ?? "<unknown>";
45
+ return newIndex ? `${funcName} ${stackParts == null ? void 0 : stackParts[newIndex + 1]}` : funcName;
46
+ });
47
+ }
48
+ };
29
49
  // Annotate the CommonJS export names for ESM import in node:
30
50
  0 && (module.exports = {
31
- LoggerStub
51
+ getFunctionName
32
52
  });
33
53
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Logger.ts"],"sourcesContent":["export * from './Logger'\n","export type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\n//to satisfy export\nexport const LoggerStub = 1\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,IAAM,aAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Logger.ts"],"sourcesContent":["export * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw Error()\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined = undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,MAAM;AAAA,EACd,SAAS,IAAI;AACX,eAAO,0BAAY,IAAI,CAAC,UAAU;AApBtC;AAqBM,UAAI,WAA+B;AACnC,YAAM,cAAa,WAAM,UAAN,mBAAa,MAAM,MAAM,OAAO,MAAM;AACzD,YAAM,YACJ,yCAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,OAAM;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,yCAAa,WAAW,EAAE,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,6 +1,26 @@
1
1
  // src/Logger.ts
2
- var LoggerStub = 1;
2
+ import { handleError } from "@xylabs/error";
3
+ var getFunctionName = (depth = 2) => {
4
+ try {
5
+ throw Error();
6
+ } catch (ex) {
7
+ return handleError(ex, (error) => {
8
+ var _a;
9
+ let newIndex = void 0;
10
+ const stackParts = (_a = error.stack) == null ? void 0 : _a.split("\n")[depth].split(" ");
11
+ const funcName = (stackParts == null ? void 0 : stackParts.find((item, index) => {
12
+ if (item.length > 0 && item !== "at") {
13
+ if (item === "new") {
14
+ newIndex = index;
15
+ }
16
+ return item;
17
+ }
18
+ })) ?? "<unknown>";
19
+ return newIndex ? `${funcName} ${stackParts == null ? void 0 : stackParts[newIndex + 1]}` : funcName;
20
+ });
21
+ }
22
+ };
3
23
  export {
4
- LoggerStub
24
+ getFunctionName
5
25
  };
6
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Logger.ts"],"sourcesContent":["export type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\n//to satisfy export\nexport const LoggerStub = 1\n"],"mappings":";AAeO,IAAM,aAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/Logger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: unknown) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw Error()\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined = undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,MAAM;AAAA,EACd,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AApBtC;AAqBM,UAAI,WAA+B;AACnC,YAAM,cAAa,WAAM,UAAN,mBAAa,MAAM,MAAM,OAAO,MAAM;AACzD,YAAM,YACJ,yCAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,OAAM;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,yCAAa,WAAW,EAAE,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;","names":[]}
package/package.json CHANGED
@@ -10,6 +10,9 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "description": "Primary SDK for using XYO Protocol 2.0",
13
+ "dependencies": {
14
+ "@xylabs/error": "~2.13.5"
15
+ },
13
16
  "devDependencies": {
14
17
  "@xylabs/ts-scripts-yarn3": "^3.1.21",
15
18
  "@xylabs/tsconfig": "^3.1.21",
@@ -53,6 +56,6 @@
53
56
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
54
57
  },
55
58
  "sideEffects": false,
56
- "version": "2.13.4",
59
+ "version": "2.13.5",
57
60
  "type": "module"
58
61
  }
@@ -0,0 +1,37 @@
1
+ import { getFunctionName, Logger } from './Logger'
2
+
3
+ export class IdLogger implements Logger {
4
+ private _id?: () => string
5
+ private _logger: Logger
6
+
7
+ constructor(logger: Logger, id?: () => string) {
8
+ this._logger = logger
9
+ this._id = id
10
+ }
11
+
12
+ set id(id: string) {
13
+ this._id = () => id
14
+ }
15
+
16
+ debug(message?: unknown) {
17
+ this._logger?.debug(this.generate(message, getFunctionName(3)))
18
+ }
19
+ error(message?: unknown) {
20
+ this._logger?.error(this.generate(message, getFunctionName(3)))
21
+ }
22
+ info(message?: unknown) {
23
+ this._logger?.info(this.generate(message, getFunctionName(3)))
24
+ }
25
+ log(message?: unknown) {
26
+ this._logger?.log(this.generate(message, getFunctionName(3)))
27
+ }
28
+ warn(message?: unknown) {
29
+ this._logger?.warn(this.generate(message, getFunctionName(3)))
30
+ }
31
+
32
+ private generate(message?: unknown, tag?: string) {
33
+ return `${tag} ${this._id ? `[${this._id}] ` : ''}${
34
+ typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`
35
+ }`
36
+ }
37
+ }
package/src/Logger.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { handleError } from '@xylabs/error'
2
+
1
3
  export type LogFunction = (message?: unknown) => void
2
4
 
3
5
  /**
@@ -12,5 +14,24 @@ export interface Logger {
12
14
  warn: LogFunction
13
15
  }
14
16
 
15
- //to satisfy export
16
- export const LoggerStub = 1
17
+ export const getFunctionName = (depth = 2) => {
18
+ try {
19
+ throw Error()
20
+ } catch (ex) {
21
+ return handleError(ex, (error) => {
22
+ let newIndex: number | undefined = undefined
23
+ const stackParts = error.stack?.split('\n')[depth].split(' ')
24
+ const funcName =
25
+ stackParts?.find((item, index) => {
26
+ if (item.length > 0 && item !== 'at') {
27
+ //check if constructor
28
+ if (item === 'new') {
29
+ newIndex = index
30
+ }
31
+ return item
32
+ }
33
+ }) ?? '<unknown>'
34
+ return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName
35
+ })
36
+ }
37
+ }