Merge pull request #13133 from endragor/resurrect-file-logging
Return and repair file logging
This commit is contained in:
commit
6c9ee1f125
19 changed files with 60 additions and 81 deletions
|
@ -29,6 +29,7 @@
|
|||
/*************************************************************************/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include "os/dir_access.h"
|
||||
#include "os/os.h"
|
||||
#include "print_string.h"
|
||||
|
@ -259,6 +260,10 @@ void CompositeLogger::log_error(const char *p_function, const char *p_file, int
|
|||
}
|
||||
}
|
||||
|
||||
void CompositeLogger::add_logger(Logger *p_logger) {
|
||||
loggers.push_back(p_logger);
|
||||
}
|
||||
|
||||
CompositeLogger::~CompositeLogger() {
|
||||
for (int i = 0; i < loggers.size(); ++i) {
|
||||
memdelete(loggers[i]);
|
||||
|
|
|
@ -101,6 +101,8 @@ 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);
|
||||
|
||||
void add_logger(Logger *p_logger);
|
||||
|
||||
virtual ~CompositeLogger();
|
||||
};
|
||||
|
||||
|
|
|
@ -63,15 +63,21 @@ void OS::debug_break(){
|
|||
// something
|
||||
};
|
||||
|
||||
void OS::_set_logger(Logger *p_logger) {
|
||||
void OS::_set_logger(CompositeLogger *p_logger) {
|
||||
if (_logger) {
|
||||
memdelete(_logger);
|
||||
}
|
||||
_logger = p_logger;
|
||||
}
|
||||
|
||||
void OS::initialize_logger() {
|
||||
_set_logger(memnew(StdLogger));
|
||||
void OS::add_logger(Logger *p_logger) {
|
||||
if (!_logger) {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(p_logger);
|
||||
_logger = memnew(CompositeLogger(loggers));
|
||||
} else {
|
||||
_logger->add_logger(p_logger);
|
||||
}
|
||||
}
|
||||
|
||||
void OS::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) {
|
||||
|
@ -604,7 +610,10 @@ OS::OS() {
|
|||
_stack_bottom = (void *)(&stack_bottom);
|
||||
|
||||
_logger = NULL;
|
||||
_set_logger(memnew(StdLogger));
|
||||
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(StdLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
OS::~OS() {
|
||||
|
|
|
@ -62,10 +62,10 @@ class OS {
|
|||
|
||||
void *_stack_bottom;
|
||||
|
||||
Logger *_logger;
|
||||
CompositeLogger *_logger;
|
||||
|
||||
protected:
|
||||
void _set_logger(Logger *p_logger);
|
||||
void _set_logger(CompositeLogger *p_logger);
|
||||
|
||||
public:
|
||||
typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
|
||||
|
@ -114,7 +114,8 @@ protected:
|
|||
virtual int get_audio_driver_count() const = 0;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const = 0;
|
||||
|
||||
virtual void initialize_logger();
|
||||
void add_logger(Logger *p_logger);
|
||||
|
||||
virtual void initialize_core() = 0;
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0;
|
||||
|
||||
|
|
|
@ -133,15 +133,6 @@ void OS_Unix::initialize_core() {
|
|||
}
|
||||
}
|
||||
|
||||
void OS_Unix::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(UnixTerminalLogger));
|
||||
// FIXME: Reenable once we figure out how to get this properly in user://
|
||||
// instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
|
||||
//loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
void OS_Unix::finalize_core() {
|
||||
}
|
||||
|
||||
|
@ -543,4 +534,10 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i
|
|||
|
||||
UnixTerminalLogger::~UnixTerminalLogger() {}
|
||||
|
||||
OS_Unix::OS_Unix() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(UnixTerminalLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,7 +53,6 @@ protected:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual int unix_initialize_audio(int p_audio_driver);
|
||||
//virtual void initialize(int p_video_driver,int p_audio_driver);
|
||||
|
@ -63,6 +62,8 @@ protected:
|
|||
String stdin_buf;
|
||||
|
||||
public:
|
||||
OS_Unix();
|
||||
|
||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
||||
virtual String get_stdin_string(bool p_block);
|
||||
|
||||
|
|
|
@ -290,8 +290,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
|
||||
register_core_settings(); //here globals is present
|
||||
|
||||
OS::get_singleton()->initialize_logger();
|
||||
|
||||
translation_server = memnew(TranslationServer);
|
||||
performance = memnew(Performance);
|
||||
ClassDB::register_class<Performance>();
|
||||
|
@ -745,6 +743,15 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
#endif
|
||||
}
|
||||
|
||||
GLOBAL_DEF("logging/file_logging/enable_file_logging", true);
|
||||
GLOBAL_DEF("logging/file_logging/log_path", "user://logs/log.txt");
|
||||
GLOBAL_DEF("logging/file_logging/max_log_files", 10);
|
||||
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");
|
||||
int max_files = GLOBAL_GET("logging/file_logging/max_log_files");
|
||||
OS::get_singleton()->add_logger(memnew(RotatedFileLogger(base_path, max_files)));
|
||||
}
|
||||
|
||||
if (editor) {
|
||||
Engine::get_singleton()->set_editor_hint(true);
|
||||
main_args.push_back("--editor");
|
||||
|
|
|
@ -114,15 +114,6 @@ void OS_Android::initialize_core() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void OS_Android::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(AndroidLogger));
|
||||
// FIXME: Reenable once we figure out how to get this properly in user://
|
||||
// instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
|
||||
//loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
|
||||
|
||||
ERR_FAIL_COND(!p_gl_extensions);
|
||||
|
@ -762,7 +753,9 @@ OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURI
|
|||
alert_func = p_alert_func;
|
||||
use_reload_hooks = false;
|
||||
|
||||
_set_logger(memnew(AndroidLogger));
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(AndroidLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
OS_Android::~OS_Android() {
|
||||
|
|
|
@ -144,7 +144,6 @@ public:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
|
|
|
@ -97,17 +97,6 @@ void OSIPhone::initialize_core() {
|
|||
set_data_dir(data_dir);
|
||||
};
|
||||
|
||||
void OSIPhone::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(SyslogLogger));
|
||||
#ifdef DEBUG_ENABLED
|
||||
// it seems iOS app's stdout/stderr is only obtainable if you launch it from Xcode
|
||||
loggers.push_back(memnew(StdLogger));
|
||||
#endif
|
||||
loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
||||
|
||||
supported_orientations = 0;
|
||||
|
@ -639,7 +628,13 @@ OSIPhone::OSIPhone(int width, int height, String p_data_dir) {
|
|||
// which is initialized in initialize_core
|
||||
data_dir = p_data_dir;
|
||||
|
||||
_set_logger(memnew(SyslogLogger));
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(SyslogLogger));
|
||||
#ifdef DEBUG_ENABLED
|
||||
// it seems iOS app's stdout/stderr is only obtainable if you launch it from Xcode
|
||||
loggers.push_back(memnew(StdLogger));
|
||||
#endif
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
};
|
||||
|
||||
OSIPhone::~OSIPhone() {
|
||||
|
|
|
@ -86,7 +86,6 @@ private:
|
|||
virtual int get_video_driver_count() const;
|
||||
virtual const char *get_video_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
|
|
|
@ -80,10 +80,6 @@ void OS_JavaScript::initialize_core() {
|
|||
FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES);
|
||||
}
|
||||
|
||||
void OS_JavaScript::initialize_logger() {
|
||||
_set_logger(memnew(StdLogger));
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_opengl_extensions(const char *p_gl_extensions) {
|
||||
|
||||
ERR_FAIL_COND(!p_gl_extensions);
|
||||
|
|
|
@ -81,7 +81,6 @@ public:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
|
|
|
@ -121,7 +121,6 @@ protected:
|
|||
virtual int get_video_driver_count() const;
|
||||
virtual const char *get_video_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
virtual void finalize();
|
||||
|
|
|
@ -1217,15 +1217,6 @@ public:
|
|||
typedef UnixTerminalLogger OSXTerminalLogger;
|
||||
#endif
|
||||
|
||||
void OS_OSX::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(OSXTerminalLogger));
|
||||
// FIXME: Reenable once we figure out how to get this properly in user://
|
||||
// instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
|
||||
//loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
void OS_OSX::alert(const String &p_alert, const String &p_title) {
|
||||
// Set OS X-compliant variables
|
||||
NSAlert *window = [[NSAlert alloc] init];
|
||||
|
@ -2174,7 +2165,9 @@ OS_OSX::OS_OSX() {
|
|||
window_size = Vector2(1024, 600);
|
||||
zoomed = false;
|
||||
|
||||
_set_logger(memnew(OSXTerminalLogger));
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(OSXTerminalLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {
|
||||
|
|
|
@ -179,15 +179,6 @@ void OSUWP::initialize_core() {
|
|||
cursor_shape = CURSOR_ARROW;
|
||||
}
|
||||
|
||||
void OSUWP::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(WindowsTerminalLogger));
|
||||
// FIXME: Reenable once we figure out how to get this properly in user://
|
||||
// instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
|
||||
//loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
bool OSUWP::can_draw() const {
|
||||
|
||||
return !minimized;
|
||||
|
@ -834,7 +825,9 @@ OSUWP::OSUWP() {
|
|||
|
||||
AudioDriverManager::add_driver(&audio_driver);
|
||||
|
||||
_set_logger(memnew(WindowsTerminalLogger));
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(WindowsTerminalLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
OSUWP::~OSUWP() {
|
||||
|
|
|
@ -157,7 +157,6 @@ protected:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
|
|
|
@ -201,15 +201,6 @@ void OS_Windows::initialize_core() {
|
|||
cursor_shape = CURSOR_ARROW;
|
||||
}
|
||||
|
||||
void OS_Windows::initialize_logger() {
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(WindowsTerminalLogger));
|
||||
// FIXME: Reenable once we figure out how to get this properly in user://
|
||||
// instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
|
||||
//loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
bool OS_Windows::can_draw() const {
|
||||
|
||||
return !minimized;
|
||||
|
@ -2326,7 +2317,9 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
|
|||
AudioDriverManager::add_driver(&driver_xaudio2);
|
||||
#endif
|
||||
|
||||
_set_logger(memnew(WindowsTerminalLogger));
|
||||
Vector<Logger *> loggers;
|
||||
loggers.push_back(memnew(WindowsTerminalLogger));
|
||||
_set_logger(memnew(CompositeLogger(loggers)));
|
||||
}
|
||||
|
||||
OS_Windows::~OS_Windows() {
|
||||
|
|
|
@ -145,7 +145,6 @@ protected:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_logger();
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
|
|
Loading…
Reference in a new issue