diff options
-rw-r--r-- | core/io/logger.cpp | 5 | ||||
-rw-r--r-- | core/io/logger.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 17 | ||||
-rw-r--r-- | core/os/os.h | 7 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 15 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 3 | ||||
-rwxr-xr-x | main/main.cpp | 11 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 13 | ||||
-rw-r--r-- | platform/android/os_android.h | 1 | ||||
-rw-r--r-- | platform/iphone/os_iphone.cpp | 19 | ||||
-rw-r--r-- | platform/iphone/os_iphone.h | 1 | ||||
-rw-r--r-- | platform/javascript/os_javascript.cpp | 4 | ||||
-rw-r--r-- | platform/javascript/os_javascript.h | 1 | ||||
-rw-r--r-- | platform/osx/os_osx.h | 1 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 13 | ||||
-rw-r--r-- | platform/uwp/os_uwp.cpp | 13 | ||||
-rw-r--r-- | platform/uwp/os_uwp.h | 1 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 13 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 1 |
19 files changed, 60 insertions, 81 deletions
diff --git a/core/io/logger.cpp b/core/io/logger.cpp index ce2ce44b1d..7177359c8a 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -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]); diff --git a/core/io/logger.h b/core/io/logger.h index cf0cc7699f..f8a394193f 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -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(); }; diff --git a/core/os/os.cpp b/core/os/os.cpp index dd71f8a9c6..0e7e26df73 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -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() { diff --git a/core/os/os.h b/core/os/os.h index e48e5c6d70..fe4ffb2922 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -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; diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index ce0967af2c..0d102902e8 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -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 diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 432f48408f..5b3fb824f0 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -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); diff --git a/main/main.cpp b/main/main.cpp index 5410aae1d2..e74402d7dd 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -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"); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index b2c8799540..b575f15559 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -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() { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index d25f60d540..3b7f55096e 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -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); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 90cb09b458..fbe3bd310d 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -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() { diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 0790a2a9ea..1ef673765a 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -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); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 74cfec14a6..d5c675d9e0 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -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); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 77eeb02a9f..a95b069d03 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -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); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index aa8ee1fe83..9a740a7bea 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -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(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 110cb776ee..9213f378b3 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1185,15 +1185,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]; @@ -2142,7 +2133,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) { diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 64e319327f..1655caf04b 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -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() { diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 3c52fc29a8..8d69cd53fd 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -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); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 72d51ad62a..c189b3b744 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -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() { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 5e0c240dba..4367297262 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -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); |