Explorar el Código

feat(core): Improved logging messages on bootstrap

Relates to #86
Michael Bromley hace 6 años
padre
commit
9efada8eab

+ 19 - 6
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<VendureConfig>): Promise<INe
     app.useLogger(new Logger());
     await runPluginOnBootstrapMethods(config, app);
     await app.listen(config.port, config.hostname);
-
-    Logger.info(`Vendure server 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);
+    logWelcomeMessage(config);
     return app;
 }
 
@@ -102,6 +98,8 @@ export async function runPluginOnBootstrapMethods(
     for (const plugin of config.plugins) {
         if (plugin.onBootstrap) {
             await plugin.onBootstrap(inject);
+            const pluginName = plugin.constructor && plugin.constructor.name || '(anonymous plugin)';
+            Logger.verbose(`Bootstrapped plugin ${pluginName}`);
         }
     }
 }
@@ -139,3 +137,18 @@ function getEntitiesFromPlugins(userConfig: Partial<VendureConfig>): Array<Type<
         .map(p => (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(`=================================================`);
+}

+ 3 - 3
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!',
             );
         }
     }

+ 1 - 1
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.

+ 2 - 2
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<SearchReindexResponse> {
         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,