mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
refactor(core): Make Logger a service (no-changelog) (#7494)
This commit is contained in:
committed by
GitHub
parent
db4e61ba24
commit
05586a900d
@@ -27,7 +27,6 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
ErrorReporterProxy as ErrorReporter,
|
||||
LoggerProxy as Logger,
|
||||
NodeOperationError,
|
||||
Workflow,
|
||||
WorkflowHooks,
|
||||
@@ -64,6 +63,7 @@ import {
|
||||
updateExistingExecution,
|
||||
} from './executionLifecycleHooks/shared/sharedHookFunctions';
|
||||
import { restoreBinaryDataId } from './executionLifecycleHooks/restoreBinaryDataId';
|
||||
import { Logger } from './Logger';
|
||||
|
||||
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
|
||||
|
||||
@@ -118,8 +118,9 @@ export function executeErrorWorkflow(
|
||||
executionId?: string,
|
||||
retryOf?: string,
|
||||
): void {
|
||||
// Check if there was an error and if so if an errorWorkflow or a trigger is set
|
||||
const logger = Container.get(Logger);
|
||||
|
||||
// Check if there was an error and if so if an errorWorkflow or a trigger is set
|
||||
let pastExecutionUrl: string | undefined;
|
||||
if (executionId !== undefined) {
|
||||
pastExecutionUrl = `${WebhookHelpers.getWebhookBaseUrl()}workflow/${
|
||||
@@ -165,7 +166,7 @@ export function executeErrorWorkflow(
|
||||
// To avoid an infinite loop do not run the error workflow again if the error-workflow itself failed and it is its own error-workflow.
|
||||
const { errorWorkflow } = workflowData.settings ?? {};
|
||||
if (errorWorkflow && !(mode === 'error' && workflowId && errorWorkflow === workflowId)) {
|
||||
Logger.verbose('Start external error workflow', {
|
||||
logger.verbose('Start external error workflow', {
|
||||
executionId,
|
||||
errorWorkflowId: errorWorkflow,
|
||||
workflowId,
|
||||
@@ -187,7 +188,7 @@ export function executeErrorWorkflow(
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
ErrorReporter.error(error);
|
||||
Logger.error(
|
||||
logger.error(
|
||||
`Could not execute ErrorWorkflow for execution ID ${this.executionId} because of error querying the workflow owner`,
|
||||
{
|
||||
executionId,
|
||||
@@ -203,7 +204,7 @@ export function executeErrorWorkflow(
|
||||
workflowId !== undefined &&
|
||||
workflowData.nodes.some((node) => node.type === ERROR_TRIGGER_TYPE)
|
||||
) {
|
||||
Logger.verbose('Start internal error workflow', { executionId, workflowId });
|
||||
logger.verbose('Start internal error workflow', { executionId, workflowId });
|
||||
void Container.get(OwnershipService)
|
||||
.getWorkflowOwnerCached(workflowId)
|
||||
.then((user) => {
|
||||
@@ -218,6 +219,7 @@ export function executeErrorWorkflow(
|
||||
*
|
||||
*/
|
||||
function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const pushInstance = Container.get(Push);
|
||||
return {
|
||||
nodeExecuteBefore: [
|
||||
@@ -229,7 +231,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.debug(`Executing hook on node "${nodeName}" (hookFunctionsPush)`, {
|
||||
logger.debug(`Executing hook on node "${nodeName}" (hookFunctionsPush)`, {
|
||||
executionId,
|
||||
sessionId,
|
||||
workflowId: this.workflowData.id,
|
||||
@@ -246,7 +248,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.debug(`Executing hook on node "${nodeName}" (hookFunctionsPush)`, {
|
||||
logger.debug(`Executing hook on node "${nodeName}" (hookFunctionsPush)`, {
|
||||
executionId,
|
||||
sessionId,
|
||||
workflowId: this.workflowData.id,
|
||||
@@ -259,7 +261,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
async function (this: WorkflowHooks): Promise<void> {
|
||||
const { sessionId, executionId } = this;
|
||||
const { id: workflowId, name: workflowName } = this.workflowData;
|
||||
Logger.debug('Executing hook (hookFunctionsPush)', {
|
||||
logger.debug('Executing hook (hookFunctionsPush)', {
|
||||
executionId,
|
||||
sessionId,
|
||||
workflowId,
|
||||
@@ -291,7 +293,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
): Promise<void> {
|
||||
const { sessionId, executionId, retryOf } = this;
|
||||
const { id: workflowId } = this.workflowData;
|
||||
Logger.debug('Executing hook (hookFunctionsPush)', {
|
||||
logger.debug('Executing hook (hookFunctionsPush)', {
|
||||
executionId,
|
||||
sessionId,
|
||||
workflowId,
|
||||
@@ -322,7 +324,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
}
|
||||
|
||||
// Push data to editor-ui once workflow finished
|
||||
Logger.debug(`Save execution progress to database for execution ID ${executionId} `, {
|
||||
logger.debug(`Save execution progress to database for execution ID ${executionId} `, {
|
||||
executionId,
|
||||
workflowId,
|
||||
});
|
||||
@@ -340,6 +342,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
|
||||
}
|
||||
|
||||
export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const externalHooks = Container.get(ExternalHooks);
|
||||
return {
|
||||
workflowExecuteBefore: [
|
||||
@@ -368,7 +371,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
|
||||
}
|
||||
|
||||
try {
|
||||
Logger.debug(
|
||||
logger.debug(
|
||||
`Save execution progress to database for execution ID ${this.executionId} `,
|
||||
{ executionId: this.executionId, nodeName },
|
||||
);
|
||||
@@ -436,7 +439,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
|
||||
// For busy machines, we may get "Database is locked" errors.
|
||||
|
||||
// We do this to prevent crashes and executions ending in `unknown` state.
|
||||
Logger.error(
|
||||
logger.error(
|
||||
`Failed saving execution progress to database for execution ID ${this.executionId} (hookFunctionsPreExecute, nodeExecuteAfter)`,
|
||||
{
|
||||
...err,
|
||||
@@ -456,6 +459,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
|
||||
*
|
||||
*/
|
||||
function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const internalHooks = Container.get(InternalHooks);
|
||||
const eventsService = Container.get(EventsService);
|
||||
return {
|
||||
@@ -476,7 +480,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
fullRunData: IRun,
|
||||
newStaticData: IDataObject,
|
||||
): Promise<void> {
|
||||
Logger.debug('Executing hook (hookFunctionsSave)', {
|
||||
logger.debug('Executing hook (hookFunctionsSave)', {
|
||||
executionId: this.executionId,
|
||||
workflowId: this.workflowData.id,
|
||||
});
|
||||
@@ -497,7 +501,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
);
|
||||
} catch (e) {
|
||||
ErrorReporter.error(e);
|
||||
Logger.error(
|
||||
logger.error(
|
||||
`There was a problem saving the workflow with id "${this.workflowData.id}" to save changed staticData: "${e.message}" (hookFunctionsSave)`,
|
||||
{ executionId: this.executionId, workflowId: this.workflowData.id },
|
||||
);
|
||||
@@ -581,7 +585,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
}
|
||||
} catch (error) {
|
||||
ErrorReporter.error(error);
|
||||
Logger.error(`Failed saving execution data to DB on execution ID ${this.executionId}`, {
|
||||
logger.error(`Failed saving execution data to DB on execution ID ${this.executionId}`, {
|
||||
executionId: this.executionId,
|
||||
workflowId: this.workflowData.id,
|
||||
error,
|
||||
@@ -615,6 +619,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||
*
|
||||
*/
|
||||
function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const internalHooks = Container.get(InternalHooks);
|
||||
const eventsService = Container.get(EventsService);
|
||||
return {
|
||||
@@ -639,7 +644,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||
fullRunData: IRun,
|
||||
newStaticData: IDataObject,
|
||||
): Promise<void> {
|
||||
Logger.debug('Executing hook (hookFunctionsSaveWorker)', {
|
||||
logger.debug('Executing hook (hookFunctionsSaveWorker)', {
|
||||
executionId: this.executionId,
|
||||
workflowId: this.workflowData.id,
|
||||
});
|
||||
@@ -653,7 +658,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||
);
|
||||
} catch (e) {
|
||||
ErrorReporter.error(e);
|
||||
Logger.error(
|
||||
logger.error(
|
||||
`There was a problem saving the workflow with id "${this.workflowData.id}" to save changed staticData: "${e.message}" (workflowExecuteAfter)`,
|
||||
{ sessionId: this.sessionId, workflowId: this.workflowData.id },
|
||||
);
|
||||
@@ -986,15 +991,16 @@ async function executeWorkflow(
|
||||
}
|
||||
|
||||
export function setExecutionStatus(status: ExecutionStatus) {
|
||||
const logger = Container.get(Logger);
|
||||
if (this.executionId === undefined) {
|
||||
Logger.debug(`Setting execution status "${status}" failed because executionId is undefined`);
|
||||
logger.debug(`Setting execution status "${status}" failed because executionId is undefined`);
|
||||
return;
|
||||
}
|
||||
Logger.debug(`Setting execution status for ${this.executionId} to "${status}"`);
|
||||
logger.debug(`Setting execution status for ${this.executionId} to "${status}"`);
|
||||
Container.get(ActiveExecutions)
|
||||
.setStatus(this.executionId, status)
|
||||
.catch((error) => {
|
||||
Logger.debug(`Setting execution status "${status}" failed: ${error.message}`);
|
||||
logger.debug(`Setting execution status "${status}" failed: ${error.message}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1009,7 +1015,8 @@ export function sendDataToUI(type: string, data: IDataObject | IDataObject[]) {
|
||||
const pushInstance = Container.get(Push);
|
||||
pushInstance.send(type as IPushDataType, data, sessionId);
|
||||
} catch (error) {
|
||||
Logger.warn(`There was a problem sending message to UI: ${error.message}`);
|
||||
const logger = Container.get(Logger);
|
||||
logger.warn(`There was a problem sending message to UI: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user