Hello Guys currently i have created a workflow and i want to log each node execution so i have created a code node and connected all nodes to code node & i am using javascript inside code but i am unable to get node names while logging
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
const logTime = new Date().toISOString();
let log = `[${logTime}] Workflow Execution Logs:\n\n`;
const inputs = $input.all();
const execKeys = Object.keys($execution || {});
inputs.forEach((entry, index) => {
let sourceNode = entry.json?.nodeNames || entry.source?.node || entry.source?.nodeNames || `Input #${index + 1}`;
let bestMatch = null;
let highestScore = 0;
if (!sourceNode || /^Input\s?#?\d*$/i.test(sourceNode)) {
for (const key of execKeys) {
const execEntry = $execution[key]?.[0];
if (!execEntry?.data) continue;
const execData = execEntry.data;
let score = 0;
for (const k of Object.keys(entry.json)) {
if (execData[k] && JSON.stringify(execData[k]) === JSON.stringify(entry.json[k])) {
score++;
}
}
if (score > highestScore) {
highestScore = score;
bestMatch = key;
}
}
if (bestMatch && highestScore > 0) {
sourceNode = bestMatch;
} else if (execKeys.length === 1) {
sourceNode = execKeys[0];
} else {
sourceNode = `Unknown Node (${index + 1})`;
}
}
const execInfo = $execution?.[sourceNode]?.[0];
if (execInfo?.error) {
log += ` Status: ❌ Error\n`;
log += ` Error: ${execInfo.error.message || JSON.stringify(execInfo.error)}\n`;
} else {
log += ` Status: ✅ Success\n`;
}
const data = entry.json;
if (Object.keys(data).length === 0) {
log += ` Output: (no data)\n`;
} else {
log += ` Output:\n`;
for (const key of Object.keys(data)) {
log += ` - ${key}: ${JSON.stringify(data[key])}\n`;
}
}
log += '\n';
});
return [{ json: { log } }];
Share the output returned by the last node
[
{
“log”:
“[2025-12-04T14:56:20.764Z] Workflow Execution Logs:\n\n Status:
Success\n Output:\n - event: “Manual execution”\n - timestamp: “2025-12-04T14:56:19.746Z”\n - workflow_id: “jviZsgdWHvsiwlVe”\n\n”
}
]
Information on your n8n setup
- n8n version:1.90
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:



