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

@@ -4,7 +4,6 @@ import type { Server } from 'http';
import express from 'express';
import compression from 'compression';
import isbot from 'isbot';
import { LoggerProxy as Logger } from 'n8n-workflow';
import config from '@/config';
import { N8N_VERSION, inDevelopment, inTest } from '@/constants';
@@ -19,8 +18,11 @@ import { TestWebhooks } from '@/TestWebhooks';
import { WaitingWebhooks } from '@/WaitingWebhooks';
import { webhookRequestHandler } from '@/WebhookHelpers';
import { generateHostInstanceId } from './databases/utils/generators';
import { Logger } from '@/Logger';
export abstract class AbstractServer {
protected logger: Logger;
protected server: Server;
readonly app: express.Application;
@@ -67,6 +69,8 @@ export abstract class AbstractServer {
this.endpointWebhookWaiting = config.getEnv('endpoints.webhookWaiting');
this.uniqueInstanceId = generateHostInstanceId(instanceType);
this.logger = Container.get(Logger);
}
async configure(): Promise<void> {
@@ -194,7 +198,7 @@ export abstract class AbstractServer {
this.app.use((req, res, next) => {
const userAgent = req.headers['user-agent'];
if (userAgent && checkIfBot(userAgent)) {
Logger.info(`Blocked ${req.method} ${req.url} for "${userAgent}"`);
this.logger.info(`Blocked ${req.method} ${req.url} for "${userAgent}"`);
res.status(204).end();
} else next();
});