Przeglądaj źródła

refactor(server): server version logging (#1073)

* refactor(server): server version logging

* chore: server => microservices
Jason Rasmussen 2 lat temu
rodzic
commit
58a149990d

+ 2 - 0
server/apps/immich/src/constants/server_version.constant.ts

@@ -14,3 +14,5 @@ export const serverVersion: IServerVersion = {
   patch: 0,
   patch: 0,
   build: 58,
   build: 58,
 };
 };
+
+export const SERVER_VERSION = `${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`;

+ 6 - 12
server/apps/immich/src/main.ts

@@ -6,11 +6,13 @@ import cookieParser from 'cookie-parser';
 import { writeFileSync } from 'fs';
 import { writeFileSync } from 'fs';
 import path from 'path';
 import path from 'path';
 import { AppModule } from './app.module';
 import { AppModule } from './app.module';
-import { serverVersion } from './constants/server_version.constant';
+import { SERVER_VERSION } from './constants/server_version.constant';
 import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
 import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
 import { json } from 'body-parser';
 import { json } from 'body-parser';
 import { patchOpenAPI } from './utils/patch-open-api.util';
 import { patchOpenAPI } from './utils/patch-open-api.util';
 
 
+const logger = new Logger('ImmichServer');
+
 async function bootstrap() {
 async function bootstrap() {
   const app = await NestFactory.create<NestExpressApplication>(AppModule);
   const app = await NestFactory.create<NestExpressApplication>(AppModule);
 
 
@@ -27,7 +29,7 @@ async function bootstrap() {
   const config = new DocumentBuilder()
   const config = new DocumentBuilder()
     .setTitle('Immich')
     .setTitle('Immich')
     .setDescription('Immich API')
     .setDescription('Immich API')
-    .setVersion(`${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`)
+    .setVersion(SERVER_VERSION)
     .addBearerAuth({
     .addBearerAuth({
       type: 'http',
       type: 'http',
       scheme: 'Bearer',
       scheme: 'Bearer',
@@ -57,18 +59,10 @@ async function bootstrap() {
       // Generate API Documentation only in development mode
       // Generate API Documentation only in development mode
       const outputPath = path.resolve(process.cwd(), 'immich-openapi-specs.json');
       const outputPath = path.resolve(process.cwd(), 'immich-openapi-specs.json');
       writeFileSync(outputPath, JSON.stringify(patchOpenAPI(apiDocument), null, 2), { encoding: 'utf8' });
       writeFileSync(outputPath, JSON.stringify(patchOpenAPI(apiDocument), null, 2), { encoding: 'utf8' });
-      Logger.log(
-        `Running Immich Server in DEVELOPMENT environment - version ${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`,
-        'ImmichServer',
-      );
     }
     }
 
 
-    if (process.env.NODE_ENV == 'production') {
-      Logger.log(
-        `Running Immich Server in PRODUCTION environment - version ${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`,
-        'ImmichServer',
-      );
-    }
+    const envName = (process.env.NODE_ENV || 'development').toUpperCase();
+    logger.log(`Running Immich Server in ${envName} environment - version ${SERVER_VERSION}`);
   });
   });
 }
 }
 bootstrap();
 bootstrap();

+ 5 - 14
server/apps/microservices/src/main.ts

@@ -1,28 +1,19 @@
 import { Logger } from '@nestjs/common';
 import { Logger } from '@nestjs/common';
 import { NestFactory } from '@nestjs/core';
 import { NestFactory } from '@nestjs/core';
-import { serverVersion } from 'apps/immich/src/constants/server_version.constant';
+import { SERVER_VERSION } from 'apps/immich/src/constants/server_version.constant';
 import { RedisIoAdapter } from '../../immich/src/middlewares/redis-io.adapter.middleware';
 import { RedisIoAdapter } from '../../immich/src/middlewares/redis-io.adapter.middleware';
 import { MicroservicesModule } from './microservices.module';
 import { MicroservicesModule } from './microservices.module';
 
 
+const logger = new Logger('ImmichMicroservice');
+
 async function bootstrap() {
 async function bootstrap() {
   const app = await NestFactory.create(MicroservicesModule);
   const app = await NestFactory.create(MicroservicesModule);
 
 
   app.useWebSocketAdapter(new RedisIoAdapter(app));
   app.useWebSocketAdapter(new RedisIoAdapter(app));
 
 
   await app.listen(3002, () => {
   await app.listen(3002, () => {
-    if (process.env.NODE_ENV == 'development') {
-      Logger.log(
-        `Running Immich Microservices in DEVELOPMENT environment - version ${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`,
-        'ImmichMicroservice',
-      );
-    }
-
-    if (process.env.NODE_ENV == 'production') {
-      Logger.log(
-        `Running Immich Microservices in PRODUCTION environment - version ${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`,
-        'ImmichMicroservice',
-      );
-    }
+    const envName = (process.env.NODE_ENV || 'development').toUpperCase();
+    logger.log(`Running Immich Microservices in ${envName} environment - version ${SERVER_VERSION}`);
   });
   });
 }
 }
 bootstrap();
 bootstrap();