Skip to content

Commit 97ce507

Browse files
Refactor logging to use n8n-logging (#15)
* refactor: using n8n-logging instead of console.log * refactor: replace console.error with Logger.error and improve logging structure
1 parent d049bd9 commit 97ce507

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
1+
import { IExecuteFunctions, INodeExecutionData, LoggerProxy as Logger } from 'n8n-workflow';
22

33
export async function executeCancelWorkflowExecution(
44
this: IExecuteFunctions,
55
i: number,
66
baseURL: string,
77
): Promise<INodeExecutionData> {
88
try {
9-
console.log('Starting workflow execution cancellation...');
9+
Logger.info('Starting workflow execution cancellation...');
1010

1111
// Get the workflow and execution IDs
1212
const workflowId = this.getNodeParameter('workflowId', i) as string;
1313
const executionId = this.getNodeParameter('executionId', i) as string;
1414

15-
console.log('Parameters:', { workflowId, executionId });
15+
Logger.info('Parameters:', { workflowId, executionId });
1616

1717
try {
1818
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'featherApi', {
@@ -25,7 +25,7 @@ export async function executeCancelWorkflowExecution(
2525
json: true,
2626
});
2727

28-
console.log('Workflow execution cancelled successfully:', JSON.stringify(response, null, 2));
28+
Logger.info('Workflow execution cancelled successfully:', { response });
2929

3030
return {
3131
json: response,
@@ -34,16 +34,16 @@ export async function executeCancelWorkflowExecution(
3434
},
3535
};
3636
} catch (apiError) {
37-
console.error('API request failed:', apiError);
38-
console.error('Request details:', {
37+
Logger.error('API request failed:', { error: apiError });
38+
Logger.error('Request details:', {
3939
url: `${baseURL}/api/v1/workflow/${workflowId}/executions/${executionId}/cancel`,
4040
workflowId,
4141
executionId,
4242
});
4343
throw apiError;
4444
}
4545
} catch (error) {
46-
console.error('Error in workflow execution cancellation:', error);
46+
Logger.error('Error in workflow execution cancellation:', { error });
4747
throw error;
4848
}
4949
}

nodes/Feather/operations/createAgentWorkflow.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
1+
import { IExecuteFunctions, INodeExecutionData, LoggerProxy as Logger } from 'n8n-workflow';
22

33
type WorkflowStep = {
44
id: string;
@@ -72,7 +72,7 @@ export async function executeCreateAgentWorkflow(
7272
baseURL: string,
7373
): Promise<INodeExecutionData> {
7474
try {
75-
console.log('Starting workflow creation...');
75+
Logger.info('Starting workflow creation...');
7676

7777
// Get basic workflow information
7878
const name = this.getNodeParameter('name', i) as string;
@@ -81,11 +81,11 @@ export async function executeCreateAgentWorkflow(
8181
const timezone = this.getNodeParameter('timezone', i) as string;
8282
const agentId = this.getNodeParameter('agentId', i) as string;
8383

84-
console.log('Basic parameters:', { name, description, active, timezone, agentId });
84+
Logger.info('Basic parameters:', { name, description, active, timezone, agentId });
8585

8686
// Get step configuration
8787
const stepConfig = this.getNodeParameter('stepConfiguration', i) as Record<string, unknown>;
88-
console.log('Step configuration:', stepConfig);
88+
Logger.info('Step configuration:', stepConfig);
8989

9090
// Get schedule configurations
9191
const workflowScheduleUi = this.getNodeParameter('workflowScheduleUi', i) as Record<
@@ -97,7 +97,7 @@ export async function executeCreateAgentWorkflow(
9797
const workflowScheduleData = workflowScheduleUi?.scheduleConfiguration || {};
9898
const tcpaScheduleData = tcpaScheduleUi?.tcpaConfiguration || {};
9999

100-
console.log('Schedule configurations:', { workflowScheduleData, tcpaScheduleData });
100+
Logger.info('Schedule configurations:', { workflowScheduleData, tcpaScheduleData });
101101

102102
// Build workflow schedule
103103
const workflowSchedule: Schedule = {
@@ -123,7 +123,7 @@ export async function executeCreateAgentWorkflow(
123123

124124
// Configure workflow schedule
125125
if (workflowScheduleData) {
126-
console.log('Configuring workflow schedule...');
126+
Logger.info('Configuring workflow schedule...');
127127
const scheduleData = workflowScheduleData as Record<string, unknown>;
128128
const {
129129
workingDays = [],
@@ -133,7 +133,7 @@ export async function executeCreateAgentWorkflow(
133133
workingMinutesEnd = 0,
134134
} = scheduleData;
135135

136-
console.log('Working days configuration:', { workingDays });
136+
Logger.info('Working days configuration:', { workingDays });
137137

138138
if (Array.isArray(workingDays) && workingDays.length > 0) {
139139
for (const day of workingDays) {
@@ -149,15 +149,15 @@ export async function executeCreateAgentWorkflow(
149149
],
150150
};
151151
}
152-
console.log('Workflow schedule configured:', workflowSchedule);
152+
Logger.info('Workflow schedule configured:', workflowSchedule);
153153
} else {
154-
console.log('No working days configured, using default empty schedule');
154+
Logger.info('No working days configured, using default empty schedule');
155155
}
156156
}
157157

158158
// Configure TCPA schedule
159159
if (tcpaScheduleData) {
160-
console.log('Configuring TCPA schedule...');
160+
Logger.info('Configuring TCPA schedule...');
161161
const tcpaData = tcpaScheduleData as Record<string, unknown>;
162162
const {
163163
tcpaDays = [],
@@ -167,7 +167,7 @@ export async function executeCreateAgentWorkflow(
167167
tcpaMinutesEnd = 0,
168168
} = tcpaData;
169169

170-
console.log('TCPA days configuration:', { tcpaDays });
170+
Logger.info('TCPA days configuration:', { tcpaDays });
171171

172172
if (Array.isArray(tcpaDays) && tcpaDays.length > 0) {
173173
for (const day of tcpaDays) {
@@ -183,9 +183,9 @@ export async function executeCreateAgentWorkflow(
183183
],
184184
};
185185
}
186-
console.log('TCPA schedule configured:', tcpaSchedule);
186+
Logger.info('TCPA schedule configured:', tcpaSchedule);
187187
} else {
188-
console.log('No TCPA days configured, using default empty schedule');
188+
Logger.info('No TCPA days configured, using default empty schedule');
189189
}
190190
}
191191

@@ -201,7 +201,7 @@ export async function executeCreateAgentWorkflow(
201201
definition: stepDefinition,
202202
};
203203

204-
console.log('Preparing API request with workflow:', JSON.stringify(workflow, null, 2));
204+
Logger.info('Preparing API request with workflow:', { workflow });
205205

206206
try {
207207
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'featherApi', {
@@ -215,7 +215,7 @@ export async function executeCreateAgentWorkflow(
215215
json: true,
216216
});
217217

218-
console.log('Workflow created successfully:', JSON.stringify(response, null, 2));
218+
Logger.info('Workflow created successfully:', { response });
219219

220220
return {
221221
json: response,
@@ -224,15 +224,15 @@ export async function executeCreateAgentWorkflow(
224224
},
225225
};
226226
} catch (apiError) {
227-
console.error('API request failed:', apiError);
228-
console.error('Request details:', {
227+
Logger.error('API request failed:', apiError);
228+
Logger.error('Request details:', {
229229
url: `${baseURL}/api/v1/workflow`,
230230
workflow,
231231
});
232232
throw apiError;
233233
}
234234
} catch (error) {
235-
console.error('Error in workflow creation:', error);
235+
Logger.error('Error in workflow creation:', error);
236236
throw error;
237237
}
238238
}

nodes/Feather/operations/createWorkflowExecution.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { IExecuteFunctions, INodeExecutionData, NodeOperationError } from 'n8n-workflow';
1+
import { IExecuteFunctions, INodeExecutionData, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
22

33
export async function executeCreateWorkflowExecution(
44
this: IExecuteFunctions,
55
i: number,
66
baseURL: string,
77
): Promise<INodeExecutionData> {
88
try {
9-
console.log('Starting workflow execution creation...');
9+
Logger.info('Starting workflow execution creation...');
1010

1111
// Get required parameters
1212
const workflowId = this.getNodeParameter('workflowId', i) as string;
@@ -75,7 +75,7 @@ export async function executeCreateWorkflowExecution(
7575
}
7676
}
7777

78-
console.log('Basic parameters:', { workflowId, customerLeadId, primaryPhone, zipcode, state });
78+
Logger.info('Basic parameters:', { workflowId, customerLeadId, primaryPhone, zipcode, state });
7979

8080
// Build request body
8181
const body: Record<string, unknown> = {
@@ -132,7 +132,7 @@ export async function executeCreateWorkflowExecution(
132132

133133
body.metadata = metadata;
134134

135-
console.log('Preparing API request with execution data:', JSON.stringify(body, null, 2));
135+
Logger.info('Preparing API request with execution data:', { body});
136136

137137
try {
138138
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'featherApi', {
@@ -146,25 +146,24 @@ export async function executeCreateWorkflowExecution(
146146
json: true,
147147
});
148148

149-
console.log('Workflow execution created successfully:', JSON.stringify(response, null, 2));
150-
149+
Logger.info('Workflow execution created successfully:', { response });
151150
return {
152151
json: response,
153152
pairedItem: {
154153
item: i,
155154
},
156155
};
157156
} catch (apiError) {
158-
console.error('API request failed:', apiError);
159-
console.error('Request details:', {
157+
Logger.error('API request failed:', apiError);
158+
Logger.error('Request details:', {
160159
url: `${baseURL}/api/v1/workflow/${workflowId}/execution`,
161160
workflowId,
162161
body,
163162
});
164163
throw apiError;
165164
}
166165
} catch (error) {
167-
console.error('Error in workflow execution creation:', error);
166+
Logger.error('Error in workflow execution creation:', error);
168167
throw error;
169168
}
170169
}

0 commit comments

Comments
 (0)