refactor(core): Make Logger a service (no-changelog) (#7494)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-10-25 16:35:22 +02:00
committed by GitHub
parent db4e61ba24
commit 05586a900d
131 changed files with 761 additions and 919 deletions

View File

@@ -2,10 +2,10 @@ import 'reflect-metadata';
import { Command } from '@oclif/command';
import { ExitError } from '@oclif/errors';
import { Container } from 'typedi';
import { LoggerProxy, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
import { ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
import { BinaryDataService, InstanceSettings, ObjectStoreService } from 'n8n-core';
import type { AbstractServer } from '@/AbstractServer';
import { getLogger } from '@/Logger';
import { Logger } from '@/Logger';
import config from '@/config';
import * as Db from '@/Db';
import * as CrashJournal from '@/CrashJournal';
@@ -24,7 +24,7 @@ import { generateHostInstanceId } from '../databases/utils/generators';
import { WorkflowHistoryManager } from '@/workflows/workflowHistory/workflowHistoryManager.ee';
export abstract class BaseCommand extends Command {
protected logger = LoggerProxy.init(getLogger());
protected logger = Container.get(Logger);
protected externalHooks: IExternalHooksClass;
@@ -64,12 +64,12 @@ export abstract class BaseCommand extends Command {
const dbType = config.getEnv('database.type');
if (['mysqldb', 'mariadb'].includes(dbType)) {
LoggerProxy.warn(
this.logger.warn(
'Support for MySQL/MariaDB has been deprecated and will be removed with an upcoming version of n8n. Please migrate to PostgreSQL.',
);
}
if (process.env.EXECUTIONS_PROCESS === 'own') {
LoggerProxy.warn(
this.logger.warn(
'Own mode has been deprecated and will be removed in a future version of n8n. If you need the isolation and performance gains, please consider using queue mode.',
);
}
@@ -129,7 +129,7 @@ export abstract class BaseCommand extends Command {
const isLicensed = Container.get(License).isFeatureEnabled(LICENSE_FEATURES.BINARY_DATA_S3);
if (isSelected && isAvailable && isLicensed) {
LoggerProxy.debug(
this.logger.debug(
'License found for external storage - object store to init in read-write mode',
);
@@ -139,7 +139,7 @@ export abstract class BaseCommand extends Command {
}
if (isSelected && isAvailable && !isLicensed) {
LoggerProxy.debug(
this.logger.debug(
'No license found for external storage - object store to init with writes blocked. To enable writes, please upgrade to a license that supports this feature.',
);
@@ -149,7 +149,7 @@ export abstract class BaseCommand extends Command {
}
if (!isSelected && isAvailable) {
LoggerProxy.debug(
this.logger.debug(
'External storage unselected but available - object store to init with writes unused',
);
@@ -204,17 +204,17 @@ export abstract class BaseCommand extends Command {
);
}
LoggerProxy.debug('Initializing object store service');
this.logger.debug('Initializing object store service');
try {
await objectStoreService.init(host, bucket, credentials);
objectStoreService.setReadonly(options.isReadOnly);
LoggerProxy.debug('Object store init completed');
this.logger.debug('Object store init completed');
} catch (e) {
const error = e instanceof Error ? e : new Error(`${e}`);
LoggerProxy.debug('Object store init failed', { error });
this.logger.debug('Object store init failed', { error });
}
}
@@ -223,7 +223,7 @@ export abstract class BaseCommand extends Command {
await this.initObjectStoreService();
} catch (e) {
const error = e instanceof Error ? e : new Error(`${e}`);
LoggerProxy.error(`Failed to init object store: ${error.message}`, { error });
this.logger.error(`Failed to init object store: ${error.message}`, { error });
process.exit(1);
}
@@ -246,14 +246,14 @@ export abstract class BaseCommand extends Command {
const hasCert = (await license.loadCertStr()).length > 0;
if (hasCert) {
return LoggerProxy.debug('Skipping license activation');
return this.logger.debug('Skipping license activation');
}
try {
LoggerProxy.debug('Attempting license activation');
this.logger.debug('Attempting license activation');
await license.activate(activationKey);
} catch (e) {
LoggerProxy.error('Could not activate license', e as Error);
this.logger.error('Could not activate license', e as Error);
}
}
}