0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-03-11 02:15:57 -05:00

chore: improve startup logging (#4788)

This commit is contained in:
Marc Bernard 2024-08-20 15:17:33 -04:00 committed by GitHub
parent e8de53bcdf
commit 7c9f3cf15e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 69 additions and 13 deletions

View file

@ -0,0 +1,13 @@
---
'@verdaccio/local-storage': patch
'@verdaccio/server': patch
'@verdaccio/core': patch
'@verdaccio/node-api': patch
'@verdaccio/loaders': patch
'@verdaccio/store': patch
'@verdaccio/auth': patch
'@verdaccio/cli': patch
'@verdaccio/web': patch
---
chore: improve startup logging

View file

@ -5,6 +5,7 @@ import { HTPasswd } from 'verdaccio-htpasswd';
import { createAnonymousRemoteUser, createRemoteUser } from '@verdaccio/config'; import { createAnonymousRemoteUser, createRemoteUser } from '@verdaccio/config';
import { import {
API_ERROR, API_ERROR,
PLUGIN_CATEGORY,
SUPPORT_ERRORS, SUPPORT_ERRORS,
TOKEN_BASIC, TOKEN_BASIC,
TOKEN_BEARER, TOKEN_BEARER,
@ -116,7 +117,8 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
typeof allow_publish !== 'undefined' typeof allow_publish !== 'undefined'
); );
}, },
this.config?.serverSettings?.pluginPrefix this.config?.serverSettings?.pluginPrefix,
PLUGIN_CATEGORY.AUTHENTICATION
); );
} }

View file

@ -59,7 +59,6 @@ export class InitCommand extends Command {
const configParsed = parseConfigFile(configPathLocation); const configParsed = parseConfigFile(configPathLocation);
this.initLogger(configParsed); this.initLogger(configParsed);
logger.info({ file: configPathLocation }, 'using config file: @{file}'); logger.info({ file: configPathLocation }, 'using config file: @{file}');
logger.info('log level: %s', configParsed.log?.level || 'default');
const { web } = configParsed; const { web } = configParsed;
process.title = web?.title || DEFAULT_PROCESS_NAME; process.title = web?.title || DEFAULT_PROCESS_NAME;
@ -67,6 +66,9 @@ export class InitCommand extends Command {
const { version, name } = require('../../package.json'); const { version, name } = require('../../package.json');
await initServer(configParsed, this.port as string, version, name); await initServer(configParsed, this.port as string, version, name);
const logLevel = configParsed.log?.level || 'default';
logger.info({ logLevel }, 'log level: @{logLevel}');
logger.info('server started'); logger.info('server started');
} catch (err: any) { } catch (err: any) {
console.error(err); console.error(err);

View file

@ -119,3 +119,11 @@ export enum HtpasswdHashAlgorithm {
crypt = 'crypt', crypt = 'crypt',
bcrypt = 'bcrypt', bcrypt = 'bcrypt',
} }
export const PLUGIN_CATEGORY = {
AUTHENTICATION: 'authentication',
MIDDLEWARE: 'middleware',
STORAGE: 'storage',
FILTER: 'filter',
THEME: 'theme',
};

View file

@ -24,6 +24,7 @@ export {
DEFAULT_USER, DEFAULT_USER,
USERS, USERS,
MAINTAINERS, MAINTAINERS,
PLUGIN_CATEGORY,
HtpasswdHashAlgorithm, HtpasswdHashAlgorithm,
} from './constants'; } from './constants';
const validationUtils = validatioUtils; const validationUtils = validatioUtils;

View file

