forked from ppkantorski/Ultrahand-Overlay
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite logger to use static buffer and printf-style syntax
- Loading branch information
1 parent
dcd6752
commit 6da34a6
Showing
17 changed files
with
216 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
#pragma once | ||
#include <algorithm> | ||
#include <cstdarg> | ||
#include <cstdio> | ||
#include <time.h> | ||
#include <chrono> | ||
|
||
void logMessage(const std::string& message) { | ||
std::time_t currentTime = std::time(nullptr); | ||
std::string logEntry = std::asctime(std::localtime(¤tTime)); | ||
std::size_t lastNonNewline = logEntry.find_last_not_of("\r\n"); | ||
if (lastNonNewline != std::string::npos) { | ||
logEntry.erase(lastNonNewline + 1); | ||
} | ||
logEntry = "[" + logEntry + "] " + message + "\n"; | ||
const char* logPath = "sdmc:/config/uberhand/log.txt"; | ||
|
||
char logTimeBuffer[std::size("yyyy-mm-dd hh:mm:ss")]{ 0 }; | ||
|
||
FILE* file = fopen("sdmc:/config/uberhand/log.txt", "a"); | ||
if (file != nullptr) { | ||
fputs(logEntry.c_str(), file); | ||
fclose(file); | ||
__attribute__((__format__(__printf__, 1, 2))) | ||
void log(const char* format, ...) noexcept { | ||
FILE* logFile = fopen(logPath, "a"); | ||
if (logFile == nullptr) { | ||
fprintf(stderr, "Failed to open log file: %s", logPath); | ||
return; | ||
} | ||
} | ||
u64 currentTime; | ||
timeGetCurrentTime(TimeType_NetworkSystemClock, ¤tTime); | ||
tm* localTime = std::localtime((std::time_t*)(¤tTime)); | ||
std::strftime(logTimeBuffer, sizeof(logTimeBuffer), "%F %T", localTime); | ||
|
||
fputc('[', logFile); | ||
fputs(logTimeBuffer, logFile); | ||
fputc(']', logFile); | ||
fputc(' ', logFile); | ||
va_list args; | ||
va_start(args, format); | ||
vfprintf(logFile, format, args); | ||
va_end(args); | ||
fputc('\n', logFile); | ||
fclose(logFile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.