@nexload-sdk/logger 1.0.1 → 1.0.2
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 +124 -0
- package/dist/index.cjs +22 -22
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +2 -2
- package/package.json +10 -5
- package/.turbo/turbo-build.log +0 -10
- package/.turbo/turbo-lint.log +0 -13
- package/CHANGELOG.md +0 -18
- package/esbuild.config.mjs +0 -5
- package/eslint.config.mjs +0 -4
- package/src/index.ts +0 -38
- package/src/next-js.ts +0 -105
- package/tsconfig.json +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexload-sdk/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"package.json"
|
|
16
|
+
],
|
|
12
17
|
"publishConfig": {
|
|
13
18
|
"access": "public"
|
|
14
19
|
},
|
|
@@ -16,12 +21,12 @@
|
|
|
16
21
|
"@types/node": "^24.9.1",
|
|
17
22
|
"eslint": "^9.38.0",
|
|
18
23
|
"typescript": "5.9.3",
|
|
19
|
-
"@nexload-sdk/
|
|
20
|
-
"@nexload-sdk/
|
|
21
|
-
"@nexload-sdk/
|
|
24
|
+
"@nexload-sdk/bundler": "1.0.1",
|
|
25
|
+
"@nexload-sdk/eslint-config": "1.0.1",
|
|
26
|
+
"@nexload-sdk/typescript-config": "1.0.1"
|
|
22
27
|
},
|
|
23
28
|
"dependencies": {
|
|
24
|
-
"@nexload-sdk/env": "^1.0.
|
|
29
|
+
"@nexload-sdk/env": "^1.0.1",
|
|
25
30
|
"pino": "^10.0.0",
|
|
26
31
|
"pino-pretty": "^13.1.2"
|
|
27
32
|
},
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @nexload-sdk/logger@0.0.0 build /Users/mm25zamanian/Codes/nexload-sdk/packages/logger
|
|
4
|
-
> node esbuild.config.mjs
|
|
5
|
-
|
|
6
|
-
1. Cleaning dist directory...
|
|
7
|
-
2. Building JS outputs (CJS & ESM) via esbuild...
|
|
8
|
-
3. Generating TypeScript declarations via tsc...
|
|
9
|
-
Build successful!
|
|
10
|
-
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @nexload-sdk/logger@0.0.0 lint /Users/mm25zamanian/Codes/nexload-sdk/packages/logger
|
|
4
|
-
> eslint .
|
|
5
|
-
|
|
6
|
-
[0m[0m
|
|
7
|
-
[0m[4m/Users/mm25zamanian/Codes/nexload-sdk/packages/logger/index.ts[24m[0m
|
|
8
|
-
[0m [2m1:1[22m [33mwarning[39m Unexpected console statement [2mno-console[22m[0m
|
|
9
|
-
[0m [2m1:23[22m [33mwarning[39m Newline required at end of file but not found [2m@stylistic/eol-last[22m[0m
|
|
10
|
-
[0m[0m
|
|
11
|
-
[0m[33m[1m✖ 2 problems (0 errors, 2 warnings)[22m[39m[0m
|
|
12
|
-
[0m[33m[1m[22m[39m[33m[1m 0 errors and 1 warning potentially fixable with the `--fix` option.[22m[39m[0m
|
|
13
|
-
[0m[33m[1m[22m[39m[0m
|
package/CHANGELOG.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# @nexload-sdk/logger
|
|
2
|
-
|
|
3
|
-
## 1.0.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- c96fe18: publish access
|
|
8
|
-
|
|
9
|
-
## 1.0.0
|
|
10
|
-
|
|
11
|
-
### Major Changes
|
|
12
|
-
|
|
13
|
-
- 8093666: initial first verison
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Updated dependencies [8093666]
|
|
18
|
-
- @nexload-sdk/env@1.0.0
|
package/esbuild.config.mjs
DELETED
package/eslint.config.mjs
DELETED
package/src/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EnvManager, merge } from "@nexload-sdk/env";
|
|
2
|
-
import { $NodePreset } from "@nexload-sdk/env/presets";
|
|
3
|
-
import pino from "pino";
|
|
4
|
-
import pretty from "pino-pretty";
|
|
5
|
-
|
|
6
|
-
const env = new EnvManager(
|
|
7
|
-
"logger", merge($NodePreset)
|
|
8
|
-
);
|
|
9
|
-
const serviceName = env.$("SERVICE_NAME");
|
|
10
|
-
const stream = pretty({
|
|
11
|
-
colorize: pretty.isColorSupported,
|
|
12
|
-
ignore: "pid,hostname",
|
|
13
|
-
});
|
|
14
|
-
const logger = pino(
|
|
15
|
-
{
|
|
16
|
-
name: serviceName,
|
|
17
|
-
level: env.$("LOG_LEVEL"),
|
|
18
|
-
timestamp: pino.stdTimeFunctions.isoTime,
|
|
19
|
-
formatters: {
|
|
20
|
-
level (label) {
|
|
21
|
-
return { level: label.toUpperCase(), };
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
base: { pid: process.pid, },
|
|
25
|
-
redact: {
|
|
26
|
-
paths: [
|
|
27
|
-
"req.headers.authorization",
|
|
28
|
-
"req.headers.cookie",
|
|
29
|
-
"user.password",
|
|
30
|
-
"user.secret"
|
|
31
|
-
],
|
|
32
|
-
censor: "[REDACTED]",
|
|
33
|
-
},
|
|
34
|
-
}, stream
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
export { withLogger } from "./next-js";
|
|
38
|
-
export default logger;
|
package/src/next-js.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import logger from "./index";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a value that may be a Promise or not.
|
|
5
|
-
*/
|
|
6
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Operation type definitions
|
|
10
|
-
*/
|
|
11
|
-
type LoggerRenderType = { type: "render" };
|
|
12
|
-
type LoggerGetDataType = { type: "get-data", functionName?: string };
|
|
13
|
-
|
|
14
|
-
export type LoggerOptions = { route: string } & (
|
|
15
|
-
| LoggerRenderType
|
|
16
|
-
| LoggerGetDataType
|
|
17
|
-
);
|
|
18
|
-
export type LoggerTimingShotFunction = (name: string) => void;
|
|
19
|
-
|
|
20
|
-
const getLogOptions = (
|
|
21
|
-
baseLog: Record<string, unknown>, duration: string
|
|
22
|
-
) => {
|
|
23
|
-
if ("timing" in baseLog) {
|
|
24
|
-
const timing = baseLog.timing as Record<string, number>;
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
...baseLog,
|
|
28
|
-
timing: {
|
|
29
|
-
...Object.fromEntries(Object.entries(timing).map(([
|
|
30
|
-
key,
|
|
31
|
-
value
|
|
32
|
-
]) => [
|
|
33
|
-
key,
|
|
34
|
-
value.toFixed(2) + "ms"
|
|
35
|
-
])),
|
|
36
|
-
total:
|
|
37
|
-
Object.values(timing)
|
|
38
|
-
.reduce(
|
|
39
|
-
(
|
|
40
|
-
acc, value
|
|
41
|
-
) => acc + value, 0
|
|
42
|
-
)
|
|
43
|
-
.toFixed(2) + "ms",
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return { ...baseLog, duration, };
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Structured performance-aware logger wrapper.
|
|
53
|
-
* Supports both sync and async functions (MaybePromise).
|
|
54
|
-
*/
|
|
55
|
-
export async function withLogger<T> (
|
|
56
|
-
options: LoggerOptions,
|
|
57
|
-
fn: (timingShot: LoggerTimingShotFunction) => MaybePromise<T>
|
|
58
|
-
): Promise<T> {
|
|
59
|
-
let start = performance.now();
|
|
60
|
-
const operationName
|
|
61
|
-
= options.type === "render" ? "Rendering" : "Getting data";
|
|
62
|
-
|
|
63
|
-
const baseLog: Record<string, unknown> = {
|
|
64
|
-
route: options.route,
|
|
65
|
-
...(options.type === "get-data" && options.functionName
|
|
66
|
-
? { functionName: options.functionName, }
|
|
67
|
-
: {}),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
logger.debug(
|
|
71
|
-
baseLog, `${operationName} start`
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const timingShot: LoggerTimingShotFunction = (name) => {
|
|
75
|
-
const duration = performance.now() - start;
|
|
76
|
-
start = performance.now();
|
|
77
|
-
|
|
78
|
-
baseLog.timing ??= {};
|
|
79
|
-
(baseLog.timing as Record<string, number>)[String(name)] = duration;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
// Handle both sync and async results safely
|
|
84
|
-
const result = await Promise.resolve(fn(timingShot));
|
|
85
|
-
const duration = performance.now() - start;
|
|
86
|
-
|
|
87
|
-
logger.debug(
|
|
88
|
-
getLogOptions(
|
|
89
|
-
baseLog, `${duration.toFixed(2)}ms`
|
|
90
|
-
), `${operationName} completed`
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return result;
|
|
94
|
-
} catch (error) {
|
|
95
|
-
const duration = performance.now() - start;
|
|
96
|
-
|
|
97
|
-
logger.error(
|
|
98
|
-
getLogOptions(
|
|
99
|
-
baseLog, `${duration.toFixed(2)}ms`
|
|
100
|
-
), `${operationName} failed`, error
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
}
|