Skip to content

Commit de37f64

Browse files
committed
feat: 增加环境变量用于禁用日志选项
1 parent 4088de9 commit de37f64

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

server/moleculer.config.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import brokerConfig from 'tailchat-server-sdk/dist/runner/moleculer.config';
1+
import {
2+
defaultBrokerConfig,
3+
config,
4+
BrokerOptions,
5+
} from 'tailchat-server-sdk';
26

3-
export default {
4-
...brokerConfig,
7+
const brokerConfig: BrokerOptions = {
8+
...defaultBrokerConfig,
59
};
10+
11+
if (config.feature.disableLogger === true) {
12+
brokerConfig.logger = false;
13+
}
14+
15+
export default brokerConfig;

server/packages/sdk/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { defaultBrokerConfig } from './runner/moleculer.config';
12
export { TcService } from './services/base';
23
export { TcBroker } from './services/broker';
34
export type { TcDbService } from './services/mixins/db.mixin';
@@ -49,6 +50,7 @@ export * from './const';
4950

5051
// other
5152
export { Utils, Errors } from 'moleculer';
53+
export type { BrokerOptions } from 'moleculer';
5254

5355
/**
5456
* 统一处理未捕获的错误, 防止直接把应用打崩

server/packages/sdk/src/runner/moleculer.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import 'moleculer-repl';
3636
* }
3737
* }
3838
*/
39-
const brokerConfig: BrokerOptions = {
39+
export const defaultBrokerConfig: BrokerOptions = {
4040
// Namespace of nodes to segment your nodes on the same network.
4141
namespace: 'tailchat',
4242
// Unique node identifier. Must be unique in a namespace.
@@ -310,5 +310,3 @@ const brokerConfig: BrokerOptions = {
310310
stopped: async (broker: ServiceBroker): Promise<void> => {},
311311
*/
312312
};
313-
314-
export default brokerConfig;

server/packages/sdk/src/services/lib/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const config = {
3737
apiUrl,
3838
staticUrl: `${apiUrl}/static/`,
3939
enableOpenapi: true, // 是否开始openapi
40+
4041
emailVerification: checkEnvTrusty(process.env.EMAIL_VERIFY) || false, // 是否在注册后验证邮箱可用性
4142
smtp: {
4243
senderName: process.env.SMTP_SENDER, // 发邮件者显示名称
@@ -45,6 +46,7 @@ export const config = {
4546
enablePrometheus: checkEnvTrusty(process.env.PROMETHEUS),
4647
feature: {
4748
disableFileCheck: checkEnvTrusty(process.env.DISABLE_FILE_CHECK),
49+
disableLogger: checkEnvTrusty(process.env.DISABLE_LOGGER), // 是否关闭日志
4850
},
4951
};
5052

website/docs/deployment/environment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ title: 环境变量
2020
| SMTP_URI | - | 邮件服务连接地址(示例: `smtp://username:[email protected]/?pool=true`) |
2121
| FILE_LIMIT | 1048576 | 文件/图片上传的大小限制,默认为1m,请输入数字 |
2222
| EMAIL_VERIFY | - | 是否开启邮箱校验, 如果为 "1" 或者 "true" 则在注册时增加邮箱校验控制 |
23+
| DISABLE_LOGGER | - | 是否禁用日志输出, 如果为 "1" 或者 "true" 则在运行中关闭日志 |
2324

2425
> 部分环境变量示例可见: https://github.com/msgbyte/tailchat/blob/master/server/.env.example
2526

0 commit comments

Comments
 (0)