From 58a149990d75386c7e1868a31fbcd3db54d818a9 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 8 Dec 2022 10:53:18 -0500 Subject: [PATCH] refactor(server): server version logging (#1073) * refactor(server): server version logging * chore: server => microservices --- .../src/constants/server_version.constant.ts | 2 ++ server/apps/immich/src/main.ts | 18 ++++++------------ server/apps/microservices/src/main.ts | 19 +++++-------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/server/apps/immich/src/constants/server_version.constant.ts b/server/apps/immich/src/constants/server_version.constant.ts index 8b7e5a2d54..c4c69bf121 100644 --- a/server/apps/immich/src/constants/server_version.constant.ts +++ b/server/apps/immich/src/constants/server_version.constant.ts @@ -14,3 +14,5 @@ export const serverVersion: IServerVersion = { patch: 0, build: 58, }; + +export const SERVER_VERSION = `${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`; diff --git a/server/apps/immich/src/main.ts b/server/apps/immich/src/main.ts index 432fc5c768..8805c7e72a 100644 --- a/server/apps/immich/src/main.ts +++ b/server/apps/immich/src/main.ts @@ -6,11 +6,13 @@ import cookieParser from 'cookie-parser'; import { writeFileSync } from 'fs'; import path from 'path'; 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 { json } from 'body-parser'; import { patchOpenAPI } from './utils/patch-open-api.util'; +const logger = new Logger('ImmichServer'); + async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -27,7 +29,7 @@ async function bootstrap() { const config = new DocumentBuilder() .setTitle('Immich') .setDescription('Immich API') - .setVersion(`${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`) + .setVersion(SERVER_VERSION) .addBearerAuth({ type: 'http', scheme: 'Bearer', @@ -57,18 +59,10 @@ async function bootstrap() { // Generate API Documentation only in development mode const outputPath = path.resolve(process.cwd(), 'immich-openapi-specs.json'); 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(); diff --git a/server/apps/microservices/src/main.ts b/server/apps/microservices/src/main.ts index 428943ef1f..72fecd40f2 100644 --- a/server/apps/microservices/src/main.ts +++ b/server/apps/microservices/src/main.ts @@ -1,28 +1,19 @@ import { Logger } from '@nestjs/common'; 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 { MicroservicesModule } from './microservices.module'; +const logger = new Logger('ImmichMicroservice'); + async function bootstrap() { const app = await NestFactory.create(MicroservicesModule); app.useWebSocketAdapter(new RedisIoAdapter(app)); 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();