@lark-apaas/client-toolkit 1.0.18 → 1.0.20-alpha.logger.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.
@@ -1,6 +1 @@
1
- export declare const logger: {
2
- debug(message: any, ...args: any[]): void;
3
- info(message: any, ...args: any[]): void;
4
- warn(message: any, ...args: any[]): void;
5
- error(message: any, ...args: any[]): void;
6
- };
1
+ export { logger } from './logger';
@@ -1,54 +1,2 @@
1
- const LOG_LEVELS = [
2
- 'debug',
3
- 'info',
4
- 'warn',
5
- 'error'
6
- ];
7
- const defaultConfig = {
8
- showLevel: false,
9
- showTimestamp: false,
10
- level: 'info',
11
- prefix: ''
12
- };
13
- let config = {
14
- ...defaultConfig
15
- };
16
- function configureLogger(options) {
17
- config = {
18
- ...defaultConfig,
19
- ...options
20
- };
21
- }
22
- function getLogLevel() {
23
- return config.level;
24
- }
25
- function shouldLog(level) {
26
- return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(getLogLevel());
27
- }
28
- function getFormattedPrefix(level) {
29
- const parts = [];
30
- if (config.prefix) parts.push(`[${config.prefix}]`);
31
- if (config.showLevel) parts.push(`[${level.toUpperCase()}]`);
32
- return parts;
33
- }
34
- configureLogger({
35
- showLevel: true,
36
- showTimestamp: false,
37
- level: 'development' === process.env.NODE_ENV ? 'debug' : 'error',
38
- prefix: 'MiaoDa'
39
- });
40
- const logger = {
41
- debug (message, ...args) {
42
- if (shouldLog('debug')) console.log(...getFormattedPrefix('debug'), message, ...args);
43
- },
44
- info (message, ...args) {
45
- if (shouldLog('info')) console.log(...getFormattedPrefix('info'), message, ...args);
46
- },
47
- warn (message, ...args) {
48
- if (shouldLog('warn')) console.log(...getFormattedPrefix('warn'), message, ...args);
49
- },
50
- error (message, ...args) {
51
- if (shouldLog('error')) console.error(...getFormattedPrefix('error'), message, ...args);
52
- }
53
- };
1
+ import { logger } from "./logger.js";
54
2
  export { logger };
