6 months ago
I have n8n deployed on railway as a Docker container using https://railway.com/deploy/r2SNX_ , and I’m trying to debug a Function/Code node by printing values with console.log (and even console.error), but I can’t find any of those messages anywhere.
What I’m doing
My node code looks like this:
// Loop over input items and add a new field to each one for (const item of $input.all()) { item.json.myNewField = 1; } // Attempt to log the first item’s name console.log($input.first().json.name); return $input.all();
I’ve also tried:
console.error('DEBUG VALUE:', $input.first().json.name); throw new Error('halting here so you can see the log');
Environment
n8n version: latest Docker image (
n8nio/n8n:latest)Host: Railway.com (Docker deployment)
Logging level: set
N8N_LOG_LEVEL=debugin Railway env vars, then redeployed
3 Replies
6 months ago
Hi,
In n8n, console.log() and console.error() inside functions do not send output to the main container logs, this is by design as n8n sandbox isolates code execution for security and this means it won't show in the main container logs. This is the case even having N8N_LOG_LEVEL=debug enabled.
You'd could try using throw new Error() to expose the values to the console:
throw new Error('DEBUG: ' + JSON.stringify($input.first().json.name));You could also try using an external logging service, such as requestbin or a temp n8n webhook node.
I'd really appreciate if you could accept this answer if it helps to solve your problem. 
6 months ago
Have you checked the browser console? As per their community, that is where the logs show up https://community.n8n.io/t/not-seeing-logs-added-in-code-node-in-server-logs/125849
6 months ago
They have detailed documentation available on how logging in n8n works https://docs.n8n.io/code/cookbook/code-node/console-log/
