Skip to content

c code snippets

MilesBai edited this page Apr 18, 2024 · 1 revision

raw log

#include <ctime>
#include <iomanip>

void appendLog(const std::string& msg)
{
    // Get the current time
    std::time_t now = std::time(nullptr);
    // Convert to local time
    std::tm *ltm = std::localtime(&now);
    std::ofstream ofile("/tmp/pybind_log.txt", std::ios::out | std::ios::app);
    ofile << std::put_time(ltm, "%Y-%m-%d %H:%M:%S") << "  :  " << msg << std::endl;
    ofile.close();
}
Clone this wiki locally