diff --git a/core/bind/logger_bind.cpp b/core/bind/logger_bind.cpp index 5b05b3e53..dc37b6419 100644 --- a/core/bind/logger_bind.cpp +++ b/core/bind/logger_bind.cpp @@ -56,6 +56,10 @@ void _PLogger::log_error(const String &str) { PLogger::log_error(str); } +void _PLogger::log_important(const String &str) { + PLogger::log_important(str); +} + _PLogger::LogLevel _PLogger::get_log_level() { return static_cast(static_cast(PLogger::get_log_level())); } @@ -83,6 +87,7 @@ void _PLogger::_bind_methods() { ClassDB::bind_method(D_METHOD("log_message", "str"), &_PLogger::log_message); ClassDB::bind_method(D_METHOD("log_warning", "str"), &_PLogger::log_warning); ClassDB::bind_method(D_METHOD("log_error", "str"), &_PLogger::log_error); + ClassDB::bind_method(D_METHOD("log_important", "str"), &_PLogger::log_important); ClassDB::bind_method(D_METHOD("get_log_level"), &_PLogger::get_log_level); ClassDB::bind_method(D_METHOD("set_log_level", "log_level"), &_PLogger::set_log_level); @@ -92,6 +97,7 @@ void _PLogger::_bind_methods() { BIND_ENUM_CONSTANT(LOG_LEVEL_MESSAGE); BIND_ENUM_CONSTANT(LOG_LEVEL_WARNING); BIND_ENUM_CONSTANT(LOG_LEVEL_ERROR); + BIND_ENUM_CONSTANT(LOG_LEVEL_IMPORTANT); BIND_ENUM_CONSTANT(LOG_LEVEL_NONE); } diff --git a/core/bind/logger_bind.h b/core/bind/logger_bind.h index a58c762b3..5815b1bbb 100644 --- a/core/bind/logger_bind.h +++ b/core/bind/logger_bind.h @@ -48,6 +48,7 @@ public: LOG_LEVEL_MESSAGE, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR, + LOG_LEVEL_IMPORTANT, LOG_LEVEL_NONE, }; @@ -58,6 +59,7 @@ public: void log_message(const String &str); void log_warning(const String &str); void log_error(const String &str); + void log_important(const String &str); LogLevel get_log_level(); void set_log_level(const LogLevel p_log_level); diff --git a/core/log/logger.cpp b/core/log/logger.cpp index 7830c51ac..4d8f55c49 100644 --- a/core/log/logger.cpp +++ b/core/log/logger.cpp @@ -278,6 +278,67 @@ void PLogger::log_error(const char *p_function, const char *p_file, int p_line, do_log_error(s); } +void PLogger::log_important(const String &str) { + if (_log_level > LOG_LEVEL_IMPORTANT) { + return; + } + + String s; + s += "I "; + s += str; + //s += "\n"; + + do_log_important(s); +} +void PLogger::log_important(const char *str) { + if (_log_level > LOG_LEVEL_IMPORTANT) { + return; + } + + String s; + s += "I "; + s += str; + //s += "\n"; + + do_log_important(s); +} +void PLogger::log_important(const char *p_function, const char *p_file, int p_line, const char *str) { + if (_log_level > LOG_LEVEL_IMPORTANT) { + return; + } + + String s; + s += "I | "; + s += p_file; + s += "::"; + s += p_function; + s += ":"; + s += String::num(p_line); + s += " | "; + s += str; + //s += "\n"; + + do_log_important(s); +} +void PLogger::log_important(const char *p_function, const char *p_file, int p_line, const String &str) { + if (_log_level > LOG_LEVEL_IMPORTANT) { + return; + } + + String s; + s += "I | "; + s += p_file; + s += "::"; + s += p_function; + s += ":"; + s += String::num(p_line); + s += " | "; + s += str; + //s += "\n"; + + do_log_important(s); +} + void PLogger::do_log_trace(const String &str) { if (_backend.is_valid()) { _backend->log_trace(str); @@ -310,6 +371,14 @@ void PLogger::do_log_error(const String &str) { } } +void PLogger::do_log_important(const String &str) { + if (_backend.is_valid()) { + _backend->log_important(str); + } else { + force_print_error(str); + } +} + PLogger::LogLevel PLogger::get_log_level() { return _log_level; } diff --git a/core/log/logger.h b/core/log/logger.h index 494cddf8e..ef24fb796 100644 --- a/core/log/logger.h +++ b/core/log/logger.h @@ -51,6 +51,9 @@ class String; #define PLOG_ERR(str) \ PLogger::log_error(__FUNCTION__, __FILE__, __LINE__, str); +#define PLOG_IMPORTANT(str) \ + PLogger::log_important(__FUNCTION__, __FILE__, __LINE__, str); + class PLogger : public Object { public: enum LogLevel { @@ -58,6 +61,7 @@ public: LOG_LEVEL_MESSAGE, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR, + LOG_LEVEL_IMPORTANT, LOG_LEVEL_NONE, }; @@ -81,10 +85,16 @@ public: static void log_error(const char *p_function, const char *p_file, int p_line, const char *str); static void log_error(const char *p_function, const char *p_file, int p_line, const String &str); + static void log_important(const String &str); + static void log_important(const char *str); + static void log_important(const char *p_function, const char *p_file, int p_line, const char *str); + static void log_important(const char *p_function, const char *p_file, int p_line, const String &str); + static void do_log_trace(const String &str); static void do_log_message(const String &str); static void do_log_warning(const String &str); static void do_log_error(const String &str); + static void do_log_important(const String &str); static LogLevel get_log_level(); static void set_log_level(const LogLevel p_log_level); diff --git a/core/log/logger_backend.cpp b/core/log/logger_backend.cpp index 74f17fb9c..fee4bb57e 100644 --- a/core/log/logger_backend.cpp +++ b/core/log/logger_backend.cpp @@ -45,6 +45,9 @@ void LoggerBackend::log_warning(const String &str) { void LoggerBackend::log_error(const String &str) { call("_log_error", str); } +void LoggerBackend::log_important(const String &str) { + call("_log_important", str); +} void LoggerBackend::_log_trace(const String &str) { print_line(str); @@ -58,6 +61,9 @@ void LoggerBackend::_log_warning(const String &str) { void LoggerBackend::_log_error(const String &str) { print_error(str); } +void LoggerBackend::_log_important(const String &str) { + print_error(str); +} LoggerBackend::LoggerBackend() { } @@ -70,14 +76,17 @@ void LoggerBackend::_bind_methods() { BIND_VMETHOD(MethodInfo("_log_message", PropertyInfo(Variant::STRING, "str"))); BIND_VMETHOD(MethodInfo("_log_warning", PropertyInfo(Variant::STRING, "str"))); BIND_VMETHOD(MethodInfo("_log_error", PropertyInfo(Variant::STRING, "str"))); + BIND_VMETHOD(MethodInfo("_log_important", PropertyInfo(Variant::STRING, "str"))); ClassDB::bind_method(D_METHOD("log_trace", "str"), &LoggerBackend::log_trace); ClassDB::bind_method(D_METHOD("log_message", "str"), &LoggerBackend::log_message); ClassDB::bind_method(D_METHOD("log_warning", "str"), &LoggerBackend::log_warning); ClassDB::bind_method(D_METHOD("log_error", "str"), &LoggerBackend::log_error); + ClassDB::bind_method(D_METHOD("log_important", "str"), &LoggerBackend::log_important); ClassDB::bind_method(D_METHOD("_log_trace", "str"), &LoggerBackend::_log_trace); ClassDB::bind_method(D_METHOD("_log_message", "str"), &LoggerBackend::_log_message); ClassDB::bind_method(D_METHOD("_log_warning", "str"), &LoggerBackend::_log_warning); ClassDB::bind_method(D_METHOD("_log_error", "str"), &LoggerBackend::_log_error); + ClassDB::bind_method(D_METHOD("_log_important", "str"), &LoggerBackend::_log_important); } diff --git a/core/log/logger_backend.h b/core/log/logger_backend.h index c0fb69fa8..7a5eb38e4 100644 --- a/core/log/logger_backend.h +++ b/core/log/logger_backend.h @@ -45,11 +45,13 @@ public: virtual void log_message(const String &str); virtual void log_warning(const String &str); virtual void log_error(const String &str); + virtual void log_important(const String &str); virtual void _log_trace(const String &str); virtual void _log_message(const String &str); virtual void _log_warning(const String &str); virtual void _log_error(const String &str); + virtual void _log_important(const String &str); LoggerBackend(); ~LoggerBackend();