@ -50,7 +50,8 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
pluginConfigs: any = {}, pluginConfigs: any = {},
params: Params, params: Params,
sanityCheck: (plugin: PluginType<T>) => boolean, sanityCheck: (plugin: PluginType<T>) => boolean,
prefix: string = 'verdaccio' prefix: string = 'verdaccio',
pluginCategory: string = ''
): Promise<PluginType<T>[]> { ): Promise<PluginType<T>[]> {
const pluginsIds = Object.keys(pluginConfigs); const pluginsIds = Object.keys(pluginConfigs);
const { config } = params; const { config } = params;
@ -75,7 +76,7 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
} }
logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} '); logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');
// throws if is nto a directory // throws if is not a directory
try { try {
await isDirectory(pluginsPath); await isDirectory(pluginsPath);
const pluginDir = pluginsPath; const pluginDir = pluginsPath;
@ -93,6 +94,10 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
continue; continue;
} }
plugins.push(plugin); plugins.push(plugin);
logger.info(
{ prefix, pluginId, pluginCategory },
'plugin @{prefix}-@{pluginId} successfully loaded (@{pluginCategory})'
);
continue; continue;
} }
} catch (err: any) { } catch (err: any) {
@ -118,6 +123,10 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
continue; continue;
} }
plugins.push(plugin); plugins.push(plugin);
logger.info(
{ prefix, pluginId, pluginCategory },
'plugin @{prefix}-@{pluginId} successfully loaded (@{pluginCategory})'
);
continue; continue;
} else { } else {
logger.error( logger.error(

View file

@ -78,6 +78,20 @@ export function createServerFactory(config: ConfigYaml, addr, app) {
serverFactory = http.createServer(app); serverFactory = http.createServer(app);
} }
// List of all routes registered in the app
function printRoutes(layer) {
if (layer.route) {
debug('%s (%s)', layer.route.path, Object.keys(layer.route.methods).join(', '));
} else if (layer.name === 'router') {
layer.handle.stack.forEach((nestedLayer) => {
printRoutes(nestedLayer);
});
}
}
debug('registered routes:');
app._router.stack.forEach(printRoutes);
if ( if (
config.server && config.server &&
typeof config.server.keepAliveTimeout !== 'undefined' && typeof config.server.keepAliveTimeout !== 'undefined' &&
@ -146,8 +160,8 @@ export async function initServer(
pathname: '/', pathname: '/',
}) })
}`; }`;
logger.info(`http address ${addressServer}`); logger.info({ addressServer }, 'http address: @{addressServer}');
logger.info(`version: ${version}`); logger.info({ version }, 'version: @{version}');
resolve(); resolve();
}) })
.on('error', function (err): void { .on('error', function (err): void {

View file

@ -46,7 +46,7 @@ class LocalDatabase extends pluginUtils.Plugin<{}> implements Storage {
debug('config path %o', config.configPath); debug('config path %o', config.configPath);
this.path = _dbGenPath(DB_NAME, config); this.path = _dbGenPath(DB_NAME, config);
this.storages = this._getCustomPackageLocalStorages(); this.storages = this._getCustomPackageLocalStorages();
this.logger.info({ path: this.path }, 'local storage path @{path}'); this.logger.info({ path: this.path }, 'local storage path: @{path}');
debug('plugin storage path %o', this.path); debug('plugin storage path %o', this.path);
} }

View file

@ -8,7 +8,7 @@ import AuditMiddleware from 'verdaccio-audit';
import apiEndpoint from '@verdaccio/api'; import apiEndpoint from '@verdaccio/api';
import { Auth } from '@verdaccio/auth'; import { Auth } from '@verdaccio/auth';
import { Config as AppConfig } from '@verdaccio/config'; import { Config as AppConfig } from '@verdaccio/config';
import { API_ERROR, errorUtils, pluginUtils } from '@verdaccio/core'; import { API_ERROR, PLUGIN_CATEGORY, errorUtils, pluginUtils } from '@verdaccio/core';
import { asyncLoadPlugin } from '@verdaccio/loaders'; import { asyncLoadPlugin } from '@verdaccio/loaders';
import { logger } from '@verdaccio/logger'; import { logger } from '@verdaccio/logger';
import { import {
@ -72,7 +72,9 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
}, },
function (plugin) { function (plugin) {
return typeof plugin.register_middlewares !== 'undefined'; return typeof plugin.register_middlewares !== 'undefined';
} },
config?.serverSettings?.pluginPrefix ?? 'verdaccio',
PLUGIN_CATEGORY.MIDDLEWARE
); );
if (plugins.length === 0) { if (plugins.length === 0) {

View file

@ -2,7 +2,7 @@ import assert from 'assert';
import buildDebug from 'debug'; import buildDebug from 'debug';
import _ from 'lodash'; import _ from 'lodash';
import { errorUtils, pluginUtils } from '@verdaccio/core'; import { PLUGIN_CATEGORY, errorUtils, pluginUtils } from '@verdaccio/core';
import { asyncLoadPlugin } from '@verdaccio/loaders'; import { asyncLoadPlugin } from '@verdaccio/loaders';
import LocalDatabase from '@verdaccio/local-storage'; import LocalDatabase from '@verdaccio/local-storage';
import { Config, Logger } from '@verdaccio/types'; import { Config, Logger } from '@verdaccio/types';
@ -75,7 +75,8 @@ class LocalStorage {
(plugin) => { (plugin) => {
return typeof plugin.getPackageStorage !== 'undefined'; return typeof plugin.getPackageStorage !== 'undefined';
}, },
this.config?.serverSettings?.pluginPrefix this.config?.serverSettings?.pluginPrefix,
PLUGIN_CATEGORY.STORAGE
); );
if (plugins.length > 1) { if (plugins.length > 1) {

View file

@ -15,6 +15,7 @@ import {
HEADER_TYPE, HEADER_TYPE,
HTTP_STATUS, HTTP_STATUS,
MAINTAINERS, MAINTAINERS,
PLUGIN_CATEGORY,
SUPPORT_ERRORS, SUPPORT_ERRORS,
USERS, USERS,
errorUtils, errorUtils,
@ -664,7 +665,8 @@ class Storage {
(plugin: pluginUtils.ManifestFilter<Config>) => { (plugin: pluginUtils.ManifestFilter<Config>) => {
return typeof plugin.filter_metadata !== 'undefined'; return typeof plugin.filter_metadata !== 'undefined';
}, },
this.config?.serverSettings?.pluginPrefix this.config?.serverSettings?.pluginPrefix,
PLUGIN_CATEGORY.FILTER
); );
debug('filters available %o', this.filters.length); debug('filters available %o', this.filters.length);
} }

View file

@ -1,6 +1,7 @@
import express from 'express'; import express from 'express';
import _ from 'lodash'; import _ from 'lodash';
import { PLUGIN_CATEGORY } from '@verdaccio/core';
import { asyncLoadPlugin } from '@verdaccio/loaders'; import { asyncLoadPlugin } from '@verdaccio/loaders';
import { logger } from '@verdaccio/logger'; import { logger } from '@verdaccio/logger';
import { webMiddleware } from '@verdaccio/middleware'; import { webMiddleware } from '@verdaccio/middleware';
@ -22,7 +23,8 @@ export async function loadTheme(config: any) {
*/ */
return plugin.staticPath && plugin.manifest && plugin.manifestFiles; return plugin.staticPath && plugin.manifest && plugin.manifestFiles;
}, },
config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme' config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme',
PLUGIN_CATEGORY.THEME
); );
if (plugin.length > 1) { if (plugin.length > 1) {
logger.warn('multiple ui themes are not supported , only the first plugin is used used'); logger.warn('multiple ui themes are not supported , only the first plugin is used used');