Skip to content

Commit 8574bec

Browse files
committed
Reduce log spam during headless import/export
1 parent b1792e5 commit 8574bec

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

editor/editor_node.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,6 +5356,11 @@ bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringNa
53565356
// Used to track the progress of tasks in the CLI output (since we don't have any other frame of reference).
53575357
static HashMap<String, int> progress_total_steps;
53585358

5359+
static String last_progress_task;
5360+
static String last_progress_state;
5361+
static int last_progress_step = 0;
5362+
static double last_progress_time = 0;
5363+
53595364
void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
53605365
if (!singleton) {
53615366
return;
@@ -5371,8 +5376,18 @@ bool EditorNode::progress_task_step(const String &p_task, const String &p_state,
53715376
if (!singleton) {
53725377
return false;
53735378
} else if (singleton->cmdline_mode) {
5374-
const int percent = (p_step / float(progress_total_steps[p_task] + 1)) * 100;
5375-
print_line_rich(vformat("[%4d%% ] [color=gray][b]%s[/b] | %s[/color]", percent, p_task, p_state));
5379+
double current_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec());
5380+
double elapsed_time = current_time - last_progress_time;
5381+
if (p_task != last_progress_task || p_state != last_progress_state || p_step != last_progress_step || elapsed_time >= 1.0) {
5382+
// Only print the progress if it's changed since the last print, or if one second has passed.
5383+
// This prevents multithreaded import from printing the same progress too often, which would bloat the log file.
5384+
const int percent = (p_step / float(progress_total_steps[p_task] + 1)) * 100;
5385+
print_line_rich(vformat("[%4d%% ] [color=gray][b]%s[/b] | %s[/color]", percent, p_task, p_state));
5386+
last_progress_task = p_task;
5387+
last_progress_state = p_state;
5388+
last_progress_step = p_step;
5389+
last_progress_time = current_time;
5390+
}
53765391
return false;
53775392
} else if (singleton->progress_dialog) {
53785393
return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);

0 commit comments

Comments
 (0)