{{{+1 Solution 1 }}} This is the most simple way to append simple log strings to a file if DEBUG is defined. {{{#!gcode C++ #include "stdio.h" void WriteLogFile(const char* szString) { #ifdef DEBUG FILE* pFile = fopen("logFile.txt", "a"); fprintf(pFile, "%s\n",szString); fclose(pFile); #endif } }}} {{{+1 Solution 2 }}} C++ answer for the same thing {{{#!gcode C++ #include void write_text_to_log_file(const std::string &text) { std::ofstream log_file( "log_file.txt", std::ios_base::out | std::ios_base::app ); log_file << text << std::end; } }}}