How to create log properly

I am using docker-compose and setting the N8N_LOG_FILE_LOCATION variable. I am seeing logs, but not my console.log . Based on this thread it seems like using console.log() is not recommended. I looked through this document and I am still a bit confused. I tried adding the js in a Code node, but I get the error Problem in node ‘Code‘ 'import' and 'export' may only appear at the top level [line 1]

Workflow json:

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    container_name: n8n
    ports:
      - 5678:5678
    environment:
      - WEBHOOK_URL=http://localhost:5678/
      - EXECUTIONS_PROCESS=main
      - TEST_ENV=testenv
      - TEST_ENV2=thisisanothertestenv
      - N8N_LOG_LEVEL=debug
      - N8N_LOG_OUTPUT=console,file
      - N8N_LOG_FILE_LOCATION=/home/node/.n8n/logs/n8n.log
      - N8N_LOG_FILE_MAXSIZE=50
      - N8N_LOG_FILE_MAXCOUNT=60
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  n8n_data:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @jtoh

what are you trying to achieve?

console.log in the Code node outputs the content to the client console, it’s not the server-side feature. console.log or LoggerProxy in the TS code acts differently, but that one is only for debugging issues with the community nodes. You normally should not collect it.

@barn4k ahh I didn’t know that, there wasn’t any mention of community node in there.

Basically, my goal is just to create logs on my workflows that I can look up later. For example, if a http request fails on a scheduled job, i would like to capture the error response message.

Maybe I need to use logging systems like AWS CloudWatch or something? I just wanted to first check if there was something native.

The title a little bit earlier says it is for development :slight_smile:

You will see the error in the execution log. It is enabled by default for each workflow. You can also set the error workflow to send the errors somewhere (splunk, database, email, etc) and attach that workflow inside the desired workflows in the settings section.

The best approach is to set the error workflow(s). n8n logs are needed for internal purposes or n8n debug when something strange is happening.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.