1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-05 08:26:32 +00:00
sys-con/source/log.h
2019-11-07 01:20:58 +03:00

41 lines
862 B
C++

#pragma once
#include <iomanip>
#include <fstream>
#include <iostream>
#include "configFile.h"
template <typename... T>
void WriteToLog(T &&... text)
{
#ifdef __APPLET__
std::stringstream ss;
((ss << text), ...);
printf(ss.str().c_str());
printf("\n");
#else
using namespace std;
time_t unixTime = time(NULL);
struct tm *time = localtime((const time_t *)&unixTime);
fstream fs;
fs.open(CONFIG_PATH "log.txt", fstream::app);
//Print time
fs << setfill('0');
fs << setw(4) << (time->tm_year + 1900)
<< "-" << setw(2) << time->tm_mon
<< "-" << setw(2) << time->tm_mday
<< " " << setw(2) << time->tm_hour
<< ":" << setw(2) << time->tm_min
<< ":" << setw(2) << time->tm_sec << ": ";
//Print the actual text
((fs << text), ...);
fs << "\n";
fs.close();
#endif
}