Found the solution.
I have made a variant subsystem, wherein the production code variant I have used 'Ground' blocks as sources such that the code generator reduces those blocks for logging. I did have to use the Bus Creator and named signals for the code generator to not complain about a missing bus.
The Variant subsystem is controlled by a Simulink.Variant parameter inside my data dictionary with the expression:
strcmp('ert.tlc',get_param('controller','SystemTargetFile'))
This way, the PI controller with logging function is used for simulation and prototyping, and is not used for production code generation.