mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-04-22 11:21:18 +02:00
commit
11cf843157
@ -56,6 +56,14 @@ void _PLogger::log_error(const String &str) {
|
||||
PLogger::log_error(str);
|
||||
}
|
||||
|
||||
void _PLogger::log_important(const String &str) {
|
||||
PLogger::log_important(str);
|
||||
}
|
||||
|
||||
void _PLogger::log_custom(const StringName &p_category, const int p_level, const String &str) {
|
||||
PLogger::log_custom(p_category, p_level, str);
|
||||
}
|
||||
|
||||
_PLogger::LogLevel _PLogger::get_log_level() {
|
||||
return static_cast<LogLevel>(static_cast<int>(PLogger::get_log_level()));
|
||||
}
|
||||
@ -83,6 +91,8 @@ 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("log_custom", "category", "level", "str"), &_PLogger::log_custom);
|
||||
|
||||
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 +102,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);
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
LOG_LEVEL_MESSAGE,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_IMPORTANT,
|
||||
LOG_LEVEL_NONE,
|
||||
};
|
||||
|
||||
@ -58,6 +59,8 @@ 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);
|
||||
void log_custom(const StringName &p_category, const int p_level, const String &str);
|
||||
|
||||
LogLevel get_log_level();
|
||||
void set_log_level(const LogLevel p_log_level);
|
||||
|
@ -62,8 +62,8 @@ 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)) {
|
||||
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, bool p_force) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -98,27 +98,19 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c
|
||||
}
|
||||
|
||||
void Logger::logf(const char *p_format, ...) {
|
||||
if (!should_log(false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list argp;
|
||||
va_start(argp, p_format);
|
||||
|
||||
logv(p_format, argp, false);
|
||||
logv(p_format, argp, false, false);
|
||||
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
void Logger::logf_error(const char *p_format, ...) {
|
||||
if (!should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list argp;
|
||||
va_start(argp, p_format);
|
||||
|
||||
logv(p_format, argp, true);
|
||||
logv(p_format, argp, true, false);
|
||||
|
||||
va_end(argp);
|
||||
}
|
||||
@ -202,8 +194,8 @@ RotatedFileLogger::RotatedFileLogger(const String &p_base_path, int p_max_files)
|
||||
rotate_file();
|
||||
}
|
||||
|
||||
void RotatedFileLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
if (!should_log(p_err)) {
|
||||
void RotatedFileLogger::logv(const char *p_format, va_list p_list, bool p_err, bool p_force) {
|
||||
if (!p_force && !should_log(p_err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -237,8 +229,8 @@ RotatedFileLogger::~RotatedFileLogger() {
|
||||
close_file();
|
||||
}
|
||||
|
||||
void StdLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
if (!should_log(p_err)) {
|
||||
void StdLogger::logv(const char *p_format, va_list p_list, bool p_err, bool p_force) {
|
||||
if (!p_force && !should_log(p_err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -260,26 +252,26 @@ CompositeLogger::CompositeLogger(Vector<Logger *> p_loggers) :
|
||||
loggers(p_loggers) {
|
||||
}
|
||||
|
||||
void CompositeLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
if (!should_log(p_err)) {
|
||||
void CompositeLogger::logv(const char *p_format, va_list p_list, bool p_err, bool p_force) {
|
||||
if (!p_force && !should_log(p_err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < loggers.size(); ++i) {
|
||||
va_list list_copy;
|
||||
va_copy(list_copy, p_list);
|
||||
loggers[i]->logv(p_format, list_copy, p_err);
|
||||
loggers[i]->logv(p_format, list_copy, p_err, p_force);
|
||||
va_end(list_copy);
|
||||
}
|
||||
}
|
||||
|
||||
void CompositeLogger::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)) {
|
||||
void CompositeLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type, bool p_force) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < loggers.size(); ++i) {
|
||||
loggers[i]->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
|
||||
loggers[i]->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type, p_force);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ public:
|
||||
|
||||
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);
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) _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, bool p_force = false);
|
||||
|
||||
void logf(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
void logf_error(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
@ -68,7 +68,7 @@ public:
|
||||
*/
|
||||
class StdLogger : public Logger {
|
||||
public:
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
virtual ~StdLogger();
|
||||
};
|
||||
|
||||
@ -91,7 +91,7 @@ class RotatedFileLogger : public Logger {
|
||||
public:
|
||||
RotatedFileLogger(const String &p_base_path, int p_max_files = 10);
|
||||
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
|
||||
virtual ~RotatedFileLogger();
|
||||
};
|
||||
@ -102,8 +102,8 @@ class CompositeLogger : public Logger {
|
||||
public:
|
||||
CompositeLogger(Vector<Logger *> p_loggers);
|
||||
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_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);
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) _PRINTF_FORMAT_ATTRIBUTE_2_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, bool p_force = false);
|
||||
|
||||
void add_logger(Logger *p_logger);
|
||||
|
||||
|
@ -42,7 +42,6 @@ void PLogger::log_trace(const String &str) {
|
||||
String s;
|
||||
s += "T ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_trace(s);
|
||||
}
|
||||
@ -54,7 +53,6 @@ void PLogger::log_trace(const char *str) {
|
||||
String s;
|
||||
s += "T ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_trace(s);
|
||||
}
|
||||
@ -72,7 +70,6 @@ void PLogger::log_trace(const char *p_function, const char *p_file, int p_line,
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_trace(s);
|
||||
}
|
||||
@ -90,7 +87,6 @@ void PLogger::log_trace(const char *p_function, const char *p_file, int p_line,
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_trace(s);
|
||||
}
|
||||
@ -103,7 +99,6 @@ void PLogger::log_message(const String &str) {
|
||||
String s;
|
||||
s += "M ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_message(s);
|
||||
}
|
||||
@ -115,7 +110,6 @@ void PLogger::log_message(const char *str) {
|
||||
String s;
|
||||
s += "M ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_message(s);
|
||||
}
|
||||
@ -133,7 +127,6 @@ void PLogger::log_message(const char *p_function, const char *p_file, int p_line
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_message(s);
|
||||
}
|
||||
@ -151,7 +144,6 @@ void PLogger::log_message(const char *p_function, const char *p_file, int p_line
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_message(s);
|
||||
}
|
||||
@ -164,7 +156,6 @@ void PLogger::log_warning(const String &str) {
|
||||
String s;
|
||||
s += "W ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_warning(s);
|
||||
}
|
||||
@ -176,7 +167,6 @@ void PLogger::log_warning(const char *str) {
|
||||
String s;
|
||||
s += "W ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_warning(s);
|
||||
}
|
||||
@ -194,7 +184,6 @@ void PLogger::log_warning(const char *p_function, const char *p_file, int p_line
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_warning(s);
|
||||
}
|
||||
@ -212,7 +201,6 @@ void PLogger::log_warning(const char *p_function, const char *p_file, int p_line
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_warning(s);
|
||||
}
|
||||
@ -225,7 +213,6 @@ void PLogger::log_error(const String &str) {
|
||||
String s;
|
||||
s += "E ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_error(s);
|
||||
}
|
||||
@ -237,7 +224,6 @@ void PLogger::log_error(const char *str) {
|
||||
String s;
|
||||
s += "E ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_error(s);
|
||||
}
|
||||
@ -255,7 +241,6 @@ void PLogger::log_error(const char *p_function, const char *p_file, int p_line,
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_error(s);
|
||||
}
|
||||
@ -273,16 +258,197 @@ void PLogger::log_error(const char *p_function, const char *p_file, int p_line,
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
//s += "\n";
|
||||
|
||||
do_log_error(s);
|
||||
}
|
||||
|
||||
void PLogger::log_important(const String &str) {
|
||||
if (_log_level > LOG_LEVEL_IMPORTANT) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += "I ";
|
||||
s += str;
|
||||
|
||||
do_log_important(s);
|
||||
}
|
||||
void PLogger::log_important(const char *str) {
|
||||
if (_log_level > LOG_LEVEL_IMPORTANT) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += "I ";
|
||||
s += str;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
do_log_important(s);
|
||||
}
|
||||
|
||||
void PLogger::log_custom(const StringName &p_category, const int p_level, const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_custom(p_category, p_level, str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_log_level > p_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += p_category;
|
||||
s += " : ";
|
||||
s += String::num(p_level);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
if (p_level < LOG_LEVEL_ERROR) {
|
||||
force_print_line(s);
|
||||
} else {
|
||||
force_print_error(s);
|
||||
}
|
||||
}
|
||||
void PLogger::log_custom(const StringName &p_category, const int p_level, const char *str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_custom(p_category, p_level, str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_log_level > p_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += p_category;
|
||||
s += " : ";
|
||||
s += String::num(p_level);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
if (p_level < LOG_LEVEL_ERROR) {
|
||||
force_print_line(s);
|
||||
} else {
|
||||
force_print_error(s);
|
||||
}
|
||||
}
|
||||
void PLogger::log_custom(const StringName &p_category, const int p_level, const char *p_function, const char *p_file, int p_line, const char *str) {
|
||||
if (_backend.is_valid()) {
|
||||
|
||||
String s;
|
||||
s += p_file;
|
||||
s += "::";
|
||||
s += p_function;
|
||||
s += ":";
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
_backend->log_custom(p_category, p_level, s);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_log_level > p_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += p_category;
|
||||
s += " : ";
|
||||
s += String::num(p_level);
|
||||
s += " | ";
|
||||
s += p_file;
|
||||
s += "::";
|
||||
s += p_function;
|
||||
s += ":";
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
if (p_level < LOG_LEVEL_ERROR) {
|
||||
force_print_line(s);
|
||||
} else {
|
||||
force_print_error(s);
|
||||
}
|
||||
}
|
||||
void PLogger::log_custom(const StringName &p_category, const int p_level, const char *p_function, const char *p_file, int p_line, const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
|
||||
String s;
|
||||
s += p_file;
|
||||
s += "::";
|
||||
s += p_function;
|
||||
s += ":";
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
_backend->log_custom(p_category, p_level, s);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_log_level > p_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s;
|
||||
s += p_category;
|
||||
s += " : ";
|
||||
s += String::num(p_level);
|
||||
s += " | ";
|
||||
s += p_file;
|
||||
s += "::";
|
||||
s += p_function;
|
||||
s += ":";
|
||||
s += String::num(p_line);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
if (p_level < LOG_LEVEL_ERROR) {
|
||||
force_print_line(s);
|
||||
} else {
|
||||
force_print_error(s);
|
||||
}
|
||||
}
|
||||
|
||||
void PLogger::do_log_trace(const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_trace(str);
|
||||
} else {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +456,7 @@ void PLogger::do_log_message(const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_message(str);
|
||||
} else {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,7 +464,7 @@ void PLogger::do_log_warning(const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_warning(str);
|
||||
} else {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,8 +472,15 @@ void PLogger::do_log_error(const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_error(str);
|
||||
} else {
|
||||
ERR_PRINT(str);
|
||||
//print_error(str);
|
||||
force_print_error(str);
|
||||
}
|
||||
}
|
||||
|
||||
void PLogger::do_log_important(const String &str) {
|
||||
if (_backend.is_valid()) {
|
||||
_backend->log_important(str);
|
||||
} else {
|
||||
force_print_error(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,12 @@ class String;
|
||||
#define PLOG_ERR(str) \
|
||||
PLogger::log_error(__FUNCTION__, __FILE__, __LINE__, str);
|
||||
|
||||
#define PLOG_IMPORTANT(str) \
|
||||
PLogger::log_important(__FUNCTION__, __FILE__, __LINE__, str);
|
||||
|
||||
#define PLOG_CUSTOM(category, level, str) \
|
||||
PLogger::log_custom(category, level, __FUNCTION__, __FILE__, __LINE__, str);
|
||||
|
||||
class PLogger : public Object {
|
||||
public:
|
||||
enum LogLevel {
|
||||
@ -58,6 +64,7 @@ public:
|
||||
LOG_LEVEL_MESSAGE,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_IMPORTANT,
|
||||
LOG_LEVEL_NONE,
|
||||
};
|
||||
|
||||
@ -81,10 +88,21 @@ 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 log_custom(const StringName &p_category, const int p_level, const String &p_str);
|
||||
static void log_custom(const StringName &p_category, const int p_level, const char *str);
|
||||
static void log_custom(const StringName &p_category, const int p_level, const char *p_function, const char *p_file, int p_line, const char *str);
|
||||
static void log_custom(const StringName &p_category, const int p_level, 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);
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include "logger_backend.h"
|
||||
|
||||
#include "core/io/logger.h"
|
||||
#include "core/log/logger.h"
|
||||
#include "core/string/print_string.h"
|
||||
|
||||
void LoggerBackend::log_trace(const String &str) {
|
||||
@ -45,18 +47,41 @@ 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_custom(const StringName &p_category, const int p_level, const String &str) {
|
||||
call("_log_custom", p_category, p_level, str);
|
||||
}
|
||||
|
||||
void LoggerBackend::_log_trace(const String &str) {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
void LoggerBackend::_log_message(const String &str) {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
void LoggerBackend::_log_warning(const String &str) {
|
||||
print_line(str);
|
||||
force_print_line(str);
|
||||
}
|
||||
void LoggerBackend::_log_error(const String &str) {
|
||||
print_error(str);
|
||||
force_print_error(str);
|
||||
}
|
||||
void LoggerBackend::_log_important(const String &str) {
|
||||
force_print_error(str);
|
||||
}
|
||||
void LoggerBackend::_log_custom(const StringName &p_category, const int p_level, const String &str) {
|
||||
String s;
|
||||
s += p_category;
|
||||
s += " : ";
|
||||
s += String::num(p_level);
|
||||
s += " | ";
|
||||
s += str;
|
||||
|
||||
if (p_level < PLogger::LOG_LEVEL_ERROR) {
|
||||
force_print_line(s);
|
||||
} else {
|
||||
force_print_error(s);
|
||||
}
|
||||
}
|
||||
|
||||
LoggerBackend::LoggerBackend() {
|
||||
@ -70,14 +95,23 @@ 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")));
|
||||
BIND_VMETHOD(MethodInfo("_log_custom",
|
||||
PropertyInfo(Variant::STRING_NAME, "category"),
|
||||
PropertyInfo(Variant::INT, "level"),
|
||||
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_custom", "category", "level", "str"), &LoggerBackend::log_custom);
|
||||
|
||||
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_custom", "category", "level", "str"), &LoggerBackend::log_custom);
|
||||
}
|
||||
|
@ -45,11 +45,15 @@ 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_custom(const StringName &p_category, const int p_level, 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);
|
||||
virtual void _log_custom(const StringName &p_category, const int p_level, const String &str);
|
||||
|
||||
LoggerBackend();
|
||||
~LoggerBackend();
|
||||
|
@ -246,6 +246,28 @@ void OS::printerr(const char *p_format, ...) {
|
||||
va_end(argp);
|
||||
};
|
||||
|
||||
void OS::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) {
|
||||
_logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type, true);
|
||||
}
|
||||
|
||||
void OS::log(const char *p_format, ...) {
|
||||
va_list argp;
|
||||
va_start(argp, p_format);
|
||||
|
||||
_logger->logv(p_format, argp, false, true);
|
||||
|
||||
va_end(argp);
|
||||
};
|
||||
|
||||
void OS::logerr(const char *p_format, ...) {
|
||||
va_list argp;
|
||||
va_start(argp, p_format);
|
||||
|
||||
_logger->logv(p_format, argp, true, true);
|
||||
|
||||
va_end(argp);
|
||||
};
|
||||
|
||||
void OS::set_keep_screen_on(bool p_enabled) {
|
||||
_keep_screen_on = p_enabled;
|
||||
}
|
||||
|
@ -186,10 +186,16 @@ public:
|
||||
virtual void global_menu_remove_item(const String &p_menu, int p_idx) {};
|
||||
virtual void global_menu_clear(const String &p_menu) {};
|
||||
|
||||
// Depens on settings if logged / printed
|
||||
void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR);
|
||||
void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
|
||||
// Will always get logged / printed
|
||||
void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR);
|
||||
void log(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
void logerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||
|
||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
|
||||
virtual String get_stdin_string() = 0;
|
||||
|
||||
|
@ -78,6 +78,7 @@ void print_line(String p_string) {
|
||||
OS::get_singleton()->print("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
||||
PrintHandlerList *l = print_handler_list;
|
||||
while (l) {
|
||||
l->printfunc(l->userdata, p_string, false);
|
||||
@ -95,6 +96,7 @@ void print_error(String p_string) {
|
||||
OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
||||
PrintHandlerList *l = print_handler_list;
|
||||
while (l) {
|
||||
l->printfunc(l->userdata, p_string, true);
|
||||
@ -109,3 +111,32 @@ void print_verbose(String p_string) {
|
||||
print_line(p_string);
|
||||
}
|
||||
}
|
||||
|
||||
void force_print_line(String p_string) {
|
||||
OS::get_singleton()->log("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
||||
PrintHandlerList *l = print_handler_list;
|
||||
while (l) {
|
||||
l->printfunc(l->userdata, p_string, false);
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
_global_unlock();
|
||||
}
|
||||
|
||||
void force_print_error(String p_string) {
|
||||
OS::get_singleton()->logerr("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
||||
PrintHandlerList *l = print_handler_list;
|
||||
while (l) {
|
||||
l->printfunc(l->userdata, p_string, true);
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
_global_unlock();
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,12 @@ void remove_print_handler(PrintHandlerList *p_handler);
|
||||
|
||||
extern bool _print_line_enabled;
|
||||
extern bool _print_error_enabled;
|
||||
|
||||
extern void print_line(String p_string);
|
||||
extern void print_error(String p_string);
|
||||
extern void print_verbose(String p_string);
|
||||
|
||||
extern void force_print_line(String p_string);
|
||||
extern void force_print_error(String p_string);
|
||||
|
||||
#endif
|
||||
|
@ -521,8 +521,8 @@ String OS_Unix::get_executable_path() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
void UnixTerminalLogger::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)) {
|
||||
void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type, bool p_force) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
|
||||
class UnixTerminalLogger : public StdLogger {
|
||||
public:
|
||||
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);
|
||||
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, bool p_force = false);
|
||||
virtual ~UnixTerminalLogger();
|
||||
};
|
||||
|
||||
|
@ -35,16 +35,16 @@
|
||||
#include "core/string/print_string.h"
|
||||
#include <syslog.h>
|
||||
|
||||
void SyslogLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
if (!should_log(p_err)) {
|
||||
void SyslogLogger::logv(const char *p_format, va_list p_list, bool p_err, bool p_force) {
|
||||
if (!p_force && !should_log(p_err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vsyslog(p_err ? LOG_ERR : LOG_INFO, p_format, p_list);
|
||||
}
|
||||
|
||||
void SyslogLogger::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 (!should_log(true)) {
|
||||
void SyslogLogger::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type, bool p_force) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,8 @@
|
||||
|
||||
class SyslogLogger : public Logger {
|
||||
public:
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type);
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) _PRINTF_FORMAT_ATTRIBUTE_2_0;
|
||||
virtual void print_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, bool p_force = false);
|
||||
|
||||
virtual ~SyslogLogger();
|
||||
};
|
||||
|
@ -80,7 +80,7 @@ String _remove_symlink(const String &dir) {
|
||||
|
||||
class AndroidLogger : public Logger {
|
||||
public:
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false) {
|
||||
__android_log_vprint(p_err ? ANDROID_LOG_ERROR : ANDROID_LOG_INFO, "pandemonium", p_format, p_list);
|
||||
}
|
||||
|
||||
|
@ -1942,8 +1942,8 @@ String OS_OSX::get_name() const {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
|
||||
class OSXTerminalLogger : public StdLogger {
|
||||
public:
|
||||
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) {
|
||||
if (!should_log(true)) {
|
||||
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, bool p_force = false) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,8 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_err) {
|
||||
if (!should_log(p_err)) {
|
||||
void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_err, bool p_force) {
|
||||
if (!p_force && !should_log(p_err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,8 +73,8 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
||||
#endif
|
||||
}
|
||||
|
||||
void WindowsTerminalLogger::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)) {
|
||||
void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type, bool p_force) {
|
||||
if (!p_force && !should_log(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,8 @@
|
||||
|
||||
class WindowsTerminalLogger : public StdLogger {
|
||||
public:
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err);
|
||||
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);
|
||||
virtual void logv(const char *p_format, va_list p_list, bool p_err, bool p_force = false);
|
||||
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, bool p_force = false);
|
||||
virtual ~WindowsTerminalLogger();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user