How can I stop a program from logging data into an SD card?

Use if (digitalRead(somePin == HIGH)) then add a section of code to stop the logging.