@nocobase/logger 1.2.12-alpha → 1.3.0-alpha.20240710084543

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/logger",
3
- "version": "1.2.12-alpha",
3
+ "version": "1.3.0-alpha.20240710084543",
4
4
  "description": "nocobase logging library",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
@@ -18,5 +18,5 @@
18
18
  "winston-daily-rotate-file": "^5.0.0",
19
19
  "winston-transport": "^4.7.0"
20
20
  },
21
- "gitHead": "553231d4882496cb7f1f17fa7541899ce82a27ab"
21
+ "gitHead": "07a8b596fc64a9779a194cb9b0dc2ca7570ed9d4"
22
22
  }
package/lib/config.d.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export declare const getLoggerLevel: () => string;
10
- export declare const getLoggerFilePath: (...paths: string[]) => string;
11
- export declare const getLoggerTransport: () => ('console' | 'file' | 'dailyRotateFile')[];
12
- export declare const getLoggerFormat: () => 'logfmt' | 'json' | 'delimiter' | 'console';
package/lib/config.js DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var config_exports = {};
39
- __export(config_exports, {
40
- getLoggerFilePath: () => getLoggerFilePath,
41
- getLoggerFormat: () => getLoggerFormat,
42
- getLoggerLevel: () => getLoggerLevel,
43
- getLoggerTransport: () => getLoggerTransport
44
- });
45
- module.exports = __toCommonJS(config_exports);
46
- var import_path = __toESM(require("path"));
47
- const getLoggerLevel = /* @__PURE__ */ __name(() => process.env.LOGGER_LEVEL || (process.env.APP_ENV === "development" ? "debug" : "info"), "getLoggerLevel");
48
- const getLoggerFilePath = /* @__PURE__ */ __name((...paths) => {
49
- return import_path.default.resolve(process.env.LOGGER_BASE_PATH || import_path.default.resolve(process.cwd(), "storage", "logs"), ...paths);
50
- }, "getLoggerFilePath");
51
- const getLoggerTransport = /* @__PURE__ */ __name(() => (process.env.LOGGER_TRANSPORT || "console,dailyRotateFile").split(","), "getLoggerTransport");
52
- const getLoggerFormat = /* @__PURE__ */ __name(() => process.env.LOGGER_FORMAT || (process.env.APP_ENV === "development" ? "console" : "json"), "getLoggerFormat");
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- getLoggerFilePath,
56
- getLoggerFormat,
57
- getLoggerLevel,
58
- getLoggerTransport
59
- });
package/lib/format.d.ts DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import winston from 'winston';
10
- import { LoggerOptions } from './logger';
11
- /**
12
- * @internal
13
- */
14
- export declare const getFormat: (format?: LoggerOptions['format']) => winston.Logform.Format;
15
- /**
16
- * @internal
17
- */
18
- export declare const colorFormat: winston.Logform.Format;
19
- /**
20
- * @internal
21
- */
22
- export declare const stripColorFormat: winston.Logform.Format;
23
- /**
24
- * @internal
25
- *https://brandur.org/logfmt
26
- */
27
- export declare const logfmtFormat: winston.Logform.Format;
28
- /**
29
- * @internal
30
- */
31
- export declare const consoleFormat: winston.Logform.Format;
32
- /**
33
- * @internal
34
- */
35
- export declare const delimiterFormat: winston.Logform.Format;
36
- /**
37
- * @internal
38
- */
39
- export declare const escapeFormat: winston.Logform.Format;
40
- /**
41
- * @internal
42
- */
43
- export declare const sortFormat: winston.Logform.Format;
package/lib/format.js DELETED
@@ -1,179 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var format_exports = {};
39
- __export(format_exports, {
40
- colorFormat: () => colorFormat,
41
- consoleFormat: () => consoleFormat,
42
- delimiterFormat: () => delimiterFormat,
43
- escapeFormat: () => escapeFormat,
44
- getFormat: () => getFormat,
45
- logfmtFormat: () => logfmtFormat,
46
- sortFormat: () => sortFormat,
47
- stripColorFormat: () => stripColorFormat
48
- });
49
- module.exports = __toCommonJS(format_exports);
50
- var import_chalk = __toESM(require("chalk"));
51
- var import_winston = __toESM(require("winston"));
52
- var import_config = require("./config");
53
- var import_lodash = require("lodash");
54
- const DEFAULT_DELIMITER = "|";
55
- const colorize = {};
56
- const getFormat = /* @__PURE__ */ __name((format) => {
57
- const configFormat = format || (0, import_config.getLoggerFormat)();
58
- let logFormat;
59
- switch (configFormat) {
60
- case "console":
61
- logFormat = import_winston.default.format.combine(consoleFormat);
62
- break;
63
- case "logfmt":
64
- logFormat = logfmtFormat;
65
- break;
66
- case "delimiter":
67
- logFormat = import_winston.default.format.combine(escapeFormat, delimiterFormat);
68
- break;
69
- case "json":
70
- logFormat = import_winston.default.format.combine(import_winston.default.format.json({ deterministic: false }));
71
- break;
72
- default:
73
- return import_winston.default.format.combine(format);
74
- }
75
- return import_winston.default.format.combine(sortFormat, logFormat);
76
- }, "getFormat");
77
- const colorFormat = import_winston.default.format((info) => {
78
- Object.entries(info).forEach(([k, v]) => {
79
- var _a;
80
- const level = info["level"];
81
- if (colorize[k]) {
82
- info[k] = colorize[k](v);
83
- return;
84
- }
85
- if ((_a = colorize[level]) == null ? void 0 : _a[k]) {
86
- info[k] = colorize[level][k](v);
87
- return;
88
- }
89
- });
90
- return info;
91
- })();
92
- const stripColorFormat = import_winston.default.format((info) => {
93
- Object.entries(info).forEach(([k, v]) => {
94
- if (typeof v !== "string") {
95
- return;
96
- }
97
- const regex = new RegExp(`\\x1b\\[\\d+m`, "g");
98
- info[k] = v.replace(regex, "");
99
- });
100
- return info;
101
- })();
102
- const logfmtFormat = import_winston.default.format.printf(
103
- (info) => Object.entries(info).map(([k, v]) => {
104
- if (typeof v === "object") {
105
- try {
106
- v = JSON.stringify(v);
107
- } catch (error) {
108
- v = String(v);
109
- }
110
- }
111
- if (v === void 0 || v === null) {
112
- v = "";
113
- }
114
- return `${k}=${v}`;
115
- }).join(" ")
116
- );
117
- const consoleFormat = import_winston.default.format.printf((info) => {
118
- const keys = ["level", "timestamp", "message"];
119
- Object.entries(info).forEach(([k, v]) => {
120
- if (typeof v === "object") {
121
- if ((0, import_lodash.isEmpty)(v)) {
122
- info[k] = "";
123
- return;
124
- }
125
- try {
126
- info[k] = JSON.stringify(v);
127
- } catch (error) {
128
- info[k] = String(v);
129
- }
130
- }
131
- if (v === void 0 || v === null) {
132
- info[k] = "";
133
- }
134
- });
135
- const tags = Object.entries(info).filter(([k, v]) => !keys.includes(k) && v).map(([k, v]) => `${k}=${v}`).join(" ");
136
- const level = `[${info.level}]`.padEnd(7, " ");
137
- const message = info.message.padEnd(44, " ");
138
- const color = {
139
- error: import_chalk.default.red,
140
- warn: import_chalk.default.yellow,
141
- info: import_chalk.default.green,
142
- debug: import_chalk.default.blue,
143
- trace: import_chalk.default.cyan
144
- }[info.level] || import_chalk.default.white;
145
- const colorized = message.startsWith("Executing") ? color(`${info.timestamp} ${level}`) + ` ${message}` : color(`${info.timestamp} ${level} ${message}`);
146
- return `${colorized} ${tags}`;
147
- });
148
- const delimiterFormat = import_winston.default.format.printf(
149
- (info) => Object.entries(info).map(([, v]) => {
150
- if (typeof v === "object") {
151
- try {
152
- return JSON.stringify(v);
153
- } catch (error) {
154
- return String(v);
155
- }
156
- }
157
- return v;
158
- }).join(DEFAULT_DELIMITER)
159
- );
160
- const escapeFormat = import_winston.default.format((info) => {
161
- let { message } = info;
162
- if (typeof message === "string" && message.includes(DEFAULT_DELIMITER)) {
163
- message = message.replace(/"/g, '\\"');
164
- message = `"${message}"`;
165
- }
166
- return { ...info, message };
167
- })();
168
- const sortFormat = import_winston.default.format((info) => ({ level: info.level, ...info }))();
169
- // Annotate the CommonJS export names for ESM import in node:
170
- 0 && (module.exports = {
171
- colorFormat,
172
- consoleFormat,
173
- delimiterFormat,
174
- escapeFormat,
175
- getFormat,
176
- logfmtFormat,
177
- sortFormat,
178
- stripColorFormat
179
- });
package/lib/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export * from './config';
10
- export * from './logger';
11
- export * from './system-logger';
12
- export * from './request-logger';
13
- export * from './transports';
package/lib/index.js DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var src_exports = {};
25
- module.exports = __toCommonJS(src_exports);
26
- __reExport(src_exports, require("./config"), module.exports);
27
- __reExport(src_exports, require("./logger"), module.exports);
28
- __reExport(src_exports, require("./system-logger"), module.exports);
29
- __reExport(src_exports, require("./request-logger"), module.exports);
30
- __reExport(src_exports, require("./transports"), module.exports);
31
- // Annotate the CommonJS export names for ESM import in node:
32
- 0 && (module.exports = {
33
- ...require("./config"),
34
- ...require("./logger"),
35
- ...require("./system-logger"),
36
- ...require("./request-logger"),
37
- ...require("./transports")
38
- });
package/lib/logger.d.ts DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import winston, { LeveledLogMethod, Logger as WinstonLogger } from 'winston';
10
- import 'winston-daily-rotate-file';
11
- interface Logger extends WinstonLogger {
12
- trace: LeveledLogMethod;
13
- }
14
- interface LoggerOptions extends Omit<winston.LoggerOptions, 'transports' | 'format'> {
15
- dirname?: string;
16
- filename?: string;
17
- format?: 'logfmt' | 'json' | 'delimiter' | 'console' | winston.Logform.Format;
18
- transports?: ('console' | 'file' | 'dailyRotateFile' | winston.transport)[];
19
- }
20
- export declare const levels: {
21
- trace: number;
22
- debug: number;
23
- info: number;
24
- warn: number;
25
- error: number;
26
- };
27
- export declare const createLogger: (options: LoggerOptions) => Logger;
28
- /**
29
- * @internal
30
- */
31
- export declare const createConsoleLogger: (options?: winston.LoggerOptions) => Logger;
32
- export { Logger, LoggerOptions };
package/lib/logger.js DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var logger_exports = {};
39
- __export(logger_exports, {
40
- createConsoleLogger: () => createConsoleLogger,
41
- createLogger: () => createLogger,
42
- levels: () => levels
43
- });
44
- module.exports = __toCommonJS(logger_exports);
45
- var import_winston = __toESM(require("winston"));
46
- var import_winston_daily_rotate_file = require("winston-daily-rotate-file");
47
- var import_config = require("./config");
48
- var import_transports = require("./transports");
49
- var import_format = require("./format");
50
- const levels = {
51
- trace: 4,
52
- debug: 3,
53
- info: 2,
54
- warn: 1,
55
- error: 0
56
- };
57
- const createLogger = /* @__PURE__ */ __name((options) => {
58
- if (process.env.GITHUB_ACTIONS) {
59
- return createConsoleLogger();
60
- }
61
- const { format, ...rest } = options;
62
- const winstonOptions = {
63
- levels,
64
- level: (0, import_config.getLoggerLevel)(),
65
- ...rest,
66
- transports: (0, import_transports.getTransports)(options)
67
- };
68
- return import_winston.default.createLogger(winstonOptions);
69
- }, "createLogger");
70
- const createConsoleLogger = /* @__PURE__ */ __name((options) => {
71
- const { format, ...rest } = options || {};
72
- return import_winston.default.createLogger({
73
- levels,
74
- level: (0, import_config.getLoggerLevel)(),
75
- format: import_winston.default.format.combine(
76
- import_winston.default.format.timestamp({
77
- format: "YYYY-MM-DD HH:mm:ss"
78
- }),
79
- format || import_format.consoleFormat
80
- ),
81
- ...rest || {},
82
- transports: [new import_winston.default.transports.Console()]
83
- });
84
- }, "createConsoleLogger");
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- createConsoleLogger,
88
- createLogger,
89
- levels
90
- });
@@ -1,15 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Logger, LoggerOptions } from './logger';
10
- export interface RequestLoggerOptions extends LoggerOptions {
11
- skip?: (ctx?: any) => Promise<boolean>;
12
- requestWhitelist?: string[];
13
- responseWhitelist?: string[];
14
- }
15
- export declare const requestLogger: (appName: string, requestLogger: Logger, options?: RequestLoggerOptions) => (ctx: any, next: any) => Promise<void>;
@@ -1,101 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp(target, name, { get: all[name], enumerable: true });
18
- };
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var request_logger_exports = {};
29
- __export(request_logger_exports, {
30
- requestLogger: () => requestLogger
31
- });
32
- module.exports = __toCommonJS(request_logger_exports);
33
- var import_lodash = require("lodash");
34
- const defaultRequestWhitelist = [
35
- "action",
36
- "header.x-role",
37
- "header.x-hostname",
38
- "header.x-timezone",
39
- "header.x-locale",
40
- "header.x-authenticator",
41
- "header.x-data-source",
42
- "referer"
43
- ];
44
- const defaultResponseWhitelist = ["status"];
45
- const requestLogger = /* @__PURE__ */ __name((appName, requestLogger2, options) => {
46
- return async (ctx, next) => {
47
- var _a, _b, _c, _d, _e, _f, _g, _h;
48
- const reqId = ctx.reqId;
49
- const path = /^\/api\/(.+):(.+)/.exec(ctx.path);
50
- const contextLogger = ctx.app.log.child({ reqId, module: path == null ? void 0 : path[1], submodule: path == null ? void 0 : path[2] });
51
- ctx.logger = ctx.log = contextLogger;
52
- const startTime = Date.now();
53
- const requestInfo = {
54
- method: ctx.method,
55
- path: ctx.url
56
- };
57
- requestLogger2.info({
58
- message: `request ${ctx.method} ${ctx.url}`,
59
- ...requestInfo,
60
- req: (0, import_lodash.pick)(ctx.request.toJSON(), (options == null ? void 0 : options.requestWhitelist) || defaultRequestWhitelist),
61
- action: (_b = (_a = ctx.action) == null ? void 0 : _a.toJSON) == null ? void 0 : _b.call(_a),
62
- app: appName,
63
- reqId
64
- });
65
- let error;
66
- try {
67
- await next();
68
- } catch (e) {
69
- error = e;
70
- } finally {
71
- const cost = Date.now() - startTime;
72
- const status = ctx.status;
73
- const info = {
74
- message: `response ${ctx.url}`,
75
- ...requestInfo,
76
- res: (0, import_lodash.pick)(ctx.response.toJSON(), (options == null ? void 0 : options.responseWhitelist) || defaultResponseWhitelist),
77
- action: (_d = (_c = ctx.action) == null ? void 0 : _c.toJSON) == null ? void 0 : _d.call(_c),
78
- userId: (_f = (_e = ctx.auth) == null ? void 0 : _e.user) == null ? void 0 : _f.id,
79
- status: ctx.status,
80
- cost,
81
- app: appName,
82
- reqId
83
- };
84
- if (Math.floor(status / 100) == 5) {
85
- requestLogger2.error({ ...info, res: ((_g = ctx.body) == null ? void 0 : _g["errors"]) || ctx.body });
86
- } else if (Math.floor(status / 100) == 4) {
87
- requestLogger2.warn({ ...info, res: ((_h = ctx.body) == null ? void 0 : _h["errors"]) || ctx.body });
88
- } else {
89
- requestLogger2.info(info);
90
- }
91
- }
92
- ctx.res.setHeader("X-Request-Id", reqId);
93
- if (error) {
94
- throw error;
95
- }
96
- };
97
- }, "requestLogger");
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {
100
- requestLogger
101
- });
@@ -1,26 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Logger, LoggerOptions } from './logger';
10
- export interface SystemLoggerOptions extends LoggerOptions {
11
- seperateError?: boolean;
12
- }
13
- export type logMethod = (message: string, meta?: {
14
- module?: string;
15
- submodule?: string;
16
- method?: string;
17
- [key: string]: any;
18
- }) => SystemLogger;
19
- export interface SystemLogger extends Omit<Logger, 'info' | 'warn' | 'error' | 'debug' | 'trace'> {
20
- info: logMethod;
21
- warn: logMethod;
22
- error: logMethod;
23
- debug: logMethod;
24
- trace: logMethod;
25
- }
26
- export declare const createSystemLogger: (options: SystemLoggerOptions) => SystemLogger;
@@ -1,147 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var system_logger_exports = {};
39
- __export(system_logger_exports, {
40
- createSystemLogger: () => createSystemLogger
41
- });
42
- module.exports = __toCommonJS(system_logger_exports);
43
- var import_winston = __toESM(require("winston"));
44
- var import_logger = require("./logger");
45
- var import_winston_transport = __toESM(require("winston-transport"));
46
- var import_triple_beam = require("triple-beam");
47
- var import_format = require("./format");
48
- const _SystemLoggerTransport = class _SystemLoggerTransport extends import_winston_transport.default {
49
- logger;
50
- errorLogger;
51
- constructor({ seperateError, filename, ...options }) {
52
- super({ ...options, format: null });
53
- this.logger = (0, import_logger.createLogger)({
54
- ...options,
55
- filename,
56
- format: import_winston.default.format.combine(
57
- (0, import_winston.format)((info) => seperateError && info.level === "error" ? false : info)(),
58
- (0, import_format.getFormat)(options.format)
59
- )
60
- });
61
- if (seperateError) {
62
- this.errorLogger = (0, import_logger.createLogger)({
63
- ...options,
64
- filename: `${filename}_error`,
65
- level: "error"
66
- });
67
- }
68
- }
69
- log(info, callback) {
70
- const { level, message, reqId, app, dataSourceKey, stack, cause, [import_triple_beam.SPLAT]: args } = info;
71
- const logger = level === "error" && this.errorLogger ? this.errorLogger : this.logger;
72
- const { module: module2, submodule, method, ...meta } = (args == null ? void 0 : args[0]) || {};
73
- if (!(cause == null ? void 0 : cause.onlyLogCause)) {
74
- logger.log({
75
- level,
76
- message,
77
- stack,
78
- meta,
79
- module: module2 || info["module"] || "",
80
- submodule: submodule || info["submodule"] || "",
81
- method: method || "",
82
- app,
83
- reqId,
84
- dataSourceKey: dataSourceKey || "main"
85
- });
86
- }
87
- if (cause) {
88
- logger.log({
89
- level,
90
- message: cause.message,
91
- stack: cause.stack,
92
- app,
93
- reqId
94
- });
95
- }
96
- callback(null, true);
97
- }
98
- close() {
99
- this.logger.close();
100
- if (this.errorLogger) {
101
- this.errorLogger.close();
102
- }
103
- }
104
- };
105
- __name(_SystemLoggerTransport, "SystemLoggerTransport");
106
- let SystemLoggerTransport = _SystemLoggerTransport;
107
- function child(defaultRequestMetadata) {
108
- const logger = this;
109
- return Object.create(logger, {
110
- write: {
111
- value: function(info) {
112
- const infoClone = Object.assign({}, defaultRequestMetadata, info);
113
- if (info instanceof Error) {
114
- infoClone.stack = info.stack;
115
- infoClone.message = info.message;
116
- infoClone.cause = info.cause;
117
- }
118
- logger.write(infoClone);
119
- }
120
- }
121
- });
122
- }
123
- __name(child, "child");
124
- const createSystemLogger = /* @__PURE__ */ __name((options) => {
125
- const transport = new SystemLoggerTransport(options);
126
- transport.once("unpipe", () => {
127
- transport.close();
128
- });
129
- const logger = import_winston.default.createLogger({
130
- levels: import_logger.levels,
131
- transports: [transport]
132
- // Due to the use of custom log levels,
133
- // we have to use the any type until Winston updates the type definitions.
134
- });
135
- return new Proxy(logger, {
136
- get(target, prop) {
137
- if (prop === "child") {
138
- return child.bind(target);
139
- }
140
- return Reflect.get(target, prop);
141
- }
142
- });
143
- }, "createSystemLogger");
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- createSystemLogger
147
- });
@@ -1,20 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import winston from 'winston';
10
- import { DailyRotateFileTransportOptions } from 'winston-daily-rotate-file';
11
- import { LoggerOptions } from './logger';
12
- export declare const Transports: {
13
- console: (options?: winston.transports.ConsoleTransportOptions) => winston.transports.ConsoleTransportInstance;
14
- file: (options?: winston.transports.FileTransportOptions) => winston.transports.FileTransportInstance;
15
- dailyRotateFile: (options?: DailyRotateFileTransportOptions) => import("winston-daily-rotate-file");
16
- };
17
- /**
18
- * @internal
19
- */
20
- export declare const getTransports: (options: LoggerOptions) => winston.transports.ConsoleTransportInstance | (import("winston-daily-rotate-file") | winston.transport)[];
package/lib/transports.js DELETED
@@ -1,95 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var transports_exports = {};
39
- __export(transports_exports, {
40
- Transports: () => Transports,
41
- getTransports: () => getTransports
42
- });
43
- module.exports = __toCommonJS(transports_exports);
44
- var import_winston = __toESM(require("winston"));
45
- var import_config = require("./config");
46
- var import_path = __toESM(require("path"));
47
- var import_format = require("./format");
48
- const Transports = {
49
- console: (options) => new import_winston.default.transports.Console(options),
50
- file: (options) => new import_winston.default.transports.File({
51
- maxsize: Number(process.env.LOGGER_MAX_SIZE) || 1024 * 1024 * 20,
52
- maxFiles: Number(process.env.LOGGER_MAX_FILES) || 10,
53
- ...options
54
- }),
55
- dailyRotateFile: (options) => new import_winston.default.transports.DailyRotateFile({
56
- maxSize: Number(process.env.LOGGER_MAX_SIZE),
57
- maxFiles: Number(process.env.LOGGER_MAX_FILES) || "14d",
58
- ...options
59
- })
60
- };
61
- const getTransports = /* @__PURE__ */ __name((options) => {
62
- const { filename, format: _format, transports: _transports } = options;
63
- let { dirname } = options;
64
- const configTransports = _transports || (0, import_config.getLoggerTransport)();
65
- const configFormat = _format || (0, import_config.getLoggerFormat)();
66
- dirname = dirname || (0, import_config.getLoggerFilePath)();
67
- if (!import_path.default.isAbsolute(dirname)) {
68
- dirname = import_path.default.resolve(process.cwd(), dirname);
69
- }
70
- const format = import_winston.default.format.combine(
71
- import_winston.default.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
72
- (0, import_format.getFormat)(configFormat)
73
- );
74
- const transports = {
75
- console: () => Transports.console({
76
- format: import_winston.default.format.combine(format)
77
- }),
78
- file: () => Transports.file({
79
- dirname,
80
- filename: filename.includes(".log") ? filename : `${filename}.log`,
81
- format
82
- }),
83
- dailyRotateFile: () => Transports.dailyRotateFile({
84
- dirname,
85
- filename: filename.includes("%DATE%") || filename.includes(".log") ? filename : `${filename}_%DATE%.log`,
86
- format
87
- })
88
- };
89
- return (configTransports == null ? void 0 : configTransports.map((t) => typeof t === "string" ? transports[t]() : t)) || transports["console"]();
90
- }, "getTransports");
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- Transports,
94
- getTransports
95
- });