refactor(core): Make Logger a service (no-changelog) (#7494)
This commit is contained in:
committed by
GitHub
parent
db4e61ba24
commit
05586a900d
@@ -17,7 +17,6 @@ import type {
|
||||
SelectQueryBuilder,
|
||||
} from 'typeorm';
|
||||
import { parse, stringify } from 'flatted';
|
||||
import { LoggerProxy as Logger } from 'n8n-workflow';
|
||||
import type { IExecutionsSummary, IRunExecutionData } from 'n8n-workflow';
|
||||
import { BinaryDataService } from 'n8n-core';
|
||||
import type {
|
||||
@@ -35,6 +34,7 @@ import { ExecutionEntity } from '../entities/ExecutionEntity';
|
||||
import { ExecutionMetadata } from '../entities/ExecutionMetadata';
|
||||
import { ExecutionDataRepository } from './executionData.repository';
|
||||
import { TIME, inTest } from '@/constants';
|
||||
import { Logger } from '@/Logger';
|
||||
|
||||
function parseFiltersToQueryBuilder(
|
||||
qb: SelectQueryBuilder<ExecutionEntity>,
|
||||
@@ -77,8 +77,6 @@ function parseFiltersToQueryBuilder(
|
||||
|
||||
@Service()
|
||||
export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
private logger = Logger;
|
||||
|
||||
private hardDeletionBatchSize = 100;
|
||||
|
||||
private rates: Record<string, number> = {
|
||||
@@ -96,6 +94,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
|
||||
constructor(
|
||||
dataSource: DataSource,
|
||||
private readonly logger: Logger,
|
||||
private readonly executionDataRepository: ExecutionDataRepository,
|
||||
private readonly binaryDataService: BinaryDataService,
|
||||
) {
|
||||
@@ -360,7 +359,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
Logger.warn(`Failed to get executions count from Postgres: ${error.message}`, {
|
||||
this.logger.warn(`Failed to get executions count from Postgres: ${error.message}`, {
|
||||
error,
|
||||
});
|
||||
}
|
||||
@@ -461,7 +460,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
|
||||
if (!executions.length) {
|
||||
if (deleteConditions.ids) {
|
||||
Logger.error('Failed to delete an execution due to insufficient permissions', {
|
||||
this.logger.error('Failed to delete an execution due to insufficient permissions', {
|
||||
executionIds: deleteConditions.ids,
|
||||
});
|
||||
}
|
||||
@@ -480,7 +479,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
* Mark executions as deleted based on age and count, in a pruning cycle.
|
||||
*/
|
||||
async softDeleteOnPruningCycle() {
|
||||
Logger.debug('Starting soft-deletion of executions (pruning cycle)');
|
||||
this.logger.debug('Starting soft-deletion of executions (pruning cycle)');
|
||||
|
||||
const maxAge = config.getEnv('executions.pruneDataMaxAge'); // in h
|
||||
const maxCount = config.getEnv('executions.pruneDataMaxCount');
|
||||
@@ -527,7 +526,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
.execute();
|
||||
|
||||
if (result.affected === 0) {
|
||||
Logger.debug('Found no executions to soft-delete (pruning cycle)');
|
||||
this.logger.debug('Found no executions to soft-delete (pruning cycle)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,8 @@ import config from '@/config';
|
||||
import { inTest } from '@/constants';
|
||||
import type { BaseMigration, Migration, MigrationContext, MigrationFn } from '@db/types';
|
||||
import { createSchemaBuilder } from '@db/dsl';
|
||||
import { getLogger } from '@/Logger';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
|
||||
const logger = getLogger();
|
||||
import { Logger } from '@/Logger';
|
||||
|
||||
const PERSONALIZATION_SURVEY_FILENAME = 'personalizationSurvey.json';
|
||||
|
||||
@@ -48,6 +46,7 @@ let runningMigrations = false;
|
||||
function logMigrationStart(migrationName: string): void {
|
||||
if (inTest) return;
|
||||
|
||||
const logger = Container.get(Logger);
|
||||
if (!runningMigrations) {
|
||||
logger.warn('Migrations in progress, please do NOT stop the process.');
|
||||
runningMigrations = true;
|
||||
@@ -59,6 +58,7 @@ function logMigrationStart(migrationName: string): void {
|
||||
function logMigrationEnd(migrationName: string): void {
|
||||
if (inTest) return;
|
||||
|
||||
const logger = Container.get(Logger);
|
||||
logger.debug(`Finished migration ${migrationName}`);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ const dbName = config.getEnv(`database.${dbType === 'mariadb' ? 'mysqldb' : dbTy
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
const createContext = (queryRunner: QueryRunner, migration: Migration): MigrationContext => ({
|
||||
logger,
|
||||
logger: Container.get(Logger),
|
||||
tablePrefix,
|
||||
dbType,
|
||||
isMysql,
|
||||
|
||||
Reference in New Issue
Block a user