@xylabs/logger 4.13.7 → 4.13.8
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/dist/neutral/index.d.ts +12 -5
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/LevelLogger.ts +11 -3
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumValue, Enum, EnumKey } from '@xylabs/enum';
|
|
2
2
|
|
|
3
3
|
type LogFunction = (...data: unknown[]) => void;
|
|
4
4
|
/**
|
|
@@ -14,6 +14,8 @@ interface Logger {
|
|
|
14
14
|
warn: LogFunction;
|
|
15
15
|
}
|
|
16
16
|
type LogLevelKey = EnumKey<typeof LogLevel>;
|
|
17
|
+
type LogVerbosity = LogLevelKey;
|
|
18
|
+
type LogLevelValue = EnumValue<typeof LogLevel>;
|
|
17
19
|
declare const LogLevel: Enum<{
|
|
18
20
|
error: 1;
|
|
19
21
|
warn: 2;
|
|
@@ -22,12 +24,17 @@ declare const LogLevel: Enum<{
|
|
|
22
24
|
debug: 5;
|
|
23
25
|
trace: 6;
|
|
24
26
|
}>;
|
|
25
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `LogLevelValue` instead.
|
|
29
|
+
* This name conflicts with the `LogLevel` enum and
|
|
30
|
+
* makes it confusing to import
|
|
31
|
+
*/
|
|
32
|
+
type LogLevel = LogLevelValue;
|
|
26
33
|
declare const NoOpLogFunction: (..._data: unknown[]) => undefined;
|
|
27
34
|
declare class LevelLogger implements Logger {
|
|
28
|
-
readonly level:
|
|
35
|
+
readonly level: LogLevelValue;
|
|
29
36
|
readonly logger: Logger;
|
|
30
|
-
constructor(logger: Logger, level?:
|
|
37
|
+
constructor(logger: Logger, level?: LogLevelValue);
|
|
31
38
|
get debug(): LogFunction;
|
|
32
39
|
get error(): LogFunction;
|
|
33
40
|
get info(): LogFunction;
|
|
@@ -57,4 +64,4 @@ declare class IdLogger implements Logger {
|
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
export { ConsoleLogger, IdLogger, LevelLogger, LogLevel, NoOpLogFunction, getFunctionName };
|
|
60
|
-
export type { LogFunction, LogLevelKey, Logger };
|
|
67
|
+
export type { LogFunction, LogLevelKey, LogLevelValue, LogVerbosity, Logger };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LevelLogger.ts","../../src/ConsoleLogger.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts"],"sourcesContent":["import type { EnumKey, EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\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
|
|
1
|
+
{"version":3,"sources":["../../src/LevelLogger.ts","../../src/ConsoleLogger.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts"],"sourcesContent":["import type { EnumKey, EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\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/**\n * @deprecated Use `LogLevelValue` instead.\n * This name conflicts with the `LogLevel` enum and\n * makes it confusing to import\n */\nexport type LogLevel = LogLevelValue\n\nexport const NoOpLogFunction = (..._data: unknown[]) => void {}\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","import { LevelLogger, LogLevel } from './LevelLogger.ts'\n\nexport class ConsoleLogger extends LevelLogger {\n constructor(level: LogLevel = 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"],"mappings":";AACA,SAAS,YAAY;AAiBd,IAAM,WAAW,KAAK;AAAA,EAC3B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO;AACT,CAAC;AAaM,IAAM,kBAAkB,IAAI,UAAqB,KAAK,CAAC;AAEvD,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,SAAS,SAAS,MAAM,KAAK,OAAO,MAAM;AAAA,EACxD;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;AACF;;;ACrEO,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAC7C,YAAY,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,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;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/logger",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.8",
|
|
4
4
|
"description": "XYLabs Logger Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"module": "dist/neutral/index.mjs",
|
|
37
37
|
"types": "dist/neutral/index.d.ts",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xylabs/enum": "^4.13.
|
|
40
|
-
"@xylabs/error": "^4.13.
|
|
41
|
-
"@xylabs/typeof": "^4.13.
|
|
39
|
+
"@xylabs/enum": "^4.13.8",
|
|
40
|
+
"@xylabs/error": "^4.13.8",
|
|
41
|
+
"@xylabs/typeof": "^4.13.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^24.0.13",
|
package/src/LevelLogger.ts
CHANGED
|
@@ -26,14 +26,22 @@ export const LogLevel = Enum({
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
export type LogLevelKey = EnumKey<typeof LogLevel>
|
|
29
|
-
export type
|
|
29
|
+
export type LogVerbosity = LogLevelKey
|
|
30
|
+
|
|
31
|
+
export type LogLevelValue = EnumValue<typeof LogLevel>
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use `LogLevelValue` instead.
|
|
34
|
+
* This name conflicts with the `LogLevel` enum and
|
|
35
|
+
* makes it confusing to import
|
|
36
|
+
*/
|
|
37
|
+
export type LogLevel = LogLevelValue
|
|
30
38
|
|
|
31
39
|
export const NoOpLogFunction = (..._data: unknown[]) => void {}
|
|
32
40
|
|
|
33
41
|
export class LevelLogger implements Logger {
|
|
34
|
-
readonly level:
|
|
42
|
+
readonly level: LogLevelValue
|
|
35
43
|
readonly logger: Logger
|
|
36
|
-
constructor(logger: Logger, level:
|
|
44
|
+
constructor(logger: Logger, level: LogLevelValue = LogLevel.warn) {
|
|
37
45
|
this.level = level
|
|
38
46
|
this.logger = logger
|
|
39
47
|
}
|