You may be disappointed. - The function node is only dummy to demonstrate where the switch node has to be placed. So my function node is a dummy and should be replaced with your function node.
The logic is still simple:
With the switch - I set a flow variable logging to true or false - dependend on the switch.
The switch node in front of your file node blocks all messages if the flow variable logging isn't true.
If you need to initialize your flow variable to a specific value then use an inject node which act as input as well and sends only one message after node-red is started. In this case you can use pass through of the dashboard switch.
[{"id":"b4c0206a2b9d36ce","type":"ui_switch","z":"c451086a0228abe0","name":"","label":"switch","tooltip":"","group":"8439522ea5fad93c","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":630,"y":180,"wires":[["7bf1ce8f689ece25"]]},{"id":"7bf1ce8f689ece25","type":"change","z":"c451086a0228abe0","name":"","rules":[{"t":"set","p":"logging","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":180,"wires":[[]]},{"id":"99bd263a70cdef9d","type":"switch","z":"c451086a0228abe0","name":"allow logging","property":"logging","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":300,"wires":[["268359bb89df44fe"]]},{"id":"109c875874c35d74","type":"file","z":"c451086a0228abe0","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":790,"y":300,"wires":[[]]},{"id":"a8b46906379c4b31","type":"inject","z":"c451086a0228abe0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":320,"wires":[["99bd263a70cdef9d"]]},{"id":"268359bb89df44fe","type":"debug","z":"c451086a0228abe0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":360,"wires":[]},{"id":"d29dcbc8a62e4387","type":"inject","z":"c451086a0228abe0","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":490,"y":180,"wires":[["b4c0206a2b9d36ce"]]},{"id":"8439522ea5fad93c","type":"ui_group","name":"Test","tab":"49e9f4d45b15375e","order":1,"disp":true,"width":"6","collapse":false},{"id":"49e9f4d45b15375e","type":"ui_tab","name":"Test","icon":"dashboard","order":5,"disabled":false,"hidden":false}]