Skip to content

Commit

Permalink
initialize logger in command constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Feb 10, 2023
1 parent 0430de0 commit 6063c3c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
6 changes: 1 addition & 5 deletions packages/cli/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { INodeTypes } from 'n8n-workflow';
import { LoggerProxy, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
import type { IUserSettings } from 'n8n-core';
import { BinaryDataManager, UserSettings } from 'n8n-core';
import type { Logger } from '@/Logger';
import { getLogger } from '@/Logger';
import config from '@/config';
import * as Db from '@/Db';
Expand All @@ -23,7 +22,7 @@ export const UM_FIX_INSTRUCTION =
'Please fix the database by running ./packages/cli/bin/n8n user-management:reset';

export abstract class BaseCommand extends Command {
protected logger: Logger;
protected logger = LoggerProxy.init(getLogger());

protected externalHooks: IExternalHooksClass;

Expand All @@ -34,9 +33,6 @@ export abstract class BaseCommand extends Command {
protected userSettings: IUserSettings;

async init(): Promise<void> {
this.logger = getLogger();
LoggerProxy.init(this.logger);

await initErrorHandling();

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/commands/db/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Command, flags } from '@oclif/command';
import type { DataSourceOptions as ConnectionOptions } from 'typeorm';
import { DataSource as Connection } from 'typeorm';
import { LoggerProxy } from 'n8n-workflow';
import type { Logger } from '@/Logger';
import { getLogger } from '@/Logger';
import { getConnectionOptions } from '@/Db';
import config from '@/config';
Expand All @@ -16,14 +15,11 @@ export class DbRevertMigrationCommand extends Command {
help: flags.help({ char: 'h' }),
};

private logger: Logger;
protected logger = LoggerProxy.init(getLogger());

private connection: Connection;

async init() {
this.logger = getLogger();
LoggerProxy.init(this.logger);

this.parse(DbRevertMigrationCommand);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/workflow/src/LoggerProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { ILogger, LogTypes } from './Interfaces';

let logger: ILogger | undefined;

export function init(loggerInstance: ILogger) {
export function init<L extends ILogger>(loggerInstance: L) {
logger = loggerInstance;
return loggerInstance;
}

export function getInstance(): ILogger {
Expand Down

0 comments on commit 6063c3c

Please sign in to comment.