From 9efada8eabe41b3f1f8f86e1290aa95ac04c708e Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 17 Apr 2019 12:40:34 +0200 Subject: [PATCH] feat(core): Improved logging messages on bootstrap Relates to #86 --- packages/core/src/bootstrap.ts | 25 ++++++++++++++----- packages/core/src/config/config.service.ts | 6 ++--- packages/core/src/config/vendure-config.ts | 2 +- .../src/service/services/search.service.ts | 4 +-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/core/src/bootstrap.ts b/packages/core/src/bootstrap.ts index fc419d9a2f..09bb852cde 100644 --- a/packages/core/src/bootstrap.ts +++ b/packages/core/src/bootstrap.ts @@ -7,7 +7,7 @@ import { InternalServerError } from './common/error/errors'; import { ReadOnlyRequired } from './common/types/common-types'; import { getConfig, setConfig } from './config/config-helpers'; import { DefaultLogger } from './config/logger/default-logger'; -import { Logger, LogLevel } from './config/logger/vendure-logger'; +import { Logger } from './config/logger/vendure-logger'; import { VendureConfig } from './config/vendure-config'; import { registerCustomEntityFields } from './entity/custom-entity-fields'; import { logProxyMiddlewares } from './plugin/plugin-utils'; @@ -35,11 +35,7 @@ export async function bootstrap(userConfig: Partial): Promise): Array (p.defineEntities ? p.defineEntities() : [])) .reduce((all, entities) => [...all, ...entities], []); } + +function logWelcomeMessage(config: VendureConfig) { + let version: string; + try { + version = require('../package.json').version; + } catch (e) { + version = ' unknown'; + } + Logger.info(`=================================================`); + Logger.info(`Vendure server (v${version}) now running on port ${config.port}`); + Logger.info(`Shop API: http://localhost:${config.port}/${config.shopApiPath}`); + Logger.info(`Admin API: http://localhost:${config.port}/${config.adminApiPath}`); + logProxyMiddlewares(config); + Logger.info(`=================================================`); +} diff --git a/packages/core/src/config/config.service.ts b/packages/core/src/config/config.service.ts index 01dc52b4b6..101bd77931 100644 --- a/packages/core/src/config/config.service.ts +++ b/packages/core/src/config/config.service.ts @@ -9,7 +9,7 @@ import { ReadOnlyRequired } from '../common/types/common-types'; import { getConfig } from './config-helpers'; import { EntityIdStrategy } from './entity-id-strategy/entity-id-strategy'; -import { VendureLogger } from './logger/vendure-logger'; +import { Logger, VendureLogger } from './logger/vendure-logger'; import { AssetOptions, AuthOptions, @@ -31,8 +31,8 @@ export class ConfigService implements VendureConfig { this.activeConfig = getConfig(); if (this.activeConfig.authOptions.disableAuth) { // tslint:disable-next-line - console.warn( - 'WARNING: auth has been disabled. This should never be the case for a production system!', + Logger.warn( + 'Auth has been disabled. This should never be the case for a production system!', ); } } diff --git a/packages/core/src/config/vendure-config.ts b/packages/core/src/config/vendure-config.ts index b751663033..90e6553420 100644 --- a/packages/core/src/config/vendure-config.ts +++ b/packages/core/src/config/vendure-config.ts @@ -458,7 +458,7 @@ export interface VendureConfig { * * @default DefaultLogger */ - logger: VendureLogger; + logger?: VendureLogger; /** * @description * Configures how taxes are calculated on products. diff --git a/packages/core/src/service/services/search.service.ts b/packages/core/src/service/services/search.service.ts index f5119e94b3..5c6a7908d1 100644 --- a/packages/core/src/service/services/search.service.ts +++ b/packages/core/src/service/services/search.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { SearchReindexResponse } from '@vendure/common/lib/generated-types'; import { RequestContext } from '../../api/common/request-context'; +import { Logger } from '../../config/logger/vendure-logger'; /** * This service should be overridden by a VendurePlugin which implements search. @@ -18,8 +19,7 @@ import { RequestContext } from '../../api/common/request-context'; export class SearchService { async reindex(ctx: RequestContext): Promise { if (!process.env.CI) { - // tslint:disable-next-line:no-console - console.warn(`The SearchService should be overridden by an appropriate search plugin.`); + Logger.warn(`The SearchService should be overridden by an appropriate search plugin.`); } return { indexedItemCount: 0,