From 6334895088947eb318c8df15d0a68db27819a06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 5 Nov 2015 20:13:05 +0100 Subject: [PATCH 1/2] Display error type (error, warning, script error) in OS::print_error Previously all types of errors would be shown as ERROR, thus making for example warnings (WARN_PRINT) somewhat aggressive. ERROR is displayed in red, WARNING in yellow and SCRIPT ERROR in magenta (though the latter does not seem used so far). Fixes #1127. --- core/os/os.cpp | 11 +++++++++-- drivers/unix/os_unix.cpp | 26 ++++++++++++++++++-------- platform/windows/os_windows.cpp | 25 ++++++++++++++++++------- platform/winrt/os_winrt.cpp | 26 ++++++++++++++++++-------- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/core/os/os.cpp b/core/os/os.cpp index ee9f12b79d7..8caf95e4d1b 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -61,9 +61,16 @@ void OS::debug_break() { void OS::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) { + const char* err_type; + switch(p_type) { + case ERR_ERROR: err_type="**ERROR**"; break; + case ERR_WARNING: err_type="**WARNING**"; break; + case ERR_SCRIPT: err_type="**SCRIPT ERROR**"; break; + } + if (p_rationale && *p_rationale) - print("**ERROR**: %s\n ",p_rationale); - print("**ERROR**: At: %s:%i:%s() - %s\n",p_file,p_line,p_function,p_code); + print("%s: %s\n ",err_type,p_rationale); + print("%s: At: %s:%i:%s() - %s\n",err_type,p_file,p_line,p_function,p_code); } void OS::print(const char* p_format, ...) { diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 8617061ad47..194802fcb89 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -65,15 +65,25 @@ void OS_Unix::print_error(const char* p_function,const char* p_file,int p_line,c if (!_print_error_enabled) return; - if (p_rationale && p_rationale[0]) { - - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); - - } else { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + const char* err_details; + if (p_rationale && p_rationale[0]) + err_details=p_rationale; + else + err_details=p_code; + switch(p_type) { + case ERR_ERROR: + print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_WARNING: + print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_SCRIPT: + print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; } } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 438a5a69037..01a82615637 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1768,15 +1768,26 @@ void OS_Windows::print_error(const char* p_function,const char* p_file,int p_lin HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); if (!hCon || hCon==INVALID_HANDLE_VALUE) { - if (p_rationale && p_rationale[0]) { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); - - } else { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + const char* err_details; + if (p_rationale && p_rationale[0]) + err_details=p_rationale; + else + err_details=p_code; + switch(p_type) { + case ERR_ERROR: + print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_WARNING: + print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_SCRIPT: + print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; } } else { diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp index 3e06d9d59b9..1e060a36679 100644 --- a/platform/winrt/os_winrt.cpp +++ b/platform/winrt/os_winrt.cpp @@ -424,15 +424,25 @@ void OSWinrt::get_fullscreen_mode_list(List *p_list,int p_screen) con void OSWinrt::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) { - if (p_rationale && p_rationale[0]) { - - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); - - } else { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + const char* err_details; + if (p_rationale && p_rationale[0]) + err_details=p_rationale; + else + err_details=p_code; + switch(p_type) { + case ERR_ERROR: + print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_WARNING: + print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; + case ERR_SCRIPT: + print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); + print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + break; } } From 9ab7de243fe0348c46a87c03b1fce15b8e1afeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 10 Nov 2015 08:04:48 +0100 Subject: [PATCH 2/2] Fix error messages forcing a white font for subsequent messages This is achieved using the "no specific formatting" \E[0m tag. Fixes #2566. Also remove the hardcoded black background colour and use default bolded terminal font for error message. Error logs should now look good both on terminals with a dark and light background colour. --- drivers/unix/os_unix.cpp | 12 ++++++------ platform/windows/os_windows.cpp | 12 ++++++------ platform/winrt/os_winrt.cpp | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 194802fcb89..fd8c26f6d9a 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -73,16 +73,16 @@ void OS_Unix::print_error(const char* p_function,const char* p_file,int p_line,c switch(p_type) { case ERR_ERROR: - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;31m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_WARNING: - print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;33m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_SCRIPT: - print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;35m At: %s:%i.\E[0m\n",p_file,p_line); break; } } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 01a82615637..964b9e76f36 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1777,16 +1777,16 @@ void OS_Windows::print_error(const char* p_function,const char* p_file,int p_lin switch(p_type) { case ERR_ERROR: - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;31m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_WARNING: - print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;33m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_SCRIPT: - print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m",p_function,err_details); + print("\E[0;35m At: %s:%i.\E[0m\n",p_file,p_line); break; } } else { diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp index 1e060a36679..51f60a03624 100644 --- a/platform/winrt/os_winrt.cpp +++ b/platform/winrt/os_winrt.cpp @@ -432,16 +432,16 @@ void OSWinrt::print_error(const char* p_function,const char* p_file,int p_line,c switch(p_type) { case ERR_ERROR: - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;31m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_WARNING: - print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details); + print("\E[0;33m At: %s:%i.\E[0m\n",p_file,p_line); break; case ERR_SCRIPT: - print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details); - print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m",p_function,err_details); + print("\E[0;35m At: %s:%i.\E[0m\n",p_file,p_line); break; } }