{
  "id": "0twZGM6kPlG2rFsv",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "TEMPL - Logger Sub-Workflow",
  "tags": [],
  "nodes": [
    {
      "id": "d8485aa8-429a-4eca-804b-2e2b5ed1a61e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        -48
      ],
      "parameters": {
        "color": 4,
        "width": 816,
        "height": 1248,
        "content": "## Centralized Logging with Supabase (Log4j2-style)\n\n\nThis workflow provides a simple yet powerful logging solution for n8n, inspired by Log4j2's log levels. \n\nIt enables you to send structured log entries (DEBUG, INFO, WARN, ERROR, FATAL) directly to a Supabase PostgreSQL database. Whether you're tracking workflow executions, node-level issues, or custom debugging events, this template offers a clean and scalable way to store and query logs from across your automation stack \u2014 perfect for monitoring, debugging, or building analytics dashboards.\n\n\nYou need first to setup Supabase database and credentials:\n\n\n### 1. Supabase Configuration\n\n- Create an enumerated type (in Database -> Database Management -> Enumerated Types):\n\t- Name: **log_level_type**\n\t- Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL\n\n\n- Create a table **logs** with following fields  (in Database -> Database Management -> Tables):\n\t- id #int8 (leave by default)\n\t- created_at timestamp (leave by default)\n\t- workflow_name text (deactivate the \"Is Nullable\" option)\n\t- node_name text (deactivate the \"Is Nullable\" option)\n\t- execution_id text (deactivate the \"Is Nullable\" option)\n\t- log_level log_level_type (deactivate the \"Is Nullable\" option)\n\t- message text (deactivate the \"Is Nullable\" option)\n  \t- metadata json\n\n\n- If you prefer the SQL scripts:\n\n```\n-- Enum type for log_level\ncreate type log_level_type as enum ('TRACE','DEBUG','INFO','WARN','ERROR','FATAL');\n  \n-- logs table\ncreate table publi c.logs (\n  id bigserial primary key,\n  created_at timestamp with time zone default now() not null,\n  workflow_name text not null,\n  node_name text not null,\n  execution_id text not null,\n  log_level log_level_type not null,\n  message text not null,\n  metadata jsonb\n);\n```\n\n\n\n### 2. Create Credentials to your Supabase Account in N8N\n\nhttps://docs.n8n.io/integrations/builtin/credentials/supabase/\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "80068177-98b8-46bf-bfb6-74613e8ce905",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        -48
      ],
      "parameters": {
        "color": 6,
        "width": 672,
        "height": 400,
        "content": "## SUB-WORKFLOW\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a7fc9373-b69d-4b44-a1ec-6ab987f442b1",
      "name": "When Log Traced",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        192,
        96
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "workflow_name"
            },
            {
              "name": "node_name"
            },
            {
              "name": "execution_id"
            },
            {
              "name": "log_level"
            },
            {
              "name": "message"
            },
            {
              "name": "metadata",
              "type": "object"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "efde8a30-d04e-4c3d-a9e7-a689cad53e8b",
      "name": "Create Log",
      "type": "n8n-nodes-base.supabase",
      "position": [
        416,
        96
      ],
      "parameters": {
        "tableId": "logs",
        "dataToSend": "autoMapInputData"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ffc0d43-de4f-498f-918b-7075ef9404a2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 400,
        "content": "## Usage Example : FATAL log from an error handler\n\nThis is a generic error handler workflow that you can configure in a workflow settings."
      },
      "typeVersion": 1
    },
    {
      "id": "aed41c4a-37d9-4d69-99f6-8f1ac4b9604d",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "disabled": true,
      "position": [
        96,
        992
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8708f89c-3c24-4a79-9228-9d30dcfcb470",
      "name": "Log Fatal",
      "type": "n8n-nodes-base.code",
      "disabled": true,
      "position": [
        304,
        992
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const e = $json; // Error Trigger\nreturn {\n        \"workflow_name\": e.workflow?.name ?? $workflow.name,\n        \"node_name\": e.execution?.lastNodeExecuted ?? $prevNode.name,\n        \"execution_id\": e.execution?.id ?? $execution.id,\n        \"log_level\": \"FATAL\",\n        \"message\": e.execution?.error?.message ?? 'Unknown error',  \n        \"metadata\": e\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "c04e954e-f560-4240-b6f2-940e9922b5ab",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 400,
        "content": "## Usage Example : log a DEBUG or INFO message\n\nCustomize the log_level, message and optional metadata.\nUse inside a workflow to trace info and debug messages."
      },
      "typeVersion": 1
    },
    {
      "id": "f2beed08-2ade-4250-bdab-370939d8397e",
      "name": "Call Logger SubWorkflow 1",
      "type": "n8n-nodes-base.executeWorkflow",
      "disabled": true,
      "position": [
        512,
        992
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": false
        },
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "0twZGM6kPlG2rFsv",
          "cachedResultName": "TEMPL - Logger Sub-Workflow"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "13f0d706-7f4e-4d97-bc90-2ab8ebce390e",
      "name": "Log Info",
      "type": "n8n-nodes-base.code",
      "disabled": true,
      "position": [
        208,
        560
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": " return {\n        \"workflow_name\": $workflow.name,\n        \"node_name\": $prevNode.name || \"Unknown node\",\n        \"execution_id\": $execution.id,\n        \"log_level\": \"INFO\",\n        \"message\": \"Insert your message here\",        \n        \"metadata\": {\n           \"attr1\": \"value1\",\n           \"attr2\": 123\n        }\n }"
      },
      "typeVersion": 2
    },
    {
      "id": "2bb9b8a3-876f-4246-8f41-81163dae799a",
      "name": "Call Logger SubWorkflow 2",
      "type": "n8n-nodes-base.executeWorkflow",
      "disabled": true,
      "position": [
        400,
        560
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": false
        },
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "0twZGM6kPlG2rFsv",
          "cachedResultName": "TEMPL - Logger Sub-Workflow"
        },
        "workflowInputs": {
          "value": {
            "message": "={{ $json.message }}",
            "metadata": "={{ $json.metadata }}",
            "log_level": "={{ $json.log_level }}",
            "node_name": "={{ $json.node_name }}",
            "execution_id": "={{ $json.execution_id }}",
            "workflow_name": "={{ $json.workflow_name }}"
          },
          "schema": [
            {
              "id": "workflow_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "workflow_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "node_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "node_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "execution_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "execution_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "log_level",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "log_level",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "metadata",
              "type": "object",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "metadata",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "00769a5f-87e6-423a-a420-36ca80479403",
  "connections": {
    "Log Info": {
      "main": [
        [
          {
            "node": "Call Logger SubWorkflow 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Fatal": {
      "main": [
        [
          {
            "node": "Call Logger SubWorkflow 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Log Fatal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Log Traced": {
      "main": [
        [
          {
            "node": "Create Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}