@gadmin2n/schematics 0.0.116 → 0.0.118

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.
@@ -17,7 +17,7 @@ import modules from './modules';
17
17
  import { ScheduleModule } from '@nestjs/schedule';
18
18
  import { ServeStaticModule } from '@nestjs/serve-static';
19
19
  import { join } from 'path';
20
- import { LogFormat } from './lib/logger';
20
+ import { consoleFormat } from './lib/logger';
21
21
  import { AgendaModule } from './modules/agenda/agenda.module';
22
22
  import { HealthModule } from './modules/health/health.module';
23
23
  import { RoleModule } from './modules/role/role.module';
@@ -54,7 +54,7 @@ import { RolesRefresherService } from './modules/role/roles-refresher.service';
54
54
  level: loggerConfig.level,
55
55
  transports: [
56
56
  new winston.transports.Console({
57
- format: LogFormat,
57
+ format: consoleFormat,
58
58
  }),
59
59
  ],
60
60
  };
@@ -1,19 +1,37 @@
1
1
  import * as winston from 'winston';
2
2
 
3
- export const LogFormat = winston.format.combine(
3
+ const baseFormats = [
4
4
  winston.format.splat(),
5
- winston.format.timestamp({
6
- format: 'YYYY-MM-DD HH:mm:ss.SSS',
7
- }),
5
+ winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
8
6
  winston.format.errors({ stack: true }),
7
+ ];
8
+
9
+ // 非终端(文件重定向、容器日志收集等)输出纯 JSON,方便机器解析
10
+ export const LogFormat = winston.format.combine(
11
+ ...baseFormats,
9
12
  winston.format.json(),
10
13
  );
11
14
 
15
+ // 终端输出:带 ANSI 颜色,方便肉眼阅读
16
+ const ttyFormat = winston.format.combine(
17
+ ...baseFormats,
18
+ winston.format.colorize(),
19
+ winston.format.printf(
20
+ ({ timestamp, level, message, context, stack, ...rest }) => {
21
+ const ctx = context ? ` [${context}]` : '';
22
+ const extra = Object.keys(rest).length ? ' ' + JSON.stringify(rest) : '';
23
+ return `${timestamp}${ctx} ${level}: ${stack ?? message}${extra}`;
24
+ },
25
+ ),
26
+ );
27
+
28
+ export const consoleFormat = process.stdout.isTTY ? ttyFormat : LogFormat;
29
+
12
30
  export const loggerInstance = winston.createLogger({
13
31
  level: 'info',
14
32
  transports: [
15
33
  new winston.transports.Console({
16
- format: LogFormat,
34
+ format: consoleFormat,
17
35
  }),
18
36
  ],
19
37
  });
@@ -1,5 +1,8 @@
1
1
  import './lib/tracing'; // OpenTelemetry Prisma instrumentation - 必须第一个导入
2
2
 
3
+ // 非终端环境禁用 ANSI 颜色,避免日志收集时出现裸转义码
4
+ if (!process.stdout.isTTY) process.env.NO_COLOR = '1';
5
+
3
6
  import { AllExceptionsFilter, UserType } from '@gadmin2n/nest-common';
4
7
  import {
5
8
  ClassSerializerInterceptor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadmin2n/schematics",
3
- "version": "0.0.116",
3
+ "version": "0.0.118",
4
4
  "description": "Gadmin - modern, fast, powerful node.js web framework (@schematics)",
5
5
  "main": "dist/index.js",
6
6
  "files": [