gemercheung 3 年之前
父節點
當前提交
99b09f62ee
共有 8 個文件被更改,包括 70 次插入12 次删除
  1. 4 2
      config.dev.yaml
  2. 3 0
      config.production.yaml
  3. 3 0
      config.production1.yaml
  4. 3 0
      config.yaml
  5. 9 6
      src/app.module.ts
  6. 40 0
      src/logConfig.ts
  7. 7 3
      src/main.ts
  8. 1 1
      src/rotate/rotate.service.ts

+ 4 - 2
config.dev.yaml

@@ -3,17 +3,19 @@ app:
   prefix: /mnt/metaverse/scene
   startPoint: 93
 
+log:
+  logFolder: /var/log/metaverse
+
 queueConfig:
   move: 10
   rotate: 2
 
+
 http:
   host: '0.0.0.0'
   port: 6688
 
 
-# grpc:
-#   url: '221.4.210.172:23000'
 grpc:
   url: '192.168.0.200:3000'
 

+ 3 - 0
config.production.yaml

@@ -7,6 +7,9 @@ queueConfig:
   move: 10
   rotate: 2
 
+log:
+  logFolder: /var/log/metaverse
+
 http:
   host: '0.0.0.0'
   port: 6688

+ 3 - 0
config.production1.yaml

@@ -2,6 +2,9 @@ app:
   prefix: /mnt/metaverse/scene
   startPoint: 93
 
+log:
+  logFolder: /var/log/metaverse
+
 queueConfig:
   move: 10
   rotate: 2

+ 3 - 0
config.yaml

@@ -2,6 +2,9 @@ app:
   prefix: /mnt/metaverse/scene
   startPoint: 29
 
+log:
+  logFolder: /var/log/metaverse
+
 queueConfig:
   move: 10
   rotate: 2

+ 9 - 6
src/app.module.ts

@@ -7,17 +7,20 @@ import { RoomModule } from './room/room.module';
 import { SceneModule } from './scene/scene.module';
 // import { CacheModule } from './cache/cache.module';
 import configuration from './config/configuration';
-// import { BullModule } from '@nestjs/bull';
-// console.log('redis配置2', configuration().queueRedis);
+import { LoggerConfig } from './logConfig';
+import {
+  // utilities as nestWinstonModuleUtilities,
+  WinstonModule,
+} from 'nest-winston';
+// import * as winston from 'winston';
+// import { join } from 'path';
+
 @Module({
   imports: [
     ConfigModule.forRoot({ isGlobal: true, load: [configuration] }),
     RoomModule,
     SceneModule,
-    // BullModule.forRoot({
-    //   redis: configuration().queueRedis,
-    // }),
-    // CacheModule,
+    WinstonModule.forRoot(LoggerConfig),
   ],
   controllers: [AppController],
   providers: [AppService, MetaGateway],

+ 40 - 0
src/logConfig.ts

@@ -0,0 +1,40 @@
+import { utilities as nestWinstonModuleUtilities } from 'nest-winston';
+import * as winston from 'winston';
+import { join } from 'path';
+import configuration from 'src/config/configuration';
+
+let logDir: string;
+if (process.env.node_env === 'development') {
+  logDir = join(__dirname, './../log');
+}
+if (process.env.node_env === 'production') {
+  logDir = configuration().get('log.logFolder');
+}
+
+export const LoggerConfig = {
+  format: winston.format.combine(
+    winston.format.timestamp(),
+    winston.format.ms(),
+    nestWinstonModuleUtilities.format.nestLike('Meta-server', {
+      prettyPrint: true,
+    }),
+  ),
+  transports: [
+    new winston.transports.Console(),
+    new winston.transports.File({
+      dirname: logDir, //path to where save loggin result
+      filename: 'debug.log', //name of file where will be saved logging result
+      level: 'debug',
+    }),
+    new winston.transports.File({
+      dirname: logDir,
+      filename: 'info.log',
+      level: 'info',
+    }),
+    new winston.transports.File({
+      dirname: logDir,
+      filename: 'error.log',
+      level: 'error',
+    }),
+  ],
+};

+ 7 - 3
src/main.ts

@@ -4,13 +4,17 @@ import { AppModule } from './app.module';
 import { WsAdapter } from './ws-adapter';
 import { Logger } from '@nestjs/common';
 import { ConfigService } from '@nestjs/config';
-
+import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
+import { WinstonModule } from 'nest-winston';
+import { LoggerConfig } from './logConfig';
 async function bootstrap() {
-  const app = await NestFactory.create(AppModule);
+  const app = await NestFactory.create(AppModule, {
+    logger: WinstonModule.createLogger(LoggerConfig),
+  });
   app.enableCors();
   app.useWebSocketAdapter(new WsAdapter(app));
   const configService = app.get(ConfigService);
-
+  app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
   const http = configService.get('http');
 
   await app.listen(http.port, http.host, function () {

+ 1 - 1
src/rotate/rotate.service.ts

@@ -26,7 +26,7 @@ export class RotateService {
   constructor(
     private cacheService: CacheService, // private sceneService: SceneService,
     private configService: ConfigService,
-  ) { }
+  ) {}
   private actionRequestPool = {};
   private logger: Logger = new Logger('rotateService');
   private Actions = {