Logger: Cache 'flush_stdout_on_print' to improve performance, and works before ProjectSettings starts.
ProjectSetting: Now 'application/run/flush_stdout_on_print' requires a restart of the Editor to take effect
(cherry picked from commit 89283b7b53
)
This commit is contained in:
parent
279b9f43f3
commit
04fefed904
|
@ -54,6 +54,12 @@ bool Logger::should_log(bool p_err) {
|
|||
return (!p_err || _print_error_enabled) && (p_err || _print_line_enabled);
|
||||
}
|
||||
|
||||
bool Logger::_flush_stdout_on_print = true;
|
||||
|
||||
void Logger::set_flush_stdout_on_print(bool value) {
|
||||
_flush_stdout_on_print = value;
|
||||
}
|
||||
|
||||
void Logger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
|
||||
if (!should_log(true)) {
|
||||
return;
|
||||
|
@ -210,7 +216,7 @@ void RotatedFileLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
|||
Memory::free_static(buf);
|
||||
}
|
||||
|
||||
if (p_err || !ProjectSettings::get_singleton() || GLOBAL_GET("application/run/flush_stdout_on_print")) {
|
||||
if (p_err || _flush_stdout_on_print) {
|
||||
// Don't always flush when printing stdout to avoid performance
|
||||
// issues when `print()` is spammed in release builds.
|
||||
file->flush();
|
||||
|
@ -231,7 +237,7 @@ void StdLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
|||
vfprintf(stderr, p_format, p_list);
|
||||
} else {
|
||||
vprintf(p_format, p_list);
|
||||
if (!ProjectSettings::get_singleton() || GLOBAL_GET("application/run/flush_stdout_on_print")) {
|
||||
if (_flush_stdout_on_print) {
|
||||
// Don't always flush when printing stdout to avoid performance
|
||||
// issues when `print()` is spammed in release builds.
|
||||
fflush(stdout);
|
||||
|
|
|
@ -41,6 +41,8 @@ class Logger {
|
|||
protected:
|
||||
bool should_log(bool p_err);
|
||||
|
||||
static bool _flush_stdout_on_print;
|
||||
|
||||
public:
|
||||
enum ErrorType {
|
||||
ERR_ERROR,
|
||||
|
@ -49,6 +51,8 @@ public:
|
|||
ERR_SHADER
|
||||
};
|
||||
|
||||
static void set_flush_stdout_on_print(bool value);
|
||||
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0 = 0;
|
||||
virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
|
||||
|
||||
|
|
|
@ -252,9 +252,11 @@
|
|||
If [code]true[/code], flushes the standard output stream every time a line is printed. This affects both terminal logging and file logging.
|
||||
When running a project, this setting must be enabled if you want logs to be collected by service managers such as systemd/journalctl. This setting is disabled by default on release builds, since flushing on every printed line will negatively affect performance if lots of lines are printed in a rapid succession. Also, if this setting is enabled, logged files will still be written successfully if the application crashes or is otherwise killed by the user (without being closed "normally").
|
||||
[b]Note:[/b] Regardless of this setting, the standard error stream ([code]stderr[/code]) is always flushed when a line is printed to it.
|
||||
Changes to this setting will only be applied upon restarting the application.
|
||||
</member>
|
||||
<member name="application/run/flush_stdout_on_print.debug" type="bool" setter="" getter="" default="true">
|
||||
Debug build override for [member application/run/flush_stdout_on_print], as performance is less important during debugging.
|
||||
Changes to this setting will only be applied upon restarting the application.
|
||||
</member>
|
||||
<member name="application/run/frame_delay_msec" type="int" setter="" getter="" default="0">
|
||||
Forces a delay between frames in the main loop (in milliseconds). This may be useful if you plan to disable vertical synchronization.
|
||||
|
|
|
@ -980,8 +980,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
|
||||
// Only flush stdout in debug builds by default, as spamming `print()` will
|
||||
// decrease performance if this is enabled.
|
||||
GLOBAL_DEF("application/run/flush_stdout_on_print", false);
|
||||
GLOBAL_DEF("application/run/flush_stdout_on_print.debug", true);
|
||||
GLOBAL_DEF_RST("application/run/flush_stdout_on_print", false);
|
||||
GLOBAL_DEF_RST("application/run/flush_stdout_on_print.debug", true);
|
||||
|
||||
GLOBAL_DEF("logging/file_logging/enable_file_logging", false);
|
||||
// Only file logging by default on desktop platforms as logs can't be
|
||||
|
@ -1029,6 +1029,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
if (quiet_stdout)
|
||||
_print_line_enabled = false;
|
||||
|
||||
Logger::set_flush_stdout_on_print(ProjectSettings::get_singleton()->get("application/run/flush_stdout_on_print"));
|
||||
|
||||
OS::get_singleton()->set_cmdline(execpath, main_args);
|
||||
|
||||
GLOBAL_DEF("rendering/quality/driver/driver_name", "GLES3");
|
||||
|
|
Loading…
Reference in New Issue