@pori15/logixlysia 0.0.1 → 6.0.1
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 +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +7 -7
- package/package.json +13 -4
- package/src/index.ts +1 -1
- package/src/interfaces.ts +12 -3
- package/src/logger/handle-http-error.ts +1 -0
- package/src/logger/index.ts +15 -1
- package/src/utils/error.ts +0 -2
- package/src/utils/handle-error.ts +289 -289
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pori15/logixlysia",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "🦊 Logixlysia is a logger for Elysia",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test:coverage": "bun test --coverage --coverage-reporter=lcov",
|
|
17
17
|
"clean": "git clean -fdx .turbo dist node_modules coverage",
|
|
18
18
|
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
19
|
-
"release": "
|
|
19
|
+
"release": "bun publish --access public"
|
|
20
20
|
},
|
|
21
21
|
"author": "Noppakorn Kaewsalabnil <hello@pungrumpy.com>",
|
|
22
22
|
"bugs": {
|
|
@@ -29,17 +29,26 @@
|
|
|
29
29
|
"logger"
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/pori15/logixlysia.git"
|
|
39
|
+
},
|
|
32
40
|
"dependencies": {
|
|
33
41
|
"chalk": "^5.6.2",
|
|
34
|
-
"elysia": "^1.4.19",
|
|
35
42
|
"pino": "^10.1.0",
|
|
36
43
|
"pino-pretty": "^13.1.3"
|
|
37
44
|
},
|
|
38
45
|
"devDependencies": {
|
|
39
46
|
"@types/bun": "^1.3.5",
|
|
40
|
-
"bunup": "^0.16.17"
|
|
47
|
+
"bunup": "^0.16.17",
|
|
48
|
+
"elysia": "^1.4.19"
|
|
41
49
|
},
|
|
42
50
|
"peerDependencies": {
|
|
51
|
+
"elysia": "^1.4.19",
|
|
43
52
|
"typescript": "^5.9.3"
|
|
44
53
|
}
|
|
45
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -133,7 +133,7 @@ export type {
|
|
|
133
133
|
Transport,
|
|
134
134
|
} from './interfaces'
|
|
135
135
|
|
|
136
|
-
export { HttpError } from './
|
|
136
|
+
export { HttpError } from './Error/errors'
|
|
137
137
|
export { toProblemJson, formatProblemJsonLog } from './utils/handle-error'
|
|
138
138
|
export type { ProblemJson } from './utils/handle-error'
|
|
139
139
|
|
package/src/interfaces.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { Code } from './Error/type'
|
|
|
8
8
|
export type Pino = PinoLogger<never, boolean>
|
|
9
9
|
export type Request = Request
|
|
10
10
|
|
|
11
|
+
export type RequestInfo = Request
|
|
12
|
+
|
|
11
13
|
export type LogLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR'
|
|
12
14
|
|
|
13
15
|
export interface StoreData {
|
|
@@ -46,9 +48,13 @@ export interface LogRotationConfig {
|
|
|
46
48
|
compression?: 'gzip'
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
export interface LogFilter {
|
|
52
|
+
/**
|
|
53
|
+
* Array of log levels to allow. If specified, only logs with these levels will be processed.
|
|
54
|
+
* If not specified, all log levels will be allowed.
|
|
55
|
+
*/
|
|
56
|
+
level?: LogLevel[]
|
|
57
|
+
}
|
|
52
58
|
|
|
53
59
|
export interface Options {
|
|
54
60
|
config?: {
|
|
@@ -61,6 +67,9 @@ export interface Options {
|
|
|
61
67
|
}
|
|
62
68
|
customLogFormat?: string
|
|
63
69
|
|
|
70
|
+
// Filtering
|
|
71
|
+
logFilter?: LogFilter
|
|
72
|
+
|
|
64
73
|
// Outputs
|
|
65
74
|
transports?: Transport[]
|
|
66
75
|
useTransportsOnly?: boolean
|
package/src/logger/index.ts
CHANGED
|
@@ -4,7 +4,9 @@ import type {
|
|
|
4
4
|
LogLevel,
|
|
5
5
|
Options,
|
|
6
6
|
Pino,
|
|
7
|
-
|
|
7
|
+
RequestInfo,
|
|
8
|
+
StoreData,
|
|
9
|
+
LogFilter
|
|
8
10
|
} from '../interfaces'
|
|
9
11
|
import { logToTransports } from '../output'
|
|
10
12
|
import { logToFile } from '../output/file'
|
|
@@ -40,12 +42,24 @@ export const createLogger = (options: Options = {}): Logger => {
|
|
|
40
42
|
transport
|
|
41
43
|
})
|
|
42
44
|
|
|
45
|
+
const shouldLog = (level: LogLevel, logFilter?: LogFilter): boolean => {
|
|
46
|
+
if (!logFilter?.level || logFilter.level.length === 0) {
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
return logFilter.level.includes(level)
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
const log = (
|
|
44
53
|
level: LogLevel,
|
|
45
54
|
request: Request,
|
|
46
55
|
data: Record<string, unknown>,
|
|
47
56
|
store: StoreData
|
|
48
57
|
): void => {
|
|
58
|
+
// Check if this log level should be filtered
|
|
59
|
+
if (!shouldLog(level, config?.logFilter)) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
logToTransports({ level, request, data, store, options })
|
|
50
64
|
|
|
51
65
|
const useTransportsOnly = config?.useTransportsOnly === true
|