I am trying to write logs or traces of my n8n flow but if I try to use the provided documentation (Logging | n8n Docs) the js code gives me the following error: Cannot use import statement outside a module. To understand what was happening I have also reviewed this forum thread LoggerProxy - Example Usage - #2 by hubschrauber but it gives me this error Cannot read properties of undefined (reading ‘debug’) [line 1], so I don’t know what I’m not understanding
hello @atenea84
That’s because you don’t have the opportunity to write logs. You should rely on the Error workflow behavior to catch the error in any workflow. Then you can check the execution and see what was wrong. The pages you have specified refer to building the custom nodes.
I trust the flow, but for business and traceability reasons, I need custom logs. I think the answer I got can’t be because it fails from the “import”, and it doesn’t even attempt to write.
You can try adding console.log("log line")
if you want to just see it in the frontend
{
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
0,
0
],
"id": "f5493a26-b590-4929-979c-6a9d4971fc17",
"name": "When clicking ‘Test workflow’"
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n item.json.myNewField = 1;\n console.log(\"added field\")\n}\n\nreturn $input.all();"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
220,
0
],
"id": "fbba4698-d187-4563-9af4-78a831c927ef",
"name": "Code with logging"
}
],
"connections": {
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Code with logging",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"instanceId": "ace885814db9b67dd2490b365735363256b8712c3324138bc33d0a3d82ef8908"
}
}```
Yes, I tried that but it is not recorded at the server level.
In that scenario, I believe that logging to external system would be the easiest way…
No, you don’t
Your logs are your executions themselves. You can export them, but that doesn’t make much sense.
Rather than that, you can use the log streaming functionality, but that is more about auth and user’s actions logs. And it requires an enterprise plan.
Log streaming | n8n Docs
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.