mirror of
https://github.com/cathery/sys-con.git
synced 2024-09-28 22:40:47 +00:00
Discard large log files on boot
This commit is contained in:
parent
2aac5d747e
commit
f527c2c388
@ -306,6 +306,7 @@ namespace syscon::config
|
|||||||
|
|
||||||
Result Initialize()
|
Result Initialize()
|
||||||
{
|
{
|
||||||
|
DiscardOldLogs();
|
||||||
config::LoadAllConfigs();
|
config::LoadAllConfigs();
|
||||||
config::CheckForFileChanges();
|
config::CheckForFileChanges();
|
||||||
utimerCreate(&filecheckTimer, 1e+9L, TimerType_Repeating);
|
utimerCreate(&filecheckTimer, 1e+9L, TimerType_Repeating);
|
||||||
|
@ -5,6 +5,30 @@
|
|||||||
|
|
||||||
static ams::os::Mutex printMutex;
|
static ams::os::Mutex printMutex;
|
||||||
|
|
||||||
|
void DiscardOldLogs()
|
||||||
|
{
|
||||||
|
std::scoped_lock printLock(printMutex);
|
||||||
|
|
||||||
|
FsFileSystem *fs = fsdevGetDeviceFileSystem("sdmc");
|
||||||
|
FsFile file;
|
||||||
|
s64 fileSize;
|
||||||
|
|
||||||
|
Result rc = fsFsOpenFile(fs, LOG_PATH, FsOpenMode_Read, &file);
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
rc = fsFileGetSize(&file, &fileSize);
|
||||||
|
fsFileClose(&file);
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fileSize >= 0x20'000)
|
||||||
|
{
|
||||||
|
fsFsDeleteFile(fs, LOG_PATH);
|
||||||
|
WriteToLog("Deleted previous log file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WriteToLog(const char *fmt, ...)
|
void WriteToLog(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
std::scoped_lock printLock(printMutex);
|
std::scoped_lock printLock(printMutex);
|
||||||
@ -14,7 +38,7 @@ void WriteToLog(const char *fmt, ...)
|
|||||||
timeGetCurrentTime(TimeType_LocalSystemClock, &ts);
|
timeGetCurrentTime(TimeType_LocalSystemClock, &ts);
|
||||||
timeToCalendarTimeWithMyRule(ts, &caltime, nullptr);
|
timeToCalendarTimeWithMyRule(ts, &caltime, nullptr);
|
||||||
|
|
||||||
FILE *fp = fopen(CONFIG_PATH "log.txt", "a");
|
FILE *fp = fopen(LOG_PATH, "a");
|
||||||
|
|
||||||
//Print time
|
//Print time
|
||||||
fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", caltime.year, caltime.month, caltime.day, caltime.hour, caltime.minute, caltime.second);
|
fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", caltime.year, caltime.month, caltime.day, caltime.hour, caltime.minute, caltime.second);
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define LOG_PATH CONFIG_PATH "log.txt"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
void DiscardOldLogs();
|
||||||
|
|
||||||
void WriteToLog(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
void WriteToLog(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user