1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-10-04 13:29:43 +00:00
sys-con/source/Sysmodule/source/log.cpp
2020-03-13 13:46:12 +03:00

36 lines
831 B
C++

#include "switch.h"
#include "log.h"
#include "config_handler.h"
#include <stratosphere.hpp>
static ams::os::Mutex printMutex;
void WriteToLog(const char *fmt, ...)
{
std::scoped_lock printLock(printMutex);
u64 ts;
TimeCalendarTime caltime;
timeGetCurrentTime(TimeType_LocalSystemClock, &ts);
timeToCalendarTimeWithMyRule(ts, &caltime, nullptr);
FILE *fp = fopen(CONFIG_PATH "log.txt", "a");
//Print time
fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", caltime.year, caltime.month, caltime.day, caltime.hour, caltime.minute, caltime.second);
//Print the actual text
va_list va;
va_start(va, fmt);
vfprintf(fp, fmt, va);
va_end(va);
fprintf(fp, "\n");
fclose(fp);
}
void LockedUpdateConsole()
{
std::scoped_lock printLock(printMutex);
consoleUpdate(NULL);
}