Get name of the previous node - Dump node information into a file

I'd like to get the name or something like this from the previous node. This request is similar to this one.

I want create a subflow that logs all information of it's msg. This will be similar to a debug node, but 'my' node will dump the information into a file. It would be nice if the handling of my log node would be as comfortable as the debug node already is.

So my first approach was to add some information into the previous node (msg.source_name = node.name).
This works as expected, but I have to modify the source node and that's not so nice.

Second I tried the proposal of jbudd to use a link call node.
OK. This gives me the _linkSource. Not very comfortable to figure out the corresponding node, but this would be OK for me.

BUT.
It seems that the link call node does not work inside a Subflow, as it works outside.
Outside of a subflow I do get something like this:

{"_msgid":"1a57f632ed223fd2","payload":1728556169732,"topic":"","_linkSource":[{"id":"875785eb3099847eac1f8fb30c9a","node":"ab4c6a1084d87fc1"}]}

Bildschirmfoto vom 2024-10-10 12-37-14

But inside I get this:
["_linkSource",[{"id":"8018b8e7ba9f780e9376b0646887","node":"59c051392d4f7fb9"}]]

Bildschirmfoto vom 2024-10-10 12-45-04

It looks similar, but I'm not able to figure out which node belongs to node '59c051392d4f7fb9'.

I understand that things work a little different within a subflow because a subflow is a kind of a template for it's instances. There might be a lot of individual instances and at the end all instances are a 'copy' of the subflow. So this is different to a subroutine in c or python.

Does anybody have a smart idea? How can I dump node information into a file similar to the debug node in the side bar?

I found a solution that is good enough for me:

[{"id":"1b8b263ddb6b5c30","type":"subflow","name":"log file","info":"","category":"","in":[{"x":40,"y":300,"wires":[{"id":"236ec74193e5d814"}]}],"out":[],"env":[],"meta":{},"color":"#DDAA99"},{"id":"236ec74193e5d814","type":"function","z":"1b8b263ddb6b5c30","name":"write to log","func":"let logpointName = [\"logNode\", env.get(\"NR_SUBFLOW_NAME\")];\nlet ObjectAr = Object.entries(msg);\n\nmsg.payload = logpointName.concat(ObjectAr);\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":300,"wires":[["4f6dcf6a3f9a7393"]]},{"id":"4f6dcf6a3f9a7393","type":"file","z":"1b8b263ddb6b5c30","name":"write to log.txt","filename":"/home/gretac/data/log.txt","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":520,"y":300,"wires":[[]]}]

And this is the important part within the function node:

let logpointName = ["logNode", env.get("NR_SUBFLOW_NAME")];
let ObjectAr = Object.entries(msg);
msg.payload = logpointName.concat(ObjectAr);
return msg;

"NR_SUBFLOW_NAME" is available sine Node-Red 3.1, so I had to upgrade it on my system.

The only nice improvement I see is a mechanism within Node-Red that offers an automatic default enumeration for subnodes like we have it for others like function node or debug node.