From 2b5f1a9fa1f74e30dd9e30ece556daaeb83e77b8 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Tue, 9 Jul 2019 13:56:11 +0200 Subject: [PATCH] info level in log file --- .editorconfig | 8 ++++---- src/editor/asset_browser.cpp | 2 ++ src/editor/asset_compiler.cpp | 2 ++ src/editor/studio_app.cpp | 11 +++++++++-- src/editor/world_editor.cpp | 3 +++ src/engine/engine.cpp | 23 +++++++++++++---------- src/engine/win/debug.cpp | 20 +++++++++++++------- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/.editorconfig b/.editorconfig index c4ee0ae3a..b39b7e548 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -root = true - -[*] -indent_style = tab \ No newline at end of file +root = true + +[*] +indent_style = tab diff --git a/src/editor/asset_browser.cpp b/src/editor/asset_browser.cpp index 39fc6d072..01623f4ad 100644 --- a/src/editor/asset_browser.cpp +++ b/src/editor/asset_browser.cpp @@ -263,6 +263,8 @@ int AssetBrowser::getThumbnailIndex(int i, int j, int columns) const void AssetBrowser::createTile(FileInfo& tile, const char* out_path) { if (tile.create_called) return; + + logInfo("Editor") << "Creating tile for " << tile.filepath; tile.create_called = true; const AssetCompiler& compiler = m_app.getAssetCompiler(); for (IPlugin* plugin : m_plugins) { diff --git a/src/editor/asset_compiler.cpp b/src/editor/asset_compiler.cpp index 7c3979ef6..912c9c3ec 100644 --- a/src/editor/asset_compiler.cpp +++ b/src/editor/asset_compiler.cpp @@ -464,6 +464,7 @@ struct AssetCompilerImpl : AssetCompiler || fs.getLastModified(dst_path) < fs.getLastModified(meta_path) ) { + logInfo("Editor") << res.getPath() << " is not compiled, pushing to compile queue"; MT::SpinLock lock(m_to_compile_mutex); MT::atomicIncrement(&m_task.m_to_compile_count); const Path path(filepath); @@ -591,6 +592,7 @@ int AssetCompilerTask::task() if (p.isValid()) { PROFILE_BLOCK("compile asset"); Profiler::pushString(p.c_str()); + logInfo("Editor") << "Compiling " << p << "..."; const bool compiled = m_compiler.compile(p); MT::atomicDecrement(&m_to_compile_count); if (compiled) { diff --git a/src/editor/studio_app.cpp b/src/editor/studio_app.cpp index 44b1a2495..3e9e9353d 100644 --- a/src/editor/studio_app.cpp +++ b/src/editor/studio_app.cpp @@ -266,6 +266,8 @@ public: void onInit() override { + OS::Timer init_timer; + m_add_cmp_root.label[0] = '\0'; m_template_name[0] = '\0'; m_open_filter[0] = '\0'; @@ -284,7 +286,8 @@ public: char data_dir[MAX_PATH_LENGTH] = {}; checkDataDirCommandLine(data_dir, lengthOf(data_dir)); - m_engine = Engine::create(data_dir[0] ? data_dir : (saved_data_dir[0] ? saved_data_dir : current_dir), m_allocator); + m_engine = Engine::create(data_dir[0] ? data_dir : (saved_data_dir[0] ? saved_data_dir : current_dir) + , m_allocator); createLua(); m_editor = WorldEditor::create(current_dir, *m_engine, m_allocator); @@ -327,6 +330,8 @@ public: m_sleep_when_inactive = shouldSleepWhenInactive(); checkScriptCommandLine(); + + logInfo("Editor") << "Startup took " << init_timer.getTimeSinceStart() << " s"; } @@ -1589,6 +1594,7 @@ public: void initIMGUI() { + logInfo("Editor") << "Initializing imgui..."; ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable; io.IniFilename = nullptr; @@ -1653,6 +1659,7 @@ public: void loadSettings() { + logInfo("Editor") << "Loading settings..."; char cmd_line[2048]; OS::getCommandLine(cmd_line, lengthOf(cmd_line)); @@ -1960,7 +1967,6 @@ public: } } - static void checkDataDirCommandLine(char* dir, int max_size) { char cmd_line[2048]; @@ -2675,6 +2681,7 @@ public: void loadIcons() { + logInfo("Editor") << "Loading icons..."; RenderInterface& render_interface = *m_editor->getRenderInterface(); FileSystem& fs = m_engine->getFileSystem(); for (auto* action : m_actions) diff --git a/src/editor/world_editor.cpp b/src/editor/world_editor.cpp index db034c266..27a1ef2a3 100644 --- a/src/editor/world_editor.cpp +++ b/src/editor/world_editor.cpp @@ -2322,6 +2322,8 @@ public: void doExecute(IEditorCommand* command) { ASSERT(command->isReady()); + + logInfo("Editor") << "Executing editor command " << command->getType() << "..."; m_is_universe_changed = true; if (m_undo_index >= 0 && command->getType() == m_undo_stack[m_undo_index]->getType()) { @@ -2688,6 +2690,7 @@ public: , m_game_mode_file(m_allocator) , m_command_queue(m_allocator) { + logInfo("Editor") << "Initializing editor..."; m_viewport.is_ortho = false; m_viewport.pos = DVec3(0); m_viewport.rot.set(0, 0, 0, 1); diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index b5017573d..496d7cad1 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -389,8 +389,8 @@ void registerCFunction(lua_State* L, const char* name, lua_CFunction f) static const u32 SERIALIZED_ENGINE_MAGIC = 0x5f4c454e; // == '_LEN' -static OS::OutputFile g_error_file; -static bool g_is_error_file_open = false; +static OS::OutputFile g_log_file; +static bool g_is_log_file_open = false; #pragma pack(1) @@ -406,7 +406,7 @@ public: static void showLogInVS(LogLevel level, const char* system, const char* message) { if(level == LogLevel::ERROR) { - Debug::debugOutput("error: "); + Debug::debugOutput("Error: "); } Debug::debugOutput(system); Debug::debugOutput(" : "); @@ -417,10 +417,13 @@ static void showLogInVS(LogLevel level, const char* system, const char* message) static void logToFile(LogLevel level, const char*, const char* message) { - if (level != LogLevel::ERROR) return; - if (!g_is_error_file_open) return; - g_error_file.write(message, stringLength(message)); - g_error_file.flush(); + if (!g_is_log_file_open) return; + if (level == LogLevel::ERROR) { + g_log_file.write("Error: ", stringLength("Error :")); + } + g_log_file.write(message, stringLength(message)); + g_log_file.write("\n", 1); + g_log_file.flush(); } @@ -466,12 +469,12 @@ public: , m_paused(false) , m_next_frame(false) { + g_is_log_file_open = g_log_file.open("lumix.log"); + logInfo("Core") << "Creating engine..."; Profiler::setThreadName("Worker"); installUnhandledExceptionHandler(); - g_is_error_file_open = g_error_file.open("error.log"); - getLogCallback().bind(); getLogCallback().bind(); @@ -1210,7 +1213,7 @@ public: m_prefab_resource_manager.destroy(); lua_close(m_state); - g_error_file.close(); + g_log_file.close(); PathManager::destroy(*m_path_manager); } diff --git a/src/engine/win/debug.cpp b/src/engine/win/debug.cpp index 47894b383..5656e8643 100644 --- a/src/engine/win/debug.cpp +++ b/src/engine/win/debug.cpp @@ -1,4 +1,5 @@ #include "engine/debug.h" +#include "engine/log.h" #include "engine/mt/atomic.h" #include "engine/os.h" #include "engine/string.h" @@ -756,7 +757,7 @@ static LONG WINAPI unhandledExceptionHandler(LPEXCEPTION_POINTERS info) }; auto dumper = [](void* data) -> DWORD { - auto info = ((CrashInfo*)data)->info; + LPEXCEPTION_POINTERS info = ((CrashInfo*)data)->info; uintptr base = (uintptr)GetModuleHandle(NULL); StaticString<4096> message; if(info) @@ -798,12 +799,6 @@ static LONG WINAPI unhandledExceptionHandler(LPEXCEPTION_POINTERS info) nullptr); CloseHandle(file); - SendFile("Lumix Studio crash", - "SMTP:mikulas.florek@gamedev.sk", - "Lumix Studio", - message, - minidump_path); - minidump_type = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpFilterMemory | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules); @@ -816,7 +811,14 @@ static LONG WINAPI unhandledExceptionHandler(LPEXCEPTION_POINTERS info) info ? &minidump_exception_info : nullptr, nullptr, nullptr); + CloseHandle(file); + + SendFile("Lumix Studio crash", + "SMTP:mikulas.florek@gamedev.sk", + "Lumix Studio", + message, + minidump_path); return 0; }; @@ -825,6 +827,10 @@ static LONG WINAPI unhandledExceptionHandler(LPEXCEPTION_POINTERS info) auto handle = CreateThread(0, 0x8000, dumper, &crash_info, 0, &thread_id); WaitForSingleObject(handle, INFINITE); + StaticString<4096> message; + getStack(*info->ContextRecord, message.data, sizeof(message.data)); + logError("Engine") << message; + return EXCEPTION_CONTINUE_SEARCH; }