Skip to content

Commit c3ad6a1

Browse files
authored
refactor: optimize the printing of version log (#1102)
1 parent ebe9d26 commit c3ad6a1

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

examples/cli/main.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct SDCliParams {
3131
std::string output_path = "output.png";
3232

3333
bool verbose = false;
34-
bool version = false;
3534
bool canny_preprocess = false;
3635

3736
preview_t preview_method = PREVIEW_NONE;
@@ -74,10 +73,6 @@ struct SDCliParams {
7473
"--verbose",
7574
"print extra info",
7675
true, &verbose},
77-
{"",
78-
"--version",
79-
"print stable-diffusion.cpp version",
80-
true, &version},
8176
{"",
8277
"--color",
8378
"colors the logging tags according to level",
@@ -354,9 +349,6 @@ int main(int argc, const char* argv[]) {
354349
SDGenerationParams gen_params;
355350

356351
parse_args(argc, argv, cli_params, ctx_params, gen_params);
357-
if (cli_params.verbose || cli_params.version) {
358-
std::cout << version_string() << "\n";
359-
}
360352
if (gen_params.video_frames > 4) {
361353
size_t last_dot_pos = cli_params.preview_path.find_last_of(".");
362354
std::string base_path = cli_params.preview_path;
@@ -384,12 +376,11 @@ int main(int argc, const char* argv[]) {
384376
cli_params.preview_noisy,
385377
(void*)&cli_params);
386378

387-
if (cli_params.verbose) {
388-
LOG_INFO("%s", sd_get_system_info());
389-
LOG_INFO("%s", cli_params.to_string().c_str());
390-
LOG_INFO("%s", ctx_params.to_string().c_str());
391-
LOG_INFO("%s", gen_params.to_string().c_str());
392-
}
379+
LOG_DEBUG("version: %s", version_string().c_str());
380+
LOG_DEBUG("%s", sd_get_system_info());
381+
LOG_DEBUG("%s", cli_params.to_string().c_str());
382+
LOG_DEBUG("%s", ctx_params.to_string().c_str());
383+
LOG_DEBUG("%s", gen_params.to_string().c_str());
393384

394385
if (cli_params.mode == CONVERT) {
395386
bool success = convert(ctx_params.model_path.c_str(),

examples/server/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ void sd_log_cb(enum sd_log_level_t level, const char* log, void* data) {
262262
}
263263

264264
int main(int argc, const char** argv) {
265+
if (argc > 1 && std::string(argv[1]) == "--version") {
266+
std::cout << version_string() << "\n";
267+
return EXIT_SUCCESS;
268+
}
265269
SDSvrParams svr_params;
266270
SDContextParams ctx_params;
267271
SDGenerationParams default_gen_params;
@@ -271,12 +275,11 @@ int main(int argc, const char** argv) {
271275
log_verbose = svr_params.verbose;
272276
log_color = svr_params.color;
273277

274-
if (svr_params.verbose) {
275-
LOG_INFO("%s", sd_get_system_info());
276-
LOG_INFO("%s", svr_params.to_string().c_str());
277-
LOG_INFO("%s", ctx_params.to_string().c_str());
278-
LOG_INFO("%s", default_gen_params.to_string().c_str());
279-
}
278+
LOG_DEBUG("version: %s", version_string().c_str());
279+
LOG_DEBUG("%s", sd_get_system_info());
280+
LOG_DEBUG("%s", svr_params.to_string().c_str());
281+
LOG_DEBUG("%s", ctx_params.to_string().c_str());
282+
LOG_DEBUG("%s", default_gen_params.to_string().c_str());
280283

281284
sd_ctx_params_t sd_ctx_params = ctx_params.to_sd_ctx_params_t(false, false, false);
282285
sd_ctx_t* sd_ctx = new_sd_ctx(&sd_ctx_params);

0 commit comments

Comments
 (0)