mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 03:24:30 +00:00
refactor: shorten log levels and move source locations to the end (#2104)
This commit is contained in:
1 parent
019bcfc0ae
commit
203a882a28
2 files changed
+27
-25
No files matched your search
+18
-21
@@ -91,34 +91,34 @@ void log_print(enum sd_log_level_t level, const char* log, sd_log_level_t min_le
|
|||||||
switch (level) {
|
switch (level) {
|
||||||
case SD_LOG_DEBUG:
|
case SD_LOG_DEBUG:
|
||||||
tag_color = 37;
|
tag_color = 37;
|
||||||
level_str = "DEBUG";
|
level_str = "D";
|
||||||
break;
|
break;
|
||||||
case SD_LOG_VERBOSE:
|
case SD_LOG_VERBOSE:
|
||||||
tag_color = 37;
|
tag_color = 37;
|
||||||
level_str = "VERBOSE";
|
level_str = "V";
|
||||||
break;
|
break;
|
||||||
case SD_LOG_INFO:
|
case SD_LOG_INFO:
|
||||||
tag_color = 34;
|
tag_color = 34;
|
||||||
level_str = "INFO";
|
level_str = "I";
|
||||||
break;
|
break;
|
||||||
case SD_LOG_WARN:
|
case SD_LOG_WARN:
|
||||||
tag_color = 35;
|
tag_color = 35;
|
||||||
level_str = "WARN";
|
level_str = "W";
|
||||||
break;
|
break;
|
||||||
case SD_LOG_ERROR:
|
case SD_LOG_ERROR:
|
||||||
tag_color = 31;
|
tag_color = 31;
|
||||||
level_str = "ERROR";
|
level_str = "E";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
tag_color = 33;
|
tag_color = 33;
|
||||||
level_str = "?????";
|
level_str = "?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color) {
|
if (color) {
|
||||||
fprintf(out_stream, "\033[%d;1m[%-7s]\033[0m ", tag_color, level_str);
|
fprintf(out_stream, "\033[%d;1m[%s]\033[0m ", tag_color, level_str);
|
||||||
} else {
|
} else {
|
||||||
fprintf(out_stream, "[%-7s] ", level_str);
|
fprintf(out_stream, "[%s] ", level_str);
|
||||||
}
|
}
|
||||||
fflush(out_stream);
|
fflush(out_stream);
|
||||||
print_utf8(out_stream, log);
|
print_utf8(out_stream, log);
|
||||||
@@ -131,18 +131,15 @@ void example_log_printf(sd_log_level_t level, const char* file, int line, const
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
static char log_buffer[LOG_BUFFER_SIZE + 1];
|
char log_buffer[LOG_BUFFER_SIZE + 1] = {};
|
||||||
int written = snprintf(log_buffer, LOG_BUFFER_SIZE, "%s:%-4d - ", sd_basename(file).c_str(), line);
|
vsnprintf(log_buffer, sizeof(log_buffer), format, args);
|
||||||
|
|
||||||
if (written >= 0 && written < static_cast<int>(LOG_BUFFER_SIZE)) {
|
|
||||||
vsnprintf(log_buffer + written, LOG_BUFFER_SIZE - written, format, args);
|
|
||||||
}
|
|
||||||
size_t len = strlen(log_buffer);
|
|
||||||
if (len == 0 || log_buffer[len - 1] != '\n') {
|
|
||||||
strncat(log_buffer, "\n", LOG_BUFFER_SIZE - len);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_print(level, log_buffer, log_level, log_color);
|
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
|
std::string message = log_buffer;
|
||||||
|
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
|
||||||
|
message.pop_back();
|
||||||
|
}
|
||||||
|
message += " - " + sd_basename(file) + ":" + std::to_string(line) + '\n';
|
||||||
|
|
||||||
|
log_print(level, message.c_str(), log_level, log_color);
|
||||||
}
|
}
|
||||||
+9
-4
@@ -644,9 +644,14 @@ void* sd_log_cb_data = nullptr;
|
|||||||
static void sd_log_dispatch(sd_log_level_t level, const std::string& origin, const std::string& text) {
|
static void sd_log_dispatch(sd_log_level_t level, const std::string& origin, const std::string& text) {
|
||||||
if (sd_log_cb == nullptr)
|
if (sd_log_cb == nullptr)
|
||||||
return;
|
return;
|
||||||
std::string message = origin + " - " + text;
|
std::string message = text;
|
||||||
if (message.back() != '\n') {
|
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
|
||||||
message += '\n';
|
message.pop_back();
|
||||||
|
}
|
||||||
|
if (origin == "ggml") {
|
||||||
|
message = origin + ": " + message + '\n';
|
||||||
|
} else {
|
||||||
|
message += " - " + origin + '\n';
|
||||||
}
|
}
|
||||||
sd_log_cb(level, message.c_str(), sd_log_cb_data);
|
sd_log_cb(level, message.c_str(), sd_log_cb_data);
|
||||||
}
|
}
|
||||||
@@ -656,7 +661,7 @@ void log_printf(sd_log_level_t level, const char* file, int line, const char* fo
|
|||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
std::string message = sd_vformat(format, args);
|
std::string message = sd_vformat(format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
std::string origin = sd_format("%s:%-4d", sd_basename(file).c_str(), line);
|
std::string origin = sd_format("%s:%d", sd_basename(file).c_str(), line);
|
||||||
sd_log_dispatch(level, origin, message);
|
sd_log_dispatch(level, origin, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user