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

@@ -1,6 +1,5 @@
import express from 'express';
import { v4 as uuid } from 'uuid';
import { LoggerProxy } from 'n8n-workflow';
import axios from 'axios';
import * as Db from '@/Db';
@@ -13,7 +12,6 @@ import { SharedWorkflow } from '@db/entities/SharedWorkflow';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { validateEntity } from '@/GenericHelpers';
import { ExternalHooks } from '@/ExternalHooks';
import { getLogger } from '@/Logger';
import type { ListQuery, WorkflowRequest } from '@/requests';
import { isBelowOnboardingThreshold } from '@/WorkflowHelpers';
import { EEWorkflowController } from './workflows.controller.ee';
@@ -27,21 +25,9 @@ import * as utils from '@/utils';
import { listQueryMiddleware } from '@/middlewares';
import { TagService } from '@/services/tag.service';
import { WorkflowHistoryService } from './workflowHistory/workflowHistory.service.ee';
import { Logger } from '@/Logger';
export const workflowsController = express.Router();
/**
* Initialize Logger if needed
*/
workflowsController.use((req, res, next) => {
try {
LoggerProxy.getInstance();
} catch (error) {
LoggerProxy.init(getLogger());
}
next();
});
workflowsController.use('/', EEWorkflowController);
/**
@@ -96,7 +82,7 @@ workflowsController.post(
});
if (!savedWorkflow) {
LoggerProxy.error('Failed to create workflow', { userId: req.user.id });
Container.get(Logger).error('Failed to create workflow', { userId: req.user.id });
throw new ResponseHelper.InternalServerError('Failed to save workflow');
}
@@ -230,7 +216,7 @@ workflowsController.get(
});
if (!shared) {
LoggerProxy.verbose('User attempted to access a workflow without permissions', {
Container.get(Logger).verbose('User attempted to access a workflow without permissions', {
workflowId,
userId: req.user.id,
});
@@ -280,7 +266,7 @@ workflowsController.delete(
const workflow = await WorkflowsService.delete(req.user, workflowId);
if (!workflow) {
LoggerProxy.verbose('User attempted to delete a workflow without permissions', {
Container.get(Logger).verbose('User attempted to delete a workflow without permissions', {
workflowId,
userId: req.user.id,
});