Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Move Logger to core (no-changelog) #12310

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@n8n/task-runner/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void (async function start() {

if (config.sentryConfig.sentryDsn) {
const { ErrorReporter } = await import('n8n-core');
errorReporter = new ErrorReporter();
errorReporter = Container.get(ErrorReporter);
await errorReporter.init('task_runner', config.sentryConfig.sentryDsn);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"bcryptjs": "2.4.3",
"bull": "4.12.1",
"cache-manager": "5.2.3",
"callsites": "3.1.0",
"change-case": "4.1.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
Expand Down Expand Up @@ -149,7 +148,7 @@
"p-cancelable": "2.1.1",
"p-lazy": "3.1.0",
"pg": "8.12.0",
"picocolors": "1.0.1",
"picocolors": "catalog:",
"pkce-challenge": "3.0.0",
"posthog-node": "3.2.1",
"prom-client": "13.2.0",
Expand All @@ -169,7 +168,6 @@
"typedi": "catalog:",
"uuid": "catalog:",
"validator": "13.7.0",
"winston": "3.14.2",
"ws": "8.17.1",
"xml2js": "catalog:",
"xmllint-wasm": "3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/abstract-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { engine as expressHandlebars } from 'express-handlebars';
import { readFile } from 'fs/promises';
import type { Server } from 'http';
import isbot from 'isbot';
import { Logger } from 'n8n-core';
import { Container, Service } from 'typedi';

import config from '@/config';
import { N8N_VERSION, TEMPLATES_DIR, inDevelopment, inTest } from '@/constants';
import * as Db from '@/db';
import { OnShutdown } from '@/decorators/on-shutdown';
import { ExternalHooks } from '@/external-hooks';
import { Logger } from '@/logging/logger.service';
import { rawBodyReader, bodyParser, corsMiddleware } from '@/middlewares';
import { send, sendErrorResponse } from '@/response-helper';
import { LiveWebhooks } from '@/webhooks/live-webhooks';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/active-executions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from 'n8n-core';
import type {
IDeferredPromise,
IExecuteResponsePromiseData,
Expand All @@ -18,7 +19,6 @@ import type {
IExecutionDb,
IExecutionsCurrentSummary,
} from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { isWorkflowIdValid } from '@/utils';

import { ConcurrencyControlService } from './concurrency/concurrency-control.service';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/active-workflow-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ActiveWorkflows,
ErrorReporter,
InstanceSettings,
Logger,
PollContext,
TriggerContext,
} from 'n8n-core';
Expand Down Expand Up @@ -42,7 +43,6 @@ import { OnShutdown } from '@/decorators/on-shutdown';
import { ExecutionService } from '@/executions/execution.service';
import { ExternalHooks } from '@/external-hooks';
import type { IWorkflowDb } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { NodeTypes } from '@/node-types';
import { Publisher } from '@/scaling/pubsub/publisher.service';
import { ActiveWorkflowsService } from '@/services/active-workflows.service';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GlobalConfig } from '@n8n/config';
import { createHash } from 'crypto';
import type { NextFunction, Response } from 'express';
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken';
import { Logger } from 'n8n-core';
import Container, { Service } from 'typedi';

import config from '@/config';
Expand All @@ -12,7 +13,6 @@ import { UserRepository } from '@/databases/repositories/user.repository';
import { AuthError } from '@/errors/response-errors/auth.error';
import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import { License } from '@/license';
import { Logger } from '@/logging/logger.service';
import type { AuthenticatedRequest } from '@/requests';
import { JwtService } from '@/services/jwt.service';
import { UrlService } from '@/services/url.service';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Command, Errors } from '@oclif/core';
import {
BinaryDataService,
InstanceSettings,
Logger,
ObjectStoreService,
DataDeduplicationService,
ErrorReporter,
Expand All @@ -25,7 +26,6 @@ import { ExternalHooks } from '@/external-hooks';
import { ExternalSecretsManager } from '@/external-secrets/external-secrets-manager.ee';
import { License } from '@/license';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { Logger } from '@/logging/logger.service';
import { NodeTypes } from '@/node-types';
import { PostHogClient } from '@/posthog';
import { ShutdownService } from '@/shutdown/shutdown.service';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/db/__tests__/revert.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Migration, MigrationExecutor } from '@n8n/typeorm';
import { type DataSource } from '@n8n/typeorm';
import { mock } from 'jest-mock-extended';
import { Logger } from 'n8n-core';

import { main } from '@/commands/db/revert';
import type { IrreversibleMigration, ReversibleMigration } from '@/databases/types';
import { Logger } from '@/logging/logger.service';
import { mockInstance } from '@test/mocking';

const logger = mockInstance(Logger);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/db/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { DataSourceOptions as ConnectionOptions } from '@n8n/typeorm';
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
import { MigrationExecutor, DataSource as Connection } from '@n8n/typeorm';
import { Command, Flags } from '@oclif/core';
import { Logger } from 'n8n-core';
import { Container } from 'typedi';

import { getConnectionOptions } from '@/databases/config';
import type { Migration } from '@/databases/types';
import { wrapMigration } from '@/databases/utils/migration-helpers';
import { Logger } from '@/logging/logger.service';

// This function is extracted to make it easier to unit test it.
// Mocking turned into a mess due to this command using typeorm and the db
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { WorkerMissingEncryptionKey } from '@/errors/worker-missing-encryption-k
import { EventMessageGeneric } from '@/eventbus/event-message-classes/event-message-generic';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay';
import { Logger } from '@/logging/logger.service';
import { PubSubHandler } from '@/scaling/pubsub/pubsub-handler';
import { Subscriber } from '@/scaling/pubsub/subscriber.service';
import type { ScalingService } from '@/scaling/scaling.service';
Expand Down Expand Up @@ -67,7 +66,7 @@ export class Worker extends BaseCommand {

super(argv, cmdConfig);

this.logger = Container.get(Logger).scoped('scaling');
this.logger = this.logger.scoped('scaling');
}

async init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from 'n8n-core';
import type { WorkflowExecuteMode as ExecutionMode } from 'n8n-workflow';
import { Service } from 'typedi';

Expand All @@ -7,7 +8,6 @@ import { InvalidConcurrencyLimitError } from '@/errors/invalid-concurrency-limit
import { UnknownExecutionModeError } from '@/errors/unknown-execution-mode.error';
import { EventService } from '@/events/event.service';
import type { IExecutingWorkflowData } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { Telemetry } from '@/telemetry';

import { ConcurrencyQueue } from './concurrency-queue';
Expand Down
25 changes: 15 additions & 10 deletions packages/cli/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import convict from 'convict';
import { flatten } from 'flat';
import { readFileSync } from 'fs';
import merge from 'lodash/merge';
import { Logger } from 'n8n-core';
import { ApplicationError, setGlobalState } from 'n8n-workflow';
import assert from 'node:assert';
import colors from 'picocolors';
import { Container } from 'typedi';

Expand Down Expand Up @@ -31,13 +33,15 @@ const config = convict(schema, { args: [] });
// eslint-disable-next-line @typescript-eslint/unbound-method
config.getEnv = config.get;

const logger = Container.get(Logger);
const globalConfig = Container.get(GlobalConfig);

// Load overwrites when not in tests
if (!inE2ETests && !inTest) {
// Overwrite default configuration with settings which got defined in
// optional configuration files
const { N8N_CONFIG_FILES } = process.env;
if (N8N_CONFIG_FILES !== undefined) {
const globalConfig = Container.get(GlobalConfig);
const configFiles = N8N_CONFIG_FILES.split(',');
for (const configFile of configFiles) {
if (!configFile) continue;
Expand All @@ -58,9 +62,10 @@ if (!inE2ETests && !inTest) {
}
}
}
console.debug('Loaded config overwrites from', configFile);
logger.debug(`Loaded config overwrites from ${configFile}`);
} catch (error) {
console.error('Error loading config file', configFile, error);
assert(error instanceof Error);
logger.error(`Error loading config file ${configFile}`, { error });
}
}
}
Expand Down Expand Up @@ -96,7 +101,7 @@ config.validate({
const userManagement = config.get('userManagement');
if (userManagement.jwtRefreshTimeoutHours >= userManagement.jwtSessionDurationHours) {
if (!inTest)
console.warn(
logger.warn(
'N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS needs to smaller than N8N_USER_MANAGEMENT_JWT_DURATION_HOURS. Setting N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS to 0 for now.',
);

Expand All @@ -105,16 +110,16 @@ if (userManagement.jwtRefreshTimeoutHours >= userManagement.jwtSessionDurationHo

const executionProcess = config.getEnv('executions.process');
if (executionProcess) {
console.error(
colors.yellow('Please unset the deprecated env variable'),
colors.bold(colors.yellow('EXECUTIONS_PROCESS')),
logger.error(
colors.yellow('Please unset the deprecated env variable') +
colors.bold(colors.yellow('EXECUTIONS_PROCESS')),
);
}
if (executionProcess === 'own') {
console.error(
logger.error(
colors.bold(colors.red('Application failed to start because "Own" mode has been removed.')),
);
console.error(
logger.error(
colors.red(
'If you need the isolation and performance gains, please consider using queue mode instead.\n\n',
),
Expand All @@ -123,7 +128,7 @@ if (executionProcess === 'own') {
}

setGlobalState({
defaultTimezone: Container.get(GlobalConfig).generic.timezone,
defaultTimezone: globalConfig.generic.timezone,
});

// eslint-disable-next-line import/no-default-export
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Response } from 'express';
import { Logger } from 'n8n-core';
import { ApplicationError } from 'n8n-workflow';
import validator from 'validator';

Expand All @@ -14,7 +15,6 @@ import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import { EventService } from '@/events/event.service';
import type { PublicUser } from '@/interfaces';
import { License } from '@/license';
import { Logger } from '@/logging/logger.service';
import { MfaService } from '@/mfa/mfa.service';
import { PostHogClient } from '@/posthog';
import { AuthenticatedRequest, LoginRequest, UserRequest } from '@/requests';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/e2e.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PushPayload, PushType } from '@n8n/api-types';
import { Request } from 'express';
import { Logger } from 'n8n-core';
import Container from 'typedi';
import { v4 as uuid } from 'uuid';

Expand All @@ -14,7 +15,6 @@ import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus'
import type { BooleanLicenseFeature, NumericLicenseFeature } from '@/interfaces';
import type { FeatureReturnType } from '@/license';
import { License } from '@/license';
import { Logger } from '@/logging/logger.service';
import { MfaService } from '@/mfa/mfa.service';
import { Push } from '@/push';
import type { UserSetupPayload } from '@/requests';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/invitation.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Response } from 'express';
import { Logger } from 'n8n-core';
import validator from 'validator';

import { AuthService } from '@/auth/auth.service';
Expand All @@ -12,7 +13,6 @@ import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import { EventService } from '@/events/event.service';
import { ExternalHooks } from '@/external-hooks';
import { License } from '@/license';
import { Logger } from '@/logging/logger.service';
import { PostHogClient } from '@/posthog';
import { UserRequest } from '@/requests';
import { PasswordUtility } from '@/services/password.utility';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/me.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@n8n/api-types';
import { plainToInstance } from 'class-transformer';
import { Response } from 'express';
import { Logger } from 'n8n-core';

import { AuthService } from '@/auth/auth.service';
import type { User } from '@/databases/entities/user';
Expand All @@ -16,7 +17,6 @@ import { EventService } from '@/events/event.service';
import { ExternalHooks } from '@/external-hooks';
import { validateEntity } from '@/generic-helpers';
import type { PublicUser } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { MfaService } from '@/mfa/mfa.service';
import { AuthenticatedRequest, MeRequest } from '@/requests';
import { PasswordUtility } from '@/services/password.utility';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Csrf from 'csrf';
import type { Response } from 'express';
import { mock } from 'jest-mock-extended';
import { Cipher } from 'n8n-core';
import { Logger } from 'n8n-core';
import nock from 'nock';
import Container from 'typedi';

Expand All @@ -16,7 +17,6 @@ import { VariablesService } from '@/environments/variables/variables.service.ee'
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { ExternalHooks } from '@/external-hooks';
import { Logger } from '@/logging/logger.service';
import type { OAuthRequest } from '@/requests';
import { SecretsHelper } from '@/secrets-helpers';
import { mockInstance } from '@test/mocking';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Csrf from 'csrf';
import { type Response } from 'express';
import { mock } from 'jest-mock-extended';
import { Cipher } from 'n8n-core';
import { Logger } from 'n8n-core';
import nock from 'nock';
import Container from 'typedi';

Expand All @@ -16,7 +17,6 @@ import { VariablesService } from '@/environments/variables/variables.service.ee'
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { ExternalHooks } from '@/external-hooks';
import { Logger } from '@/logging/logger.service';
import type { OAuthRequest } from '@/requests';
import { SecretsHelper } from '@/secrets-helpers';
import { mockInstance } from '@test/mocking';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GlobalConfig } from '@n8n/config';
import Csrf from 'csrf';
import type { Response } from 'express';
import { Credentials } from 'n8n-core';
import { Credentials, Logger } from 'n8n-core';
import type { ICredentialDataDecryptedObject, IWorkflowExecuteAdditionalData } from 'n8n-workflow';
import { jsonParse, ApplicationError } from 'n8n-workflow';
import { Service } from 'typedi';
Expand All @@ -16,7 +16,6 @@ import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { ExternalHooks } from '@/external-hooks';
import type { ICredentialsDb } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import type { AuthenticatedRequest, OAuthRequest } from '@/requests';
import { UrlService } from '@/services/url.service';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/owner.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Response } from 'express';
import { Logger } from 'n8n-core';
import validator from 'validator';

import { AuthService } from '@/auth/auth.service';
Expand All @@ -9,7 +10,6 @@ import { GlobalScope, Post, RestController } from '@/decorators';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { EventService } from '@/events/event.service';
import { validateEntity } from '@/generic-helpers';
import { Logger } from '@/logging/logger.service';
import { PostHogClient } from '@/posthog';
import { OwnerRequest } from '@/requests';
import { PasswordUtility } from '@/services/password.utility';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/password-reset.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Response } from 'express';
import { Logger } from 'n8n-core';
import validator from 'validator';

import { AuthService } from '@/auth/auth.service';
Expand All @@ -13,7 +14,6 @@ import { UnprocessableRequestError } from '@/errors/response-errors/unprocessabl
import { EventService } from '@/events/event.service';
import { ExternalHooks } from '@/external-hooks';
import { License } from '@/license';
import { Logger } from '@/logging/logger.service';
import { MfaService } from '@/mfa/mfa.service';
import { PasswordResetRequest } from '@/requests';
import { PasswordUtility } from '@/services/password.utility';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/controllers/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RoleChangeRequestDto, SettingsUpdateRequestDto } from '@n8n/api-types';
import { Response } from 'express';
import { Logger } from 'n8n-core';

import { AuthService } from '@/auth/auth.service';
import { CredentialsService } from '@/credentials/credentials.service';
Expand All @@ -18,7 +19,6 @@ import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { EventService } from '@/events/event.service';
import { ExternalHooks } from '@/external-hooks';
import type { PublicUser } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { listQueryMiddleware } from '@/middlewares';
import { AuthenticatedRequest, ListQuery, UserRequest } from '@/requests';
import { ProjectService } from '@/services/project.service';
Expand Down
Loading
Loading