@xylabs/logger 5.0.79 → 5.0.81
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 +6 -23
- package/package.json +7 -10
- package/src/ConsoleLogger.ts +0 -8
- package/src/IdLogger.ts +0 -43
- package/src/LevelLogger.ts +0 -66
- package/src/NoOpLogFunction.ts +0 -1
- package/src/SilentLogger.ts +0 -18
- package/src/getFunctionName.ts +0 -24
- package/src/index.ts +0 -6
package/README.md
CHANGED
|
@@ -35,7 +35,6 @@ XYLabs Logger Library
|
|
|
35
35
|
## Type Aliases
|
|
36
36
|
|
|
37
37
|
- [LogFunction](#type-aliases/LogFunction)
|
|
38
|
-
- [~~LogLevel~~](#type-aliases/LogLevel)
|
|
39
38
|
- [LogLevelKey](#type-aliases/LogLevelKey)
|
|
40
39
|
- [LogVerbosity](#type-aliases/LogVerbosity)
|
|
41
40
|
- [LogLevelValue](#type-aliases/LogLevelValue)
|
|
@@ -69,12 +68,12 @@ Interface to handle overlap between Winston &
|
|
|
69
68
|
### Constructor
|
|
70
69
|
|
|
71
70
|
```ts
|
|
72
|
-
new ConsoleLogger(level): ConsoleLogger;
|
|
71
|
+
new ConsoleLogger(level?): ConsoleLogger;
|
|
73
72
|
```
|
|
74
73
|
|
|
75
74
|
### Parameters
|
|
76
75
|
|
|
77
|
-
#### level
|
|
76
|
+
#### level?
|
|
78
77
|
|
|
79
78
|
[`LogLevelValue`](#../type-aliases/LogLevelValue) = `LogLevel.warn`
|
|
80
79
|
|
|
@@ -439,7 +438,7 @@ Interface to handle overlap between Winston &
|
|
|
439
438
|
### Constructor
|
|
440
439
|
|
|
441
440
|
```ts
|
|
442
|
-
new LevelLogger(logger, level): LevelLogger;
|
|
441
|
+
new LevelLogger(logger, level?): LevelLogger;
|
|
443
442
|
```
|
|
444
443
|
|
|
445
444
|
### Parameters
|
|
@@ -448,7 +447,7 @@ new LevelLogger(logger, level): LevelLogger;
|
|
|
448
447
|
|
|
449
448
|
[`Logger`](#../interfaces/Logger)
|
|
450
449
|
|
|
451
|
-
#### level
|
|
450
|
+
#### level?
|
|
452
451
|
|
|
453
452
|
[`LogLevelValue`](#../type-aliases/LogLevelValue) = `LogLevel.warn`
|
|
454
453
|
|
|
@@ -769,12 +768,12 @@ function NoOpLogFunction(..._data): undefined;
|
|
|
769
768
|
***
|
|
770
769
|
|
|
771
770
|
```ts
|
|
772
|
-
function getFunctionName(depth): string;
|
|
771
|
+
function getFunctionName(depth?): string;
|
|
773
772
|
```
|
|
774
773
|
|
|
775
774
|
## Parameters
|
|
776
775
|
|
|
777
|
-
### depth
|
|
776
|
+
### depth?
|
|
778
777
|
|
|
779
778
|
`number` = `2`
|
|
780
779
|
|
|
@@ -863,22 +862,6 @@ type LogFunction = (...data) => void;
|
|
|
863
862
|
|
|
864
863
|
`void`
|
|
865
864
|
|
|
866
|
-
### <a id="LogLevel"></a>LogLevel
|
|
867
|
-
|
|
868
|
-
[**@xylabs/logger**](#../README)
|
|
869
|
-
|
|
870
|
-
***
|
|
871
|
-
|
|
872
|
-
```ts
|
|
873
|
-
type LogLevel = LogLevelValue;
|
|
874
|
-
```
|
|
875
|
-
|
|
876
|
-
## Deprecated
|
|
877
|
-
|
|
878
|
-
Use `LogLevelValue` instead.
|
|
879
|
-
This name conflicts with the `LogLevel` enum and
|
|
880
|
-
makes it confusing to import
|
|
881
|
-
|
|
882
865
|
### <a id="LogLevelKey"></a>LogLevelKey
|
|
883
866
|
|
|
884
867
|
[**@xylabs/logger**](#../README)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/logger",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.81",
|
|
4
4
|
"description": "XYLabs Logger Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger",
|
|
@@ -29,30 +29,27 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/neutral/index.d.ts",
|
|
32
|
-
"source": "./src/index.ts",
|
|
33
32
|
"default": "./dist/neutral/index.mjs"
|
|
34
33
|
},
|
|
35
34
|
"./package.json": "./package.json"
|
|
36
35
|
},
|
|
37
36
|
"module": "./dist/neutral/index.mjs",
|
|
38
|
-
"source": "./src/index.ts",
|
|
39
37
|
"types": "./dist/neutral/index.d.ts",
|
|
40
38
|
"files": [
|
|
41
39
|
"dist",
|
|
42
|
-
"src",
|
|
43
40
|
"!**/*.bench.*",
|
|
44
41
|
"!**/*.spec.*",
|
|
45
42
|
"!**/*.test.*"
|
|
46
43
|
],
|
|
47
44
|
"dependencies": {
|
|
48
|
-
"@xylabs/enum": "~5.0.
|
|
49
|
-
"@xylabs/error": "~5.0.
|
|
50
|
-
"@xylabs/typeof": "~5.0.
|
|
45
|
+
"@xylabs/enum": "~5.0.81",
|
|
46
|
+
"@xylabs/error": "~5.0.81",
|
|
47
|
+
"@xylabs/typeof": "~5.0.81"
|
|
51
48
|
},
|
|
52
49
|
"devDependencies": {
|
|
53
|
-
"@types/node": "~25.
|
|
54
|
-
"@xylabs/ts-scripts-yarn3": "~7.
|
|
55
|
-
"@xylabs/tsconfig": "~7.
|
|
50
|
+
"@types/node": "~25.4.0",
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.11",
|
|
52
|
+
"@xylabs/tsconfig": "~7.4.11",
|
|
56
53
|
"typescript": "~5.9.3",
|
|
57
54
|
"vitest": "~4.0.18"
|
|
58
55
|
},
|
package/src/ConsoleLogger.ts
DELETED
package/src/IdLogger.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Logger } from './LevelLogger.ts'
|
|
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(...data: unknown[]) {
|
|
17
|
-
this._logger?.debug(this.prefix(), ...data)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
error(...data: unknown[]) {
|
|
21
|
-
this._logger?.error(this.prefix(), ...data)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
info(...data: unknown[]) {
|
|
25
|
-
this._logger?.info(this.prefix(), ...data)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
log(...data: unknown[]) {
|
|
29
|
-
this._logger?.log(this.prefix(), ...data)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
trace(...data: unknown[]) {
|
|
33
|
-
this._logger?.trace(this.prefix(), ...data)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
warn(...data: unknown[]) {
|
|
37
|
-
this._logger?.warn(this.prefix(), ...data)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private prefix() {
|
|
41
|
-
return `[${this._id?.()}]`
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/LevelLogger.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { EnumKey, EnumValue } from '@xylabs/enum'
|
|
2
|
-
import { Enum } from '@xylabs/enum'
|
|
3
|
-
|
|
4
|
-
import { NoOpLogFunction } from './NoOpLogFunction.ts'
|
|
5
|
-
|
|
6
|
-
export type LogFunction = (...data: unknown[]) => void
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Interface to handle overlap between Winston &
|
|
10
|
-
* `console` with as much congruency as possible.
|
|
11
|
-
*/
|
|
12
|
-
export interface Logger {
|
|
13
|
-
debug: LogFunction
|
|
14
|
-
error: LogFunction
|
|
15
|
-
info: LogFunction
|
|
16
|
-
log: LogFunction
|
|
17
|
-
trace: LogFunction
|
|
18
|
-
warn: LogFunction
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const LogLevel = Enum({
|
|
22
|
-
error: 1,
|
|
23
|
-
warn: 2,
|
|
24
|
-
info: 3,
|
|
25
|
-
log: 4,
|
|
26
|
-
debug: 5,
|
|
27
|
-
trace: 6,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export type LogLevelKey = EnumKey<typeof LogLevel>
|
|
31
|
-
export type LogVerbosity = LogLevelKey
|
|
32
|
-
|
|
33
|
-
export type LogLevelValue = EnumValue<typeof LogLevel>
|
|
34
|
-
|
|
35
|
-
export class LevelLogger implements Logger {
|
|
36
|
-
readonly level: LogLevelValue
|
|
37
|
-
readonly logger: Logger
|
|
38
|
-
constructor(logger: Logger, level: LogLevelValue = LogLevel.warn) {
|
|
39
|
-
this.level = level
|
|
40
|
-
this.logger = logger
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get debug() {
|
|
44
|
-
return this.level >= LogLevel.debug ? this.logger.debug : NoOpLogFunction
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get error() {
|
|
48
|
-
return this.level >= LogLevel.error ? this.logger.error : NoOpLogFunction
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get info() {
|
|
52
|
-
return this.level >= LogLevel.info ? this.logger.info : NoOpLogFunction
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get log() {
|
|
56
|
-
return this.level >= LogLevel.log ? this.logger.log : NoOpLogFunction
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get trace() {
|
|
60
|
-
return this.level >= LogLevel.trace ? this.logger.trace : NoOpLogFunction
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get warn() {
|
|
64
|
-
return this.level >= LogLevel.warn ? this.logger.warn : NoOpLogFunction
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/NoOpLogFunction.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const NoOpLogFunction = (..._data: unknown[]) => void {}
|
package/src/SilentLogger.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Logger } from './LevelLogger.ts'
|
|
2
|
-
import { NoOpLogFunction } from './NoOpLogFunction.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A logger that does not log anything.
|
|
6
|
-
* This is useful when you want to disable logging
|
|
7
|
-
* like when running unit tests or in silent mode.
|
|
8
|
-
* It implements the `Logger` interface but all methods
|
|
9
|
-
* are no-op functions.
|
|
10
|
-
*/
|
|
11
|
-
export class SilentLogger implements Logger {
|
|
12
|
-
readonly debug = NoOpLogFunction
|
|
13
|
-
readonly error = NoOpLogFunction
|
|
14
|
-
readonly info = NoOpLogFunction
|
|
15
|
-
readonly log = NoOpLogFunction
|
|
16
|
-
readonly trace = NoOpLogFunction
|
|
17
|
-
readonly warn = NoOpLogFunction
|
|
18
|
-
}
|
package/src/getFunctionName.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { handleError } from '@xylabs/error'
|
|
2
|
-
import { isNumber } from '@xylabs/typeof'
|
|
3
|
-
|
|
4
|
-
export const getFunctionName = (depth = 2) => {
|
|
5
|
-
try {
|
|
6
|
-
throw new Error('Getting function name')
|
|
7
|
-
} catch (ex) {
|
|
8
|
-
return handleError(ex, (error) => {
|
|
9
|
-
let newIndex: number | undefined
|
|
10
|
-
const stackParts = error.stack?.split('\n')[depth]?.split(' ')
|
|
11
|
-
const funcName
|
|
12
|
-
= stackParts?.find((item, index) => {
|
|
13
|
-
if (item.length > 0 && item !== 'at') {
|
|
14
|
-
// check if constructor
|
|
15
|
-
if (item === 'new') {
|
|
16
|
-
newIndex = index
|
|
17
|
-
}
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
20
|
-
}) ?? '<unknown>'
|
|
21
|
-
return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|