opto-coupler: transistor vs logic

Is this the right way to add the RC Low-pass filter (R2 & C1)? See attached schematic.