@xylabs/logger 5.0.83 → 5.0.84

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/README.md CHANGED
@@ -56,8 +56,7 @@ XYLabs Logger Library
56
56
 
57
57
  ***
58
58
 
59
- Interface to handle overlap between Winston &
60
- `console` with as much congruency as possible.
59
+ A LevelLogger that delegates to the global `console` object.
61
60
 
62
61
  ## Extends
63
62
 
@@ -223,8 +222,8 @@ get warn(): LogFunction;
223
222
 
224
223
  ***
225
224
 
226
- Interface to handle overlap between Winston &
227
- `console` with as much congruency as possible.
225
+ A logger wrapper that prefixes every log message with a bracketed identifier.
226
+ Useful for distinguishing log output from different components or instances.
228
227
 
229
228
  ## Implements
230
229
 
@@ -422,8 +421,8 @@ Logger.warn
422
421
 
423
422
  ***
424
423
 
425
- Interface to handle overlap between Winston &
426
- `console` with as much congruency as possible.
424
+ A logger that filters messages based on a configured log level.
425
+ Methods for levels above the configured threshold return a no-op function.
427
426
 
428
427
  ## Extended by
429
428
 
@@ -615,6 +614,8 @@ new SilentLogger(): SilentLogger;
615
614
  readonly debug: (..._data) => undefined = NoOpLogFunction;
616
615
  ```
617
616
 
617
+ A log function that silently discards all arguments.
618
+
618
619
  ### Parameters
619
620
 
620
621
  #### \_data
@@ -637,6 +638,8 @@ readonly debug: (..._data) => undefined = NoOpLogFunction;
637
638
  readonly error: (..._data) => undefined = NoOpLogFunction;
638
639
  ```
639
640
 
641
+ A log function that silently discards all arguments.
642
+
640
643
  ### Parameters
641
644
 
642
645
  #### \_data
@@ -659,6 +662,8 @@ readonly error: (..._data) => undefined = NoOpLogFunction;
659
662
  readonly info: (..._data) => undefined = NoOpLogFunction;
660
663
  ```
661
664
 
665
+ A log function that silently discards all arguments.
666
+
662
667
  ### Parameters
663
668
 
664
669
  #### \_data
@@ -681,6 +686,8 @@ readonly info: (..._data) => undefined = NoOpLogFunction;
681
686
  readonly log: (..._data) => undefined = NoOpLogFunction;
682
687
  ```
683
688
 
689
+ A log function that silently discards all arguments.
690
+
684
691
  ### Parameters
685
692
 
686
693
  #### \_data
@@ -703,6 +710,8 @@ readonly log: (..._data) => undefined = NoOpLogFunction;
703
710
  readonly trace: (..._data) => undefined = NoOpLogFunction;
704
711
  ```
705
712
 
713
+ A log function that silently discards all arguments.
714
+
706
715
  ### Parameters
707
716
 
708
717
  #### \_data
@@ -725,6 +734,8 @@ readonly trace: (..._data) => undefined = NoOpLogFunction;
725
734
  readonly warn: (..._data) => undefined = NoOpLogFunction;
726
735
  ```
727
736
 
737
+ A log function that silently discards all arguments.
738
+
728
739
  ### Parameters
729
740
 
730
741
  #### \_data
@@ -751,6 +762,8 @@ readonly warn: (..._data) => undefined = NoOpLogFunction;
751
762
  function NoOpLogFunction(..._data): undefined;
752
763
  ```
753
764
 
765
+ A log function that silently discards all arguments.
766
+
754
767
  ## Parameters
755
768
 
756
769
  ### \_data
@@ -771,16 +784,22 @@ function NoOpLogFunction(..._data): undefined;
771
784
  function getFunctionName(depth?): string;
772
785
  ```
773
786
 
787
+ Retrieves the name of the calling function by inspecting the stack trace.
788
+
774
789
  ## Parameters
775
790
 
776
791
  ### depth?
777
792
 
778
793
  `number` = `2`
779
794
 
795
+ The stack frame depth to inspect (default: 2, the caller's caller).
796
+
780
797
  ## Returns
781
798
 
782
799
  `string`
783
800
 
801
+ The function name, or '<unknown>' if it cannot be determined.
802
+
784
803
  ### interfaces
785
804
 
786
805
  ### <a id="Logger"></a>Logger
@@ -852,6 +871,8 @@ warn: LogFunction;
852
871
  type LogFunction = (...data) => void;
853
872
  ```
854
873
 
874
+ A generic logging function that accepts any number of arguments.
875
+
855
876
  ## Parameters
856
877
 
857
878
  ### data
@@ -872,6 +893,8 @@ type LogFunction = (...data) => void;
872
893
  type LogLevelKey = EnumKey<typeof LogLevel>;
873
894
  ```
874
895
 
896
+ String key for a log level (e.g. 'error', 'warn', 'info').
897
+
875
898
  ### <a id="LogLevelValue"></a>LogLevelValue
876
899
 
877
900
  [**@xylabs/logger**](#../README)
@@ -882,6 +905,8 @@ type LogLevelKey = EnumKey<typeof LogLevel>;
882
905
  type LogLevelValue = EnumValue<typeof LogLevel>;
883
906
  ```
884
907
 
908
+ Numeric value of a log level (1 through 6).
909
+
885
910
  ### <a id="LogVerbosity"></a>LogVerbosity
886
911
 
887
912
  [**@xylabs/logger**](#../README)
@@ -892,6 +917,8 @@ type LogLevelValue = EnumValue<typeof LogLevel>;
892
917
  type LogVerbosity = LogLevelKey;
893
918
  ```
894
919
 
920
+ Alias for LogLevelKey, representing the verbosity setting as a string.
921
+
895
922
  ### variables
896
923
 
897
924
  ### <a id="LogLevel"></a>LogLevel
@@ -911,6 +938,8 @@ const LogLevel: Enum<{
911
938
  }>;
912
939
  ```
913
940
 
941
+ Numeric log level values, from least verbose (error=1) to most verbose (trace=6).
942
+
914
943
 
915
944
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
916
945
 
@@ -1,5 +1,6 @@
1
1
  import type { LogLevelValue } from './LevelLogger.ts';
2
2
  import { LevelLogger } from './LevelLogger.ts';
3
+ /** A LevelLogger that delegates to the global `console` object. */
3
4
  export declare class ConsoleLogger extends LevelLogger {
4
5
  constructor(level?: LogLevelValue);
5
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../src/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAA;AAExD,qBAAa,aAAc,SAAQ,WAAW;gBAChC,KAAK,GAAE,aAA6B;CAGjD"}
1
+ {"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../src/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAA;AAExD,mEAAmE;AACnE,qBAAa,aAAc,SAAQ,WAAW;gBAChC,KAAK,GAAE,aAA6B;CAGjD"}
@@ -1,4 +1,8 @@
1
1
  import type { Logger } from './LevelLogger.ts';
2
+ /**
3
+ * A logger wrapper that prefixes every log message with a bracketed identifier.
4
+ * Useful for distinguishing log output from different components or instances.
5
+ */
2
6
  export declare class IdLogger implements Logger {
3
7
  private _id?;
4
8
  private _logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C,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,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAItB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
1
+ {"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C;;;GAGG;AACH,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,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAItB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
@@ -1,5 +1,6 @@
1
1
  import type { EnumKey, EnumValue } from '@xylabs/enum';
2
2
  import { Enum } from '@xylabs/enum';
3
+ /** A generic logging function that accepts any number of arguments. */
3
4
  export type LogFunction = (...data: unknown[]) => void;
4
5
  /**
5
6
  * Interface to handle overlap between Winston &
@@ -13,6 +14,7 @@ export interface Logger {
13
14
  trace: LogFunction;
14
15
  warn: LogFunction;
15
16
  }
17
+ /** Numeric log level values, from least verbose (error=1) to most verbose (trace=6). */
16
18
  export declare const LogLevel: Enum<{
17
19
  error: 1;
18
20
  warn: 2;
@@ -21,9 +23,16 @@ export declare const LogLevel: Enum<{
21
23
  debug: 5;
22
24
  trace: 6;
23
25
  }>;
26
+ /** String key for a log level (e.g. 'error', 'warn', 'info'). */
24
27
  export type LogLevelKey = EnumKey<typeof LogLevel>;
28
+ /** Alias for LogLevelKey, representing the verbosity setting as a string. */
25
29
  export type LogVerbosity = LogLevelKey;
30
+ /** Numeric value of a log level (1 through 6). */
26
31
  export type LogLevelValue = EnumValue<typeof LogLevel>;
32
+ /**
33
+ * A logger that filters messages based on a configured log level.
34
+ * Methods for levels above the configured threshold return a no-op function.
35
+ */
27
36
  export declare class LevelLogger implements Logger {
28
37
  readonly level: LogLevelValue;
29
38
  readonly logger: Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"LevelLogger.d.ts","sourceRoot":"","sources":["../../src/LevelLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAInC,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;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,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,eAAO,MAAM,QAAQ;;;;;;;EAOnB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,QAAQ,CAAC,CAAA;AAClD,MAAM,MAAM,YAAY,GAAG,WAAW,CAAA;AAEtC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEtD,qBAAa,WAAY,YAAW,MAAM;IACxC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBACX,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,aAA6B;IAKhE,IAAI,KAAK,gBAER;IAED,IAAI,KAAK,gBAER;IAED,IAAI,IAAI,gBAEP;IAED,IAAI,GAAG,gBAEN;IAED,IAAI,KAAK,gBAER;IAED,IAAI,IAAI,gBAEP;CACF"}
1
+ {"version":3,"file":"LevelLogger.d.ts","sourceRoot":"","sources":["../../src/LevelLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAInC,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;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,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,wFAAwF;AACxF,eAAO,MAAM,QAAQ;;;;;;;EAOnB,CAAA;AAEF,iEAAiE;AACjE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,QAAQ,CAAC,CAAA;AAElD,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,WAAW,CAAA;AAEtC,kDAAkD;AAClD,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEtD;;;GAGG;AACH,qBAAa,WAAY,YAAW,MAAM;IACxC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBACX,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,aAA6B;IAKhE,IAAI,KAAK,gBAER;IAED,IAAI,KAAK,gBAER;IAED,IAAI,IAAI,gBAEP;IAED,IAAI,GAAG,gBAEN;IAED,IAAI,KAAK,gBAER;IAED,IAAI,IAAI,gBAEP;CACF"}
@@ -1,2 +1,3 @@
1
+ /** A log function that silently discards all arguments. */
1
2
  export declare const NoOpLogFunction: (..._data: unknown[]) => undefined;
2
3
  //# sourceMappingURL=NoOpLogFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NoOpLogFunction.d.ts","sourceRoot":"","sources":["../../src/NoOpLogFunction.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,GAAG,OAAO,OAAO,EAAE,cAAY,CAAA"}
1
+ {"version":3,"file":"NoOpLogFunction.d.ts","sourceRoot":"","sources":["../../src/NoOpLogFunction.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,eAAO,MAAM,eAAe,GAAI,GAAG,OAAO,OAAO,EAAE,cAAY,CAAA"}
@@ -1,2 +1,7 @@
1
+ /**
2
+ * Retrieves the name of the calling function by inspecting the stack trace.
3
+ * @param depth - The stack frame depth to inspect (default: 2, the caller's caller).
4
+ * @returns The function name, or '<unknown>' if it cannot be determined.
5
+ */
1
6
  export declare const getFunctionName: (depth?: number) => string;
2
7
  //# sourceMappingURL=getFunctionName.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,GAAI,cAAS,WAoBxC,CAAA"}
1
+ {"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,cAAS,WAoBxC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/LevelLogger.ts","../../src/NoOpLogFunction.ts","../../src/ConsoleLogger.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/SilentLogger.ts"],"sourcesContent":["import type { EnumKey, EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\n\nimport { NoOpLogFunction } from './NoOpLogFunction.ts'\n\nexport type LogFunction = (...data: 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 trace: LogFunction\n warn: LogFunction\n}\n\nexport const LogLevel = Enum({\n error: 1,\n warn: 2,\n info: 3,\n log: 4,\n debug: 5,\n trace: 6,\n})\n\nexport type LogLevelKey = EnumKey<typeof LogLevel>\nexport type LogVerbosity = LogLevelKey\n\nexport type LogLevelValue = EnumValue<typeof LogLevel>\n\nexport class LevelLogger implements Logger {\n readonly level: LogLevelValue\n readonly logger: Logger\n constructor(logger: Logger, level: LogLevelValue = LogLevel.warn) {\n this.level = level\n this.logger = logger\n }\n\n get debug() {\n return this.level >= LogLevel.debug ? this.logger.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? this.logger.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? this.logger.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? this.logger.log : NoOpLogFunction\n }\n\n get trace() {\n return this.level >= LogLevel.trace ? this.logger.trace : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? this.logger.warn : NoOpLogFunction\n }\n}\n","export const NoOpLogFunction = (..._data: unknown[]) => void {}\n","import type { LogLevelValue } from './LevelLogger.ts'\nimport { LevelLogger, LogLevel } from './LevelLogger.ts'\n\nexport class ConsoleLogger extends LevelLogger {\n constructor(level: LogLevelValue = LogLevel.warn) {\n super(console, level)\n }\n}\n","import { handleError } from '@xylabs/error'\nimport { isNumber } from '@xylabs/typeof'\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | 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 true\n }\n }) ?? '<unknown>'\n return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import type { Logger } from './LevelLogger.ts'\n\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n\n trace(...data: unknown[]) {\n this._logger?.trace(this.prefix(), ...data)\n }\n\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}]`\n }\n}\n","import type { Logger } from './LevelLogger.ts'\nimport { NoOpLogFunction } from './NoOpLogFunction.ts'\n\n/**\n * A logger that does not log anything.\n * This is useful when you want to disable logging\n * like when running unit tests or in silent mode.\n * It implements the `Logger` interface but all methods\n * are no-op functions.\n */\nexport class SilentLogger implements Logger {\n readonly debug = NoOpLogFunction\n readonly error = NoOpLogFunction\n readonly info = NoOpLogFunction\n readonly log = NoOpLogFunction\n readonly trace = NoOpLogFunction\n readonly warn = NoOpLogFunction\n}\n"],"mappings":";AACA,SAAS,YAAY;;;ACDd,IAAM,kBAAkB,IAAI,UAAqB,KAAK,CAAC;;;ADoBvD,IAAM,WAAW,KAAK;AAAA,EAC3B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO;AACT,CAAC;AAOM,IAAM,cAAN,MAAoC;AAAA,EAChC;AAAA,EACA;AAAA,EACT,YAAY,QAAgB,QAAuB,SAAS,MAAM;AAChE,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,SAAS,QAAQ,KAAK,OAAO,QAAQ;AAAA,EAC5D;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,SAAS,QAAQ,KAAK,OAAO,QAAQ;AAAA,EAC5D;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,SAAS,OAAO,KAAK,OAAO,OAAO;AAAA,EAC1D;AAAA,EAEA,IAAI,MAAM;AACR,WAAO,KAAK,SA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AiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EAEA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EAEA,OAAO,MAAiB;AACtB,SAAK,SAAS,IAAI,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EAEA,SAAS,MAAiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EAEA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EAEQ,SAAS;AACf,WAAO,IAAI,KAAK,MAAM,CAAC;AAAA,EACzB;AACF;;;AChCO,IAAM,eAAN,MAAqC;AAAA,EACjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAClB;","names":[]}
1
+ {"version":3,"sources":["../../src/LevelLogger.ts","../../src/NoOpLogFunction.ts","../../src/ConsoleLogger.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/SilentLogger.ts"],"sourcesContent":["import type { EnumKey, EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\n\nimport { NoOpLogFunction } from './NoOpLogFunction.ts'\n\n/** A generic logging function that accepts any number of arguments. */\nexport type LogFunction = (...data: 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 trace: LogFunction\n warn: LogFunction\n}\n\n/** Numeric log level values, from least verbose (error=1) to most verbose (trace=6). */\nexport const LogLevel = Enum({\n error: 1,\n warn: 2,\n info: 3,\n log: 4,\n debug: 5,\n trace: 6,\n})\n\n/** String key for a log level (e.g. 'error', 'warn', 'info'). */\nexport type LogLevelKey = EnumKey<typeof LogLevel>\n\n/** Alias for LogLevelKey, representing the verbosity setting as a string. */\nexport type LogVerbosity = LogLevelKey\n\n/** Numeric value of a log level (1 through 6). */\nexport type LogLevelValue = EnumValue<typeof LogLevel>\n\n/**\n * A logger that filters messages based on a configured log level.\n * Methods for levels above the configured threshold return a no-op function.\n */\nexport class LevelLogger implements Logger {\n readonly level: LogLevelValue\n readonly logger: Logger\n constructor(logger: Logger, level: LogLevelValue = LogLevel.warn) {\n this.level = level\n this.logger = logger\n }\n\n get debug() {\n return this.level >= LogLevel.debug ? this.logger.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? this.logger.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? this.logger.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? this.logger.log : NoOpLogFunction\n }\n\n get trace() {\n return this.level >= LogLevel.trace ? this.logger.trace : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? this.logger.warn : NoOpLogFunction\n }\n}\n","/** A log function that silently discards all arguments. */\nexport const NoOpLogFunction = (..._data: unknown[]) => void {}\n","import type { LogLevelValue } from './LevelLogger.ts'\nimport { LevelLogger, LogLevel } from './LevelLogger.ts'\n\n/** A LevelLogger that delegates to the global `console` object. */\nexport class ConsoleLogger extends LevelLogger {\n constructor(level: LogLevelValue = LogLevel.warn) {\n super(console, level)\n }\n}\n","import { handleError } from '@xylabs/error'\nimport { isNumber } from '@xylabs/typeof'\n\n/**\n * Retrieves the name of the calling function by inspecting the stack trace.\n * @param depth - The stack frame depth to inspect (default: 2, the caller's caller).\n * @returns The function name, or '<unknown>' if it cannot be determined.\n */\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | 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 true\n }\n }) ?? '<unknown>'\n return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import type { Logger } from './LevelLogger.ts'\n\n/**\n * A logger wrapper that prefixes every log message with a bracketed identifier.\n * Useful for distinguishing log output from different components or instances.\n */\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n\n trace(...data: unknown[]) {\n this._logger?.trace(this.prefix(), ...data)\n }\n\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}]`\n }\n}\n","import type { Logger } from './LevelLogger.ts'\nimport { NoOpLogFunction } from './NoOpLogFunction.ts'\n\n/**\n * A logger that does not log anything.\n * This is useful when you want to disable logging\n * like when running unit tests or in silent mode.\n * It implements the `Logger` interface but all methods\n * are no-op functions.\n */\nexport class SilentLogger implements Logger {\n readonly debug = NoOpLogFunction\n readonly error = NoOpLogFunction\n readonly info = NoOpLogFunction\n readonly log = NoOpLogFunction\n readonly trace = NoOpLogFunction\n readonly warn = NoOpLogFunction\n}\n"],"mappings":";AACA,SAAS,YAAY;;;ACAd,IAAM,kBAAkB,IAAI,UAAqB,KAAK,CAAC;;;ADqBvD,IAAM,WAAW,KAAK;AAAA,EAC3B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO;AACT,CAAC;AAeM,IAAM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Logger Library",
5
5
  "keywords": [
6
6
  "logger",
@@ -42,14 +42,14 @@
42
42
  "!**/*.test.*"
43
43
  ],
44
44
  "dependencies": {
45
- "@xylabs/enum": "~5.0.83",
46
- "@xylabs/error": "~5.0.83",
47
- "@xylabs/typeof": "~5.0.83"
45
+ "@xylabs/enum": "~5.0.84",
46
+ "@xylabs/error": "~5.0.84",
47
+ "@xylabs/typeof": "~5.0.84"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "~25.4.0",
51
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
52
- "@xylabs/tsconfig": "~7.4.11",
51
+ "@xylabs/ts-scripts-yarn3": "~7.4.13",
52
+ "@xylabs/tsconfig": "~7.4.13",
53
53
  "typescript": "~5.9.3",
54
54
  "vitest": "~4.0.18"
55
55
  },