Skip to content

Commit

Permalink
feat(core): Improved logging messages on bootstrap
Browse files Browse the repository at this point in the history
Relates to #86
  • Loading branch information
michaelbromley committed Apr 17, 2019
1 parent 06e5997 commit 9efada8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
25 changes: 19 additions & 6 deletions packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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}`);
}
}
}
Expand Down Expand Up @@ -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(`=================================================`);
}
6 changes: 3 additions & 3 deletions packages/core/src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!',
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/vendure-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export interface VendureConfig {
*
* @default DefaultLogger
*/
logger: VendureLogger;
logger?: VendureLogger;
/**
* @description
* Configures how taxes are calculated on products.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/service/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 9efada8

Please sign in to comment.