v1
Laptop Windows 2024-02-21 20:36:22 -05:00
parent 43cf8c0ba1
commit 89bde7c6e8
3 changed files with 62 additions and 32 deletions

View File

@ -319,17 +319,17 @@ namespace blt::logging {
}
};
#define BLT_NOW() auto t = std::time(nullptr); auto now = std::localtime(&t)
#define BLT_ISO_YEAR(S) auto S = std::to_string(now->tm_year + 1900); \
#define BLT_NOW() auto t = std::time(nullptr); tm now; localtime_s(&now, &t); //auto now = std::localtime(&t)
#define BLT_ISO_YEAR(S) auto S = std::to_string(now.tm_year + 1900); \
S += '-'; \
S += ensureHasDigits(now->tm_mon+1, 2); \
S += ensureHasDigits(now.tm_mon+1, 2); \
S += '-'; \
S += ensureHasDigits(now->tm_mday, 2);
#define BLT_CUR_TIME(S) auto S = ensureHasDigits(now->tm_hour, 2); \
S += ensureHasDigits(now.tm_mday, 2);
#define BLT_CUR_TIME(S) auto S = ensureHasDigits(now.tm_hour, 2); \
S += ':'; \
S += ensureHasDigits(now->tm_min, 2); \
S += ensureHasDigits(now.tm_min, 2); \
S += ':'; \
S += ensureHasDigits(now->tm_sec, 2);
S += ensureHasDigits(now.tm_sec, 2);
static inline std::string ensureHasDigits(int current, int digits) {
std::string asString = std::to_string(current);
@ -352,27 +352,27 @@ namespace blt::logging {
const std::unique_ptr<tag_map> tagMap = std::make_unique<tag_map>(tag_map{
{"YEAR", [](const tag_func_param&) -> std::string {
BLT_NOW();
return std::to_string(now->tm_year);
return std::to_string(now.tm_year);
}},
{"MONTH", [](const tag_func_param&) -> std::string {
BLT_NOW();
return ensureHasDigits(now->tm_mon+1, 2);
return ensureHasDigits(now.tm_mon+1, 2);
}},
{"DAY", [](const tag_func_param&) -> std::string {
BLT_NOW();
return ensureHasDigits(now->tm_mday, 2);
return ensureHasDigits(now.tm_mday, 2);
}},
{"HOUR", [](const tag_func_param&) -> std::string {
BLT_NOW();
return ensureHasDigits(now->tm_hour, 2);
return ensureHasDigits(now.tm_hour, 2);
}},
{"MINUTE", [](const tag_func_param&) -> std::string {
BLT_NOW();
return ensureHasDigits(now->tm_min, 2);
return ensureHasDigits(now.tm_min, 2);
}},
{"SECOND", [](const tag_func_param&) -> std::string {
BLT_NOW();
return ensureHasDigits(now->tm_sec, 2);
return ensureHasDigits(now.tm_sec, 2);
}},
{"MS", [](const tag_func_param&) -> std::string {
return std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(
@ -674,6 +674,11 @@ namespace blt::logging {
#endif
#if defined(__clang__) || defined(__llvm__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#ifdef BLT_DISABLE_LOGGING
#define BLT_LOG(format, level, ...)
#define BLT_LOG_STREAM(level)
@ -753,4 +758,8 @@ namespace blt::logging {
#endif
#endif
#if defined(__clang__) || defined(__llvm__)
#pragma clang diagnostic pop
#endif
#endif //BLT_TESTS_LOGGING2_H

View File

@ -86,19 +86,21 @@ namespace blt::system
static inline std::string getTimeString()
{
auto t = std::time(nullptr);
auto now = std::localtime(&t);
tm now{};
localtime_s(&now, &t);
//auto now = std::localtime(&t);
std::stringstream timeString;
timeString << (1900 + now->tm_year);
timeString << (1900 + now.tm_year);
timeString << "-";
timeString << (1 + now->tm_mon);
timeString << (1 + now.tm_mon);
timeString << "-";
timeString << now->tm_mday;
timeString << now.tm_mday;
timeString << " ";
timeString << now->tm_hour;
timeString << now.tm_hour;
timeString << ":";
timeString << now->tm_min;
timeString << now.tm_min;
timeString << ":";
timeString << now->tm_sec;
timeString << now.tm_sec;
return timeString.str();
}
@ -110,13 +112,15 @@ namespace blt::system
static inline std::string getTimeStringLog()
{
auto t = std::time(nullptr);
auto now = std::localtime(&t);
tm now{};
localtime_s(&now, &t);
//auto now = std::localtime(&t);
std::string timeString = "[";
timeString += ensureHasDigits(now->tm_hour, 2);
timeString += ensureHasDigits(now.tm_hour, 2);
timeString += ":";
timeString += ensureHasDigits(now->tm_min, 2);
timeString += ensureHasDigits(now.tm_min, 2);
timeString += ":";
timeString += ensureHasDigits(now->tm_sec, 2);
timeString += ensureHasDigits(now.tm_sec, 2);
timeString += "] ";
return timeString;
}
@ -127,19 +131,21 @@ namespace blt::system
static inline std::string getTimeStringFS()
{
auto t = std::time(nullptr);
auto now = std::localtime(&t);
tm now{};
localtime_s(&now, &t);
//auto now = std::localtime(&t);
std::stringstream timeString;
timeString << (1900 + now->tm_year);
timeString << (1900 + now.tm_year);
timeString << "-";
timeString << (1 + now->tm_mon);
timeString << (1 + now.tm_mon);
timeString << "-";
timeString << now->tm_mday;
timeString << now.tm_mday;
timeString << "_";
timeString << now->tm_hour;
timeString << now.tm_hour;
timeString << "-";
timeString << now->tm_min;
timeString << now.tm_min;
timeString << "-";
timeString << now->tm_sec;
timeString << now.tm_sec;
return timeString.str();
}
}

View File

@ -30,7 +30,8 @@
#endif
namespace blt {
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
static inline std::string _macro_filename(const std::string& path){
auto paths = blt::string::split(path, "/");
auto final = paths[paths.size()-1];
@ -38,6 +39,7 @@ namespace blt {
return paths[paths.size()-2];
return final;
}
#endif
void b_throw(const char* what, const char* path, int line)
{
@ -49,6 +51,10 @@ namespace blt {
printStacktrace(messages, size, path, line);
BLT_FREE_STACK_TRACE();
#else
(void) what;
(void) path;
(void) line;
#endif
}
@ -66,6 +72,10 @@ namespace blt {
BLT_FREE_STACK_TRACE();
#endif
(void) expression;
(void) msg;
(void) path;
(void) line;
}
void printStacktrace(char** messages, int size, const char* path, int line)
@ -106,7 +116,12 @@ namespace blt {
BLT_ERROR(buffer);
}
#else
(void) size;
(void) path;
(void) line;
#endif
}