refactor(core): Make Logger a service (no-changelog) (#7494)
This commit is contained in:
committed by
GitHub
parent
db4e61ba24
commit
05586a900d
@@ -1,14 +1,15 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Container } from 'typedi';
|
||||
import type { DeleteResult, InsertResult } from 'typeorm';
|
||||
import type { INodeCredentials } from 'n8n-workflow';
|
||||
import {
|
||||
LoggerProxy,
|
||||
MessageEventBusDestinationTypeNames,
|
||||
MessageEventBusDestinationOptions,
|
||||
} from 'n8n-workflow';
|
||||
import * as Db from '@/Db';
|
||||
import { Logger } from '@/Logger';
|
||||
import type { AbstractEventMessage } from '../EventMessageClasses/AbstractEventMessage';
|
||||
import type { EventMessageTypes } from '../EventMessageClasses';
|
||||
import type { DeleteResult, InsertResult } from 'typeorm';
|
||||
import type { EventMessageConfirmSource } from '../EventMessageClasses/EventMessageConfirm';
|
||||
import { MessageEventBus } from '../MessageEventBus/MessageEventBus';
|
||||
import type { MessageWithCallback } from '../MessageEventBus/MessageEventBus';
|
||||
@@ -20,6 +21,8 @@ export abstract class MessageEventBusDestination implements MessageEventBusDesti
|
||||
|
||||
readonly eventBusInstance: MessageEventBus;
|
||||
|
||||
protected readonly logger: Logger;
|
||||
|
||||
__type: MessageEventBusDestinationTypeNames;
|
||||
|
||||
label: string;
|
||||
@@ -33,6 +36,7 @@ export abstract class MessageEventBusDestination implements MessageEventBusDesti
|
||||
anonymizeAuditMessages: boolean;
|
||||
|
||||
constructor(eventBusInstance: MessageEventBus, options: MessageEventBusDestinationOptions) {
|
||||
this.logger = Container.get(Logger);
|
||||
this.eventBusInstance = eventBusInstance;
|
||||
this.id = !options.id || options.id.length !== 36 ? uuid() : options.id;
|
||||
this.__type = options.__type ?? MessageEventBusDestinationTypeNames.abstract;
|
||||
@@ -41,7 +45,7 @@ export abstract class MessageEventBusDestination implements MessageEventBusDesti
|
||||
this.subscribedEvents = options.subscribedEvents ?? [];
|
||||
this.anonymizeAuditMessages = options.anonymizeAuditMessages ?? false;
|
||||
if (options.credentials) this.credentials = options.credentials;
|
||||
LoggerProxy.debug(`${this.__type}(${this.id}) event destination constructed`);
|
||||
this.logger.debug(`${this.__type}(${this.id}) event destination constructed`);
|
||||
}
|
||||
|
||||
startListening() {
|
||||
@@ -55,7 +59,7 @@ export abstract class MessageEventBusDestination implements MessageEventBusDesti
|
||||
await this.receiveFromEventBus({ msg, confirmCallback });
|
||||
},
|
||||
);
|
||||
LoggerProxy.debug(`${this.id} listener started`);
|
||||
this.logger.debug(`${this.id} listener started`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { MessageEventBusDestinationTypeNames, LoggerProxy } from 'n8n-workflow';
|
||||
import { MessageEventBusDestinationTypeNames } from 'n8n-workflow';
|
||||
import type { EventDestinations } from '@/databases/entities/EventDestinations';
|
||||
import type { MessageEventBus } from '../MessageEventBus/MessageEventBus';
|
||||
import type { MessageEventBusDestination } from './MessageEventBusDestination.ee';
|
||||
import { MessageEventBusDestinationSentry } from './MessageEventBusDestinationSentry.ee';
|
||||
import { MessageEventBusDestinationSyslog } from './MessageEventBusDestinationSyslog.ee';
|
||||
import { MessageEventBusDestinationWebhook } from './MessageEventBusDestinationWebhook.ee';
|
||||
import { Container } from 'typedi';
|
||||
import { Logger } from '@/Logger';
|
||||
|
||||
export function messageEventBusDestinationFromDb(
|
||||
eventBusInstance: MessageEventBus,
|
||||
@@ -20,7 +22,7 @@ export function messageEventBusDestinationFromDb(
|
||||
case MessageEventBusDestinationTypeNames.webhook:
|
||||
return MessageEventBusDestinationWebhook.deserialize(eventBusInstance, destinationData);
|
||||
default:
|
||||
LoggerProxy.debug('MessageEventBusDestination __type unknown');
|
||||
Container.get(Logger).debug('MessageEventBusDestination __type unknown');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { MessageEventBusDestination } from './MessageEventBusDestination.ee';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import {
|
||||
LoggerProxy,
|
||||
MessageEventBusDestinationTypeNames,
|
||||
MessageEventBusDestinationSentryOptions,
|
||||
} from 'n8n-workflow';
|
||||
@@ -90,7 +89,7 @@ export class MessageEventBusDestinationSentry
|
||||
sendResult = true;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.message) LoggerProxy.debug(error.message as string);
|
||||
if (error.message) this.logger.debug(error.message as string);
|
||||
}
|
||||
return sendResult;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import syslog from 'syslog-client';
|
||||
|
||||
import type { MessageEventBusDestinationOptions } from 'n8n-workflow';
|
||||
import {
|
||||
LoggerProxy,
|
||||
MessageEventBusDestinationTypeNames,
|
||||
MessageEventBusDestinationSyslogOptions,
|
||||
} from 'n8n-workflow';
|
||||
@@ -11,7 +11,6 @@ import { isLogStreamingEnabled } from '../MessageEventBus/MessageEventBusHelper'
|
||||
import { eventMessageGenericDestinationTestEvent } from '../EventMessageClasses/EventMessageGeneric';
|
||||
import { MessageEventBus } from '../MessageEventBus/MessageEventBus';
|
||||
import type { MessageWithCallback } from '../MessageEventBus/MessageEventBus';
|
||||
|
||||
export const isMessageEventBusDestinationSyslogOptions = (
|
||||
candidate: unknown,
|
||||
): candidate is MessageEventBusDestinationSyslogOptions => {
|
||||
@@ -63,7 +62,7 @@ export class MessageEventBusDestinationSyslog
|
||||
? syslog.Transport.Tcp
|
||||
: syslog.Transport.Udp,
|
||||
});
|
||||
LoggerProxy.debug(`MessageEventBusDestinationSyslog with id ${this.getId()} initialized`);
|
||||
this.logger.debug(`MessageEventBusDestinationSyslog with id ${this.getId()} initialized`);
|
||||
this.client.on('error', function (error) {
|
||||
console.error(error);
|
||||
});
|
||||
@@ -93,7 +92,7 @@ export class MessageEventBusDestinationSyslog
|
||||
},
|
||||
async (error) => {
|
||||
if (error?.message) {
|
||||
LoggerProxy.debug(error.message);
|
||||
this.logger.debug(error.message);
|
||||
} else {
|
||||
// eventBus.confirmSent(msg, { id: this.id, name: this.label });
|
||||
confirmCallback(msg, { id: this.id, name: this.label });
|
||||
@@ -102,7 +101,7 @@ export class MessageEventBusDestinationSyslog
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
if (error.message) LoggerProxy.debug(error.message as string);
|
||||
if (error.message) this.logger.debug(error.message as string);
|
||||
}
|
||||
if (msg.eventName === eventMessageGenericDestinationTestEvent) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
@@ -7,7 +7,6 @@ import axios from 'axios';
|
||||
import type { AxiosRequestConfig, Method } from 'axios';
|
||||
import {
|
||||
jsonParse,
|
||||
LoggerProxy,
|
||||
MessageEventBusDestinationTypeNames,
|
||||
MessageEventBusDestinationWebhookOptions,
|
||||
} from 'n8n-workflow';
|
||||
@@ -102,7 +101,7 @@ export class MessageEventBusDestinationWebhook
|
||||
if (options.sendPayload) this.sendPayload = options.sendPayload;
|
||||
if (options.options) this.options = options.options;
|
||||
|
||||
LoggerProxy.debug(`MessageEventBusDestinationWebhook with id ${this.getId()} initialized`);
|
||||
this.logger.debug(`MessageEventBusDestinationWebhook with id ${this.getId()} initialized`);
|
||||
}
|
||||
|
||||
async matchDecryptedCredentialType(credentialType: string) {
|
||||
@@ -359,7 +358,7 @@ export class MessageEventBusDestinationWebhook
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
LoggerProxy.warn(
|
||||
this.logger.warn(
|
||||
`Webhook destination ${this.label} failed to send message to: ${this.url} - ${
|
||||
(error as Error).message
|
||||
}`,
|
||||
|
||||
Reference in New Issue
Block a user