Enable file logging by default on desktops to help with troubleshooting

- Use the `.log` file extension (recognized on Windows out of the box)
  to better hint that generated files are logs. Some editors provide
  dedicated syntax highlighting for those files.
- Use an underscore to separate the basename from the date and
  the date from the time in log filenames. This makes the filename
  easier to read.
- Keep only 5 log files by default to decrease disk usage in case
  messages are spammed.

(cherry picked from commit 20af28ec06)
This commit is contained in:
Hugo Locurcio 2020-07-04 16:59:49 +02:00 committed by Rémi Verschelde
parent a0f0aa1741
commit c2a4ce9380
3 changed files with 12 additions and 5 deletions

View File

@ -154,7 +154,7 @@ void RotatedFileLogger::rotate_file() {
char timestamp[21]; char timestamp[21];
OS::Date date = OS::get_singleton()->get_date(); OS::Date date = OS::get_singleton()->get_date();
OS::Time time = OS::get_singleton()->get_time(); OS::Time time = OS::get_singleton()->get_time();
sprintf(timestamp, "-%04d-%02d-%02d-%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec); sprintf(timestamp, "_%04d-%02d-%02d_%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
String backup_name = base_path.get_basename() + timestamp; String backup_name = base_path.get_basename() + timestamp;
if (base_path.get_extension() != String()) { if (base_path.get_extension() != String()) {

View File

@ -812,10 +812,12 @@
<member name="logging/file_logging/enable_file_logging" type="bool" setter="" getter="" default="false"> <member name="logging/file_logging/enable_file_logging" type="bool" setter="" getter="" default="false">
If [code]true[/code], logs all output to files. If [code]true[/code], logs all output to files.
</member> </member>
<member name="logging/file_logging/log_path" type="String" setter="" getter="" default="&quot;user://logs/log.txt&quot;"> <member name="logging/file_logging/enable_file_logging.pc" type="bool" setter="" getter="" default="true">
</member>
<member name="logging/file_logging/log_path" type="String" setter="" getter="" default="&quot;user://logs/godot.log&quot;">
Path to logs within the project. Using an [code]user://[/code] path is recommended. Path to logs within the project. Using an [code]user://[/code] path is recommended.
</member> </member>
<member name="logging/file_logging/max_log_files" type="int" setter="" getter="" default="10"> <member name="logging/file_logging/max_log_files" type="int" setter="" getter="" default="5">
Specifies the maximum amount of log files allowed (used for rotation). Specifies the maximum amount of log files allowed (used for rotation).
</member> </member>
<member name="memory/limits/message_queue/max_size_kb" type="int" setter="" getter="" default="1024"> <member name="memory/limits/message_queue/max_size_kb" type="int" setter="" getter="" default="1024">

View File

@ -955,8 +955,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
#endif #endif
GLOBAL_DEF("logging/file_logging/enable_file_logging", false); GLOBAL_DEF("logging/file_logging/enable_file_logging", false);
GLOBAL_DEF("logging/file_logging/log_path", "user://logs/log.txt"); // Only file logging by default on desktop platforms as logs can't be
GLOBAL_DEF("logging/file_logging/max_log_files", 10); // accessed easily on mobile/Web platforms (if at all).
// This also prevents logs from being created for the editor instance, as feature tags
// are disabled while in the editor (even if they should logically apply).
GLOBAL_DEF("logging/file_logging/enable_file_logging.pc", true);
GLOBAL_DEF("logging/file_logging/log_path", "user://logs/godot.log");
GLOBAL_DEF("logging/file_logging/max_log_files", 5);
ProjectSettings::get_singleton()->set_custom_property_info("logging/file_logging/max_log_files", PropertyInfo(Variant::INT, "logging/file_logging/max_log_files", PROPERTY_HINT_RANGE, "0,20,1,or_greater")); //no negative numbers ProjectSettings::get_singleton()->set_custom_property_info("logging/file_logging/max_log_files", PropertyInfo(Variant::INT, "logging/file_logging/max_log_files", PROPERTY_HINT_RANGE, "0,20,1,or_greater")); //no negative numbers
if (FileAccess::get_create_func(FileAccess::ACCESS_USERDATA) && GLOBAL_GET("logging/file_logging/enable_file_logging")) { if (FileAccess::get_create_func(FileAccess::ACCESS_USERDATA) && GLOBAL_GET("logging/file_logging/enable_file_logging")) {
String base_path = GLOBAL_GET("logging/file_logging/log_path"); String base_path = GLOBAL_GET("logging/file_logging/log_path");