@@ -0,0 +1 @@
1
+ export declare function interceptGlobalError(): void;
@@ -0,0 +1,10 @@
1
+ import { logger } from "./logger.js";
2
+ function interceptGlobalError() {
3
+ window.addEventListener('error', (event)=>{
4
+ logger.error('global error', event);
5
+ });
6
+ window.addEventListener('unhandledrejection', (event)=>{
7
+ logger.error('global unhandledrejection', event);
8
+ });
9
+ }
10
+ export { interceptGlobalError };
@@ -0,0 +1,113 @@
1
+ import z from 'zod';
2
+ export declare const networkRequestLogSchema: z.ZodObject<{
3
+ method: z.ZodString;
4
+ status: z.ZodInt;
5
+ statusText: z.ZodString;
6
+ path: z.ZodString;
7
+ requestData: z.ZodOptional<z.ZodUnknown>;
8
+ requestParams: z.ZodOptional<z.ZodUnknown>;
9
+ responseData: z.ZodOptional<z.ZodUnknown>;
10
+ traceID: z.ZodString;
11
+ }, z.core.$strip>;
12
+ export declare const genericErrorSchema: z.ZodObject<{
13
+ message: z.ZodString;
14
+ stack: z.ZodString;
15
+ }, z.core.$strip>;
16
+ export declare const routerErrorSchema: z.ZodObject<{
17
+ path: z.ZodString;
18
+ }, z.core.$strip>;
19
+ export declare const noCategoryLogSchema: z.ZodObject<{
20
+ message: z.ZodUnknown;
21
+ args: z.ZodArray<z.ZodUnknown>;
22
+ }, z.core.$strip>;
23
+ export declare const levelSchema: z.ZodEnum<{
24
+ info: "info";
25
+ warn: "warn";
26
+ error: "error";
27
+ debug: "debug";
28
+ }>;
29
+ export declare const selectedLogSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ type: z.ZodLiteral<"networkRequest">;
31
+ level: z.ZodEnum<{
32
+ info: "info";
33
+ warn: "warn";
34
+ error: "error";
35
+ debug: "debug";
36
+ }>;
37
+ id: z.ZodString;
38
+ data: z.ZodObject<{
39
+ method: z.ZodString;
40
+ status: z.ZodInt;
41
+ statusText: z.ZodString;
42
+ path: z.ZodString;
43
+ requestData: z.ZodOptional<z.ZodUnknown>;
44
+ requestParams: z.ZodOptional<z.ZodUnknown>;
45
+ responseData: z.ZodOptional<z.ZodUnknown>;
46
+ traceID: z.ZodString;
47
+ }, z.core.$strip>;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ type: z.ZodLiteral<"routerError">;
50
+ level: z.ZodEnum<{
51
+ info: "info";
52
+ warn: "warn";
53
+ error: "error";
54
+ debug: "debug";
55
+ }>;
56
+ id: z.ZodString;
57
+ data: z.ZodObject<{
58
+ path: z.ZodString;
59
+ }, z.core.$strip>;
60
+ }, z.core.$strip>, z.ZodObject<{
61
+ type: z.ZodLiteral<"renderError">;
62
+ level: z.ZodEnum<{
63
+ info: "info";
64
+ warn: "warn";
65
+ error: "error";
66
+ debug: "debug";
67
+ }>;
68
+ id: z.ZodString;
69
+ data: z.ZodObject<{
70
+ message: z.ZodString;
71
+ stack: z.ZodString;
72
+ }, z.core.$strip>;
73
+ }, z.core.$strip>, z.ZodObject<{
74
+ type: z.ZodLiteral<"globalError">;
75
+ level: z.ZodEnum<{
76
+ info: "info";
77
+ warn: "warn";
78
+ error: "error";
79
+ debug: "debug";
80
+ }>;
81
+ id: z.ZodString;
82
+ data: z.ZodObject<{
83
+ message: z.ZodString;
84
+ stack: z.ZodString;
85
+ }, z.core.$strip>;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ type: z.ZodLiteral<"unhandledRejectionError">;
88
+ level: z.ZodEnum<{
89
+ info: "info";
90
+ warn: "warn";
91
+ error: "error";
92
+ debug: "debug";
93
+ }>;
94
+ id: z.ZodString;
95
+ data: z.ZodObject<{
96
+ message: z.ZodString;
97
+ stack: z.ZodString;
98
+ }, z.core.$strip>;
99
+ }, z.core.$strip>, z.ZodObject<{
100
+ type: z.ZodLiteral<"noCategory">;
101
+ level: z.ZodEnum<{
102
+ info: "info";
103
+ warn: "warn";
104
+ error: "error";
105
+ debug: "debug";
106
+ }>;
107
+ id: z.ZodString;
108
+ data: z.ZodObject<{
109
+ message: z.ZodUnknown;
110
+ args: z.ZodArray<z.ZodUnknown>;
111
+ }, z.core.$strip>;
112
+ }, z.core.$strip>], "type">;
113
+ export type SelectedLog = z.infer<typeof selectedLogSchema>;
@@ -0,0 +1,67 @@
1
+ import zod from "zod";
2
+ const networkRequestLogSchema = zod.object({
3
+ method: zod.string(),
4
+ status: zod.int(),
5
+ statusText: zod.string(),
6
+ path: zod.string(),
7
+ requestData: zod.optional(zod.unknown()),
8
+ requestParams: zod.optional(zod.unknown()),
9
+ responseData: zod.optional(zod.unknown()),
10
+ traceID: zod.string()
11
+ });
12
+ const genericErrorSchema = zod.object({
13
+ message: zod.string(),
14
+ stack: zod.string()
15
+ });
16
+ const routerErrorSchema = zod.object({
17
+ path: zod.string()
18
+ });
19
+ const noCategoryLogSchema = zod.object({
20
+ message: zod.unknown(),
21
+ args: zod.array(zod.unknown())
22
+ });
23
+ const levelSchema = zod["enum"]([
24
+ 'info',
25
+ 'warn',
26
+ 'error',
27
+ 'debug'
28
+ ]);
29
+ const selectedLogSchema = zod.discriminatedUnion('type', [
30
+ zod.object({
31
+ type: zod.literal('networkRequest'),
32
+ level: levelSchema,
33
+ id: zod.string(),
34
+ data: networkRequestLogSchema
35
+ }),
36
+ zod.object({
37
+ type: zod.literal('routerError'),
38
+ level: levelSchema,
39
+ id: zod.string(),
40
+ data: routerErrorSchema
41
+ }),
42
+ zod.object({
43
+ type: zod.literal('renderError'),
44
+ level: levelSchema,
45
+ id: zod.string(),
46
+ data: genericErrorSchema
47
+ }),
48
+ zod.object({
49
+ type: zod.literal('globalError'),
50
+ level: levelSchema,
51
+ id: zod.string(),
52
+ data: genericErrorSchema
53
+ }),
54
+ zod.object({
55
+ type: zod.literal('unhandledRejectionError'),
56
+ level: levelSchema,
57
+ id: zod.string(),
58
+ data: genericErrorSchema
59
+ }),
60
+ zod.object({
61
+ type: zod.literal('noCategory'),
62
+ level: levelSchema,
63
+ id: zod.string(),
64
+ data: noCategoryLogSchema
65
+ })
66
+ ]);
67
+ export { genericErrorSchema, levelSchema, networkRequestLogSchema, noCategoryLogSchema, routerErrorSchema, selectedLogSchema };
@@ -0,0 +1,7 @@
1
+ export type LogInterceptor = (originLogger: typeof logger) => typeof logger;
2
+ export declare let logger: {
3
+ debug(message: any, ...args: any[]): void;
4
+ info(message: any, ...args: any[]): void;
5
+ warn(message: any, ...args: any[]): void;
6
+ error(message: any, ...args: any[]): void;
7
+ };
@@ -0,0 +1,58 @@
1
+ import { interceptors } from "./selected-logs.js";
2
+ import { interceptGlobalError } from "./intercept-global-error.js";
3
+ const LOG_LEVELS = [
4
+ 'debug',
5
+ 'info',
6
+ 'warn',
7
+ 'error'
8
+ ];
9
+ const defaultConfig = {
10
+ showLevel: false,
11
+ showTimestamp: false,
12
+ level: 'info',
13
+ prefix: ''
14
+ };
15
+ let config = {
16
+ ...defaultConfig
17
+ };
18
+ function configureLogger(options) {
19
+ config = {
20
+ ...defaultConfig,
21
+ ...options
22
+ };
23
+ }
24
+ function getLogLevel() {
25
+ return config.level;
26
+ }
27
+ function shouldLog(level) {
28
+ return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(getLogLevel());
29
+ }
30
+ function getFormattedPrefix(level) {
31
+ const parts = [];
32
+ if (config.prefix) parts.push(`[${config.prefix}]`);
33
+ if (config.showLevel) parts.push(`[${level.toUpperCase()}]`);
34
+ return parts;
35
+ }
36
+ configureLogger({
37
+ showLevel: true,
38
+ showTimestamp: false,
39
+ level: 'development' === process.env.NODE_ENV ? 'debug' : 'error',
40
+ prefix: 'MiaoDa'
41
+ });
42
+ let logger = {
43
+ debug (message, ...args) {
44
+ if (shouldLog('debug')) console.log(...getFormattedPrefix('debug'), message, ...args);
45
+ },
46
+ info (message, ...args) {
47
+ if (shouldLog('info')) console.log(...getFormattedPrefix('info'), message, ...args);
48
+ },
49
+ warn (message, ...args) {
50
+ if (shouldLog('warn')) console.log(...getFormattedPrefix('warn'), message, ...args);
51
+ },
52
+ error (message, ...args) {
53
+ if (shouldLog('error')) console.error(...getFormattedPrefix('error'), message, ...args);
54
+ }
55
+ };
56
+ for (const interceptor of interceptors)logger = interceptor(logger);
57
+ interceptGlobalError();
58
+ export { logger };
@@ -0,0 +1,2 @@
1
+ import type { SelectedLog } from './log-types';
2
+ export declare const mockLogs: SelectedLog[];
@@ -0,0 +1,125 @@
1
+ const mockLogs = [
2
+ {
3
+ id: '1',
4
+ type: 'renderError',
5
+ level: 'error',
6
+ data: {
7
+ message: 'Not implemented',
8
+ stack: 'Error: Not implemented\n at ToDoPage (/client/src/pages/Todo.tsx:95:8)\n at Object.react_stack_bottom_frame (/node_modules/react-dom/cjs/react-dom-client.development.js:25904:0)\n at renderWithHooks (/node_modules/react-dom/cjs/react-dom-client.development.js:7662:0)\n at updateFunctionComponent (/node_modules/react-dom/cjs/react-dom-client.development.js:10166:0)\n at beginWork (/node_modules/react-dom/cjs/react-dom-client.development.js:11778:0)\n at runWithFiberInDEV (/node_modules/react-dom/cjs/react-dom-client.development.js:871:0)\n at performUnitOfWork (/node_modules/react-dom/cjs/react-dom-client.development.js:17641:0)\n at workLoopSync (/node_modules/react-dom/cjs/react-dom-client.development.js:17469:38)\n at renderRootSync (/node_modules/react-dom/cjs/react-dom-client.development.js:17450:0)\n at performWorkOnRoot (/node_modules/react-dom/cjs/react-dom-client.development.js:16583:0)'
9
+ }
10
+ },
11
+ {
12
+ id: '2',
13
+ level: 'error',
14
+ type: 'routerError',
15
+ data: {
16
+ path: '/todo1'
17
+ }
18
+ },
19
+ {
20
+ id: '3',
21
+ type: 'networkRequest',
22
+ level: 'info',
23
+ data: {
24
+ method: 'POST',
25
+ status: 201,
26
+ statusText: 'Created',
27
+ path: '/api/todo',
28
+ requestData: {
29
+ title: '1',
30
+ content: '1'
31
+ },
32
+ responseData: {
33
+ id: 14,
34
+ title: '1',
35
+ content: '1',
36
+ completed: false
37
+ },
38
+ traceID: '5ace3e1b-f91e-43a6-ab72-b0a3f38d8171'
39
+ }
40
+ },
41
+ {
42
+ id: '4',
43
+ type: 'noCategory',
44
+ level: 'error',
45
+ data: {
46
+ message: {
47
+ type: 'HTTP Response',
48
+ url: '/api/todo1',
49
+ method: 'POST',
50
+ data: '{"title":"123","content":"123"}',
51
+ headers: {
52
+ Accept: 'application/json',
53
+ 'Content-Type': 'application/json',
54
+ 'X-Suda-Csrf-Token': '[REDACTED]',
55
+ 'X-Trace-ID': '53e065cb-604d-478b-8a0c-e175772ac49e'
56
+ },
57
+ status: 404,
58
+ statusText: 'Not Found',
59
+ message: 'Request failed with status code 404',
60
+ responseData: {
61
+ code: 'NOT_FOUND',
62
+ message: 'Cannot POST /api/todo1',
63
+ success: false,
64
+ data: null,
65
+ timestamp: 1762331639509,
66
+ httpStatus: 404,
67
+ error: {
68
+ code: 'NOT_FOUND',
69
+ message: 'Cannot POST /api/todo1',
70
+ details: '{"message":"Cannot POST /api/todo1","error":"Not Found","statusCode":404}'
71
+ }
72
+ },
73
+ responseTime: 7
74
+ },
75
+ args: []
76
+ }
77
+ },
78
+ {
79
+ id: '5',
80
+ type: 'noCategory',
81
+ level: 'error',
82
+ data: {
83
+ message: 'global error',
84
+ args: [
85
+ 'Uncaught Error: Not implemented',
86
+ 'http://localhost:8080/main.js',
87
+ 116068,
88
+ 7,
89
+ {}
90
+ ]
91
+ }
92
+ },
93
+ {
94
+ id: '6',
95
+ type: 'noCategory',
96
+ level: 'error',
97
+ data: {
98
+ message: 'global error',
99
+ args: [
100
+ {
101
+ isTrusted: true
102
+ }
103
+ ]
104
+ }
105
+ },
106
+ {
107
+ id: '7',
108
+ type: 'globalError',
109
+ level: 'error',
110
+ data: {
111
+ message: 'Not implemented',
112
+ stack: 'Error: Not implemented\n at ./client/src/pages/Todo.tsx (/client/src/pages/Todo.tsx:35:6)\n at __webpack_require__ (http://localhost:8080/main.js:200726:21)\n at fn (/webpack/runtime/hot_module_replacement:60:0)\n at ./client/src/app.tsx (http://localhost:8080/main.js:114432:64)\n at __webpack_require__ (http://localhost:8080/main.js:200726:21)\n at fn (/webpack/runtime/hot_module_replacement:60:0)\n at ./client/src/index.tsx (http://localhost:8080/main.js:115780:61)\n at __webpack_require__ (http://localhost:8080/main.js:200726:21)\n at http://localhost:8080/main.js:201993:27\n at http://localhost:8080/main.js:201994:3'
113
+ }
114
+ },
115
+ {
116
+ id: '8',
117
+ type: 'unhandledRejectionError',
118
+ level: 'error',
119
+ data: {
120
+ message: 'Not implemented',
121
+ stack: 'Error: Not implemented\n at ./client/src/pages/Todo.tsx (/client/src/pages/Todo.tsx:37:15)\n at __webpack_require__ (http://localhost:8080/main.js:200746:21)\n at fn (/webpack/runtime/hot_module_replacement:60:0)\n at ./client/src/app.tsx (http://localhost:8080/main.js:114452:64)\n at __webpack_require__ (http://localhost:8080/main.js:200746:21)\n at fn (/webpack/runtime/hot_module_replacement:60:0)\n at ./client/src/index.tsx (http://localhost:8080/main.js:115800:61)\n at __webpack_require__ (http://localhost:8080/main.js:200746:21)\n at http://localhost:8080/main.js:202013:27\n at http://localhost:8080/main.js:202014:3'
122
+ }
123
+ }
124
+ ];
125
+ export { mockLogs };
@@ -0,0 +1,2 @@
1
+ import { type LogInterceptor } from './logger';
2
+ export declare const interceptors: LogInterceptor[];