logixlysia 4.2.2 → 4.2.4
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/index.cjs +13 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +13 -0
- package/package.json +15 -6
- package/CHANGELOG.md +0 -291
- package/src/extensions/index.ts +0 -1
- package/src/extensions/start-server.ts +0 -33
- package/src/helpers/color-mapping.ts +0 -19
- package/src/helpers/duration.ts +0 -27
- package/src/helpers/index.ts +0 -7
- package/src/helpers/log.ts +0 -9
- package/src/helpers/method.ts +0 -11
- package/src/helpers/path.ts +0 -11
- package/src/helpers/status.ts +0 -33
- package/src/helpers/timestamp.ts +0 -48
- package/src/index.ts +0 -46
- package/src/interfaces/index.ts +0 -98
- package/src/logger/build-log-message.ts +0 -67
- package/src/logger/create-logger.ts +0 -58
- package/src/logger/filter.ts +0 -24
- package/src/logger/handle-http-error.ts +0 -30
- package/src/logger/index.ts +0 -2
- package/src/output/console.ts +0 -28
- package/src/output/file.ts +0 -34
- package/src/output/index.ts +0 -2
- package/tsconfig.json +0 -25
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
durationString,
|
|
5
|
-
formatTimestamp,
|
|
6
|
-
logString,
|
|
7
|
-
methodString,
|
|
8
|
-
pathString,
|
|
9
|
-
statusString
|
|
10
|
-
} from '../helpers'
|
|
11
|
-
import type {
|
|
12
|
-
LogComponents,
|
|
13
|
-
LogData,
|
|
14
|
-
LogLevel,
|
|
15
|
-
Options,
|
|
16
|
-
RequestInfo,
|
|
17
|
-
StoreData
|
|
18
|
-
} from '../interfaces'
|
|
19
|
-
|
|
20
|
-
const defaultLogFormat =
|
|
21
|
-
'🦊 {now} {level} {duration} {method} {pathname} {status} {message} {ip}'
|
|
22
|
-
|
|
23
|
-
function shouldUseColors(useColors: boolean, options?: Options): boolean {
|
|
24
|
-
if (options?.config?.useColors !== undefined) {
|
|
25
|
-
return options.config.useColors && process.env.NO_COLOR === undefined
|
|
26
|
-
}
|
|
27
|
-
return useColors && process.env.NO_COLOR === undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function buildLogMessage(
|
|
31
|
-
level: LogLevel,
|
|
32
|
-
request: RequestInfo,
|
|
33
|
-
data: LogData,
|
|
34
|
-
store: StoreData,
|
|
35
|
-
options?: Options,
|
|
36
|
-
useColors = true
|
|
37
|
-
): string {
|
|
38
|
-
const actuallyUseColors = shouldUseColors(useColors, options)
|
|
39
|
-
const now = new Date()
|
|
40
|
-
const components: LogComponents = {
|
|
41
|
-
now: actuallyUseColors
|
|
42
|
-
? chalk.bgYellow(
|
|
43
|
-
chalk.black(formatTimestamp(now, options?.config?.timestamp))
|
|
44
|
-
)
|
|
45
|
-
: formatTimestamp(now, options?.config?.timestamp),
|
|
46
|
-
epoch: Math.floor(now.getTime() / 1000).toString(),
|
|
47
|
-
level: logString(level, useColors),
|
|
48
|
-
duration: durationString(store.beforeTime, useColors),
|
|
49
|
-
method: methodString(request.method, useColors),
|
|
50
|
-
pathname: pathString(request),
|
|
51
|
-
status: statusString(data.status || 200, useColors),
|
|
52
|
-
message: data.message || '',
|
|
53
|
-
ip:
|
|
54
|
-
options?.config?.ip && request.headers.get('x-forwarded-for')
|
|
55
|
-
? `IP: ${request.headers.get('x-forwarded-for')}`
|
|
56
|
-
: ''
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const logFormat = options?.config?.customLogFormat || defaultLogFormat
|
|
60
|
-
|
|
61
|
-
return logFormat.replace(/{(\w+)}/g, (_, key: string) => {
|
|
62
|
-
if (key in components) {
|
|
63
|
-
return components[key as keyof LogComponents] || ''
|
|
64
|
-
}
|
|
65
|
-
return ''
|
|
66
|
-
})
|
|
67
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
LogData,
|
|
3
|
-
LogLevel,
|
|
4
|
-
Logger,
|
|
5
|
-
Options,
|
|
6
|
-
RequestInfo,
|
|
7
|
-
StoreData
|
|
8
|
-
} from '../interfaces'
|
|
9
|
-
import { logToFile, logToTransports } from '../output'
|
|
10
|
-
import { buildLogMessage } from './build-log-message'
|
|
11
|
-
import { filterLog } from './filter'
|
|
12
|
-
import { handleHttpError } from './handle-http-error'
|
|
13
|
-
|
|
14
|
-
async function log(
|
|
15
|
-
level: LogLevel,
|
|
16
|
-
request: RequestInfo,
|
|
17
|
-
data: LogData,
|
|
18
|
-
store: StoreData,
|
|
19
|
-
options?: Options
|
|
20
|
-
): Promise<void> {
|
|
21
|
-
if (!filterLog(level, data.status || 200, request.method, options)) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const logMessage = buildLogMessage(level, request, data, store, options, true)
|
|
26
|
-
console.log(logMessage)
|
|
27
|
-
|
|
28
|
-
const promises: Promise<void>[] = []
|
|
29
|
-
|
|
30
|
-
if (options?.config?.logFilePath) {
|
|
31
|
-
promises.push(
|
|
32
|
-
logToFile(
|
|
33
|
-
options.config.logFilePath,
|
|
34
|
-
level,
|
|
35
|
-
request,
|
|
36
|
-
data,
|
|
37
|
-
store,
|
|
38
|
-
options
|
|
39
|
-
)
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (options?.config?.transports?.length) {
|
|
44
|
-
promises.push(logToTransports(level, request, data, store, options))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await Promise.all(promises)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function createLogger(options?: Options): Logger {
|
|
51
|
-
return {
|
|
52
|
-
log: (level, request, data, store) =>
|
|
53
|
-
log(level, request, data, store, options),
|
|
54
|
-
handleHttpError: (request, error, store) =>
|
|
55
|
-
handleHttpError(request, error, store, options),
|
|
56
|
-
customLogFormat: options?.config?.customLogFormat
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/logger/filter.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { LogLevel, Options } from '../interfaces'
|
|
2
|
-
|
|
3
|
-
const checkFilter = (filterValue: unknown, value: unknown) =>
|
|
4
|
-
Array.isArray(filterValue)
|
|
5
|
-
? filterValue.includes(value)
|
|
6
|
-
: filterValue === value
|
|
7
|
-
|
|
8
|
-
export function filterLog(
|
|
9
|
-
logLevel: LogLevel,
|
|
10
|
-
status: number,
|
|
11
|
-
method: string,
|
|
12
|
-
options?: Options
|
|
13
|
-
): boolean {
|
|
14
|
-
const filter = options?.config?.logFilter
|
|
15
|
-
if (!filter) {
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
(!filter.level || checkFilter(filter.level, logLevel)) &&
|
|
21
|
-
(!filter.status || checkFilter(filter.status, status)) &&
|
|
22
|
-
(!filter.method || checkFilter(filter.method, method))
|
|
23
|
-
)
|
|
24
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { HttpError, Options, RequestInfo, StoreData } from '../interfaces'
|
|
2
|
-
import { logToFile } from '../output'
|
|
3
|
-
import { buildLogMessage } from './build-log-message'
|
|
4
|
-
|
|
5
|
-
export function handleHttpError(
|
|
6
|
-
request: RequestInfo,
|
|
7
|
-
error: HttpError,
|
|
8
|
-
store: StoreData,
|
|
9
|
-
options?: Options
|
|
10
|
-
): void {
|
|
11
|
-
const statusCode = error.status || 500
|
|
12
|
-
console.error(
|
|
13
|
-
buildLogMessage('ERROR', request, { status: statusCode }, store, options)
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const promises: Promise<void>[] = []
|
|
17
|
-
|
|
18
|
-
if (options?.config?.logFilePath) {
|
|
19
|
-
promises.push(
|
|
20
|
-
logToFile(
|
|
21
|
-
options.config.logFilePath,
|
|
22
|
-
'ERROR',
|
|
23
|
-
request,
|
|
24
|
-
{ status: statusCode },
|
|
25
|
-
store,
|
|
26
|
-
options
|
|
27
|
-
)
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/logger/index.ts
DELETED
package/src/output/console.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
LogData,
|
|
3
|
-
LogLevel,
|
|
4
|
-
Options,
|
|
5
|
-
RequestInfo,
|
|
6
|
-
StoreData
|
|
7
|
-
} from '../interfaces'
|
|
8
|
-
import { buildLogMessage } from '../logger/build-log-message'
|
|
9
|
-
|
|
10
|
-
export async function logToTransports(
|
|
11
|
-
level: LogLevel,
|
|
12
|
-
request: RequestInfo,
|
|
13
|
-
data: LogData,
|
|
14
|
-
store: StoreData,
|
|
15
|
-
options?: Options
|
|
16
|
-
): Promise<void> {
|
|
17
|
-
if (!options?.config?.transports || options.config.transports.length === 0) {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const message = buildLogMessage(level, request, data, store, options, false)
|
|
22
|
-
|
|
23
|
-
const promises = options.config.transports.map(transport =>
|
|
24
|
-
transport.log(level, message, { request, data, store })
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
await Promise.all(promises)
|
|
28
|
-
}
|
package/src/output/file.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs'
|
|
2
|
-
import { dirname } from 'node:path'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
LogData,
|
|
6
|
-
LogLevel,
|
|
7
|
-
Options,
|
|
8
|
-
RequestInfo,
|
|
9
|
-
StoreData
|
|
10
|
-
} from '../interfaces'
|
|
11
|
-
import { buildLogMessage } from '../logger/build-log-message'
|
|
12
|
-
|
|
13
|
-
const dirCache = new Set<string>()
|
|
14
|
-
|
|
15
|
-
async function ensureDirectoryExists(filePath: string): Promise<void> {
|
|
16
|
-
const dir = dirname(filePath)
|
|
17
|
-
if (!dirCache.has(dir)) {
|
|
18
|
-
await fs.mkdir(dir, { recursive: true })
|
|
19
|
-
dirCache.add(dir)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function logToFile(
|
|
24
|
-
filePath: string,
|
|
25
|
-
level: LogLevel,
|
|
26
|
-
request: RequestInfo,
|
|
27
|
-
data: LogData,
|
|
28
|
-
store: StoreData,
|
|
29
|
-
options?: Options
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
await ensureDirectoryExists(filePath)
|
|
32
|
-
const logMessage = `${buildLogMessage(level, request, data, store, options, false)}\n`
|
|
33
|
-
await fs.appendFile(filePath, logMessage, { flag: 'a' })
|
|
34
|
-
}
|
package/src/output/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noUncheckedIndexedAccess": true,
|
|
5
|
-
"strict": true,
|
|
6
|
-
"allowImportingTsExtensions": true,
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"moduleResolution": "Bundler",
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"types": ["bun-types"],
|
|
11
|
-
"downlevelIteration": true,
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"allowSyntheticDefaultImports": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"jsx": "react",
|
|
17
|
-
"jsxFactory": "ElysiaJSX",
|
|
18
|
-
"jsxFragmentFactory": "ElysiaJSX.Fragment",
|
|
19
|
-
"lib": ["ESNext"],
|
|
20
|
-
"moduleDetection": "force",
|
|
21
|
-
"target": "ESNext",
|
|
22
|
-
"composite": true,
|
|
23
|
-
"skipLibCheck": true
|
|
24
|
-
}
|
|
25
|
-
}
|