Skip to content

Commit

Permalink
shortcut guide logs (#8191)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Nov 24, 2020
1 parent 50dcd97 commit 65f8966
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/logger/logger_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct LogSettings
inline const static std::wstring runnerLogPath = L"RunnerLogs\\runner-log.txt";
inline const static std::string launcherLoggerName = "launcher";
inline const static std::wstring launcherLogPath = L"LogsModuleInterface\\launcher-log.txt";
inline const static std::string shortcutGuideLoggerName = "shortcut-guide";
inline const static std::wstring shortcutGuideLogPath = L"ShortcutGuideLogs\\shortcut-guide-log.txt";
inline const static int retention = 30;
std::wstring logLevel;
LogSettings();
Expand Down
24 changes: 24 additions & 0 deletions src/modules/shortcut_guide/ShortcutGuideLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "pch.h"
#include "ShortcutGuideLogger.h"
#include <common\settings_helpers.h>
#include <filesystem>

std::shared_ptr<Logger> ShortcutGuideLogger::logger;

void ShortcutGuideLogger::Init(std::wstring moduleSaveLocation)
{
std::filesystem::path logFilePath(moduleSaveLocation);
logFilePath.append(LogSettings::shortcutGuideLogPath);
logger = std::make_shared<Logger>(LogSettings::shortcutGuideLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
logger->info("Shortcut Guide logger initialized");
}

std::shared_ptr<Logger> ShortcutGuideLogger::GetLogger()
{
if (!logger)
{
throw "Shortcut Guide logger is not initialized";
}

return logger;
}
11 changes: 11 additions & 0 deletions src/modules/shortcut_guide/ShortcutGuideLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <common/logger/logger.h>

class ShortcutGuideLogger
{
static std::shared_ptr<Logger> logger;

public:
static void Init(std::wstring moduleSaveLocation);
static std::shared_ptr<Logger> GetLogger();
};
8 changes: 8 additions & 0 deletions src/modules/shortcut_guide/shortcut_guide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <common/debug_control.h>
#include <sstream>
#include <modules\shortcut_guide\ShortcutGuideConstants.h>
#include <modules\shortcut_guide\ShortcutGuideLogger.h>
#include <common\settings_helpers.cpp>

extern "C" IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -96,6 +98,8 @@ OverlayWindow::OverlayWindow()
{
app_name = GET_RESOURCE_STRING(IDS_SHORTCUT_GUIDE);
app_key = ShortcutGuideConstants::ModuleKey;
ShortcutGuideLogger::Init(PTSettingsHelper::get_module_save_folder_location(app_key));
ShortcutGuideLogger::GetLogger()->info("Overlay Window is creating");
init_settings();
}

Expand Down Expand Up @@ -196,6 +200,8 @@ constexpr UINT alternative_switch_vk_code = VK_OEM_2;

void OverlayWindow::enable()
{
ShortcutGuideLogger::GetLogger()->info("Shortcut Guide is enabling");

auto switcher = [&](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
if (msg == WM_KEYDOWN && wparam == VK_ESCAPE && instance->target_state->active())
{
Expand Down Expand Up @@ -247,6 +253,8 @@ void OverlayWindow::enable()

void OverlayWindow::disable(bool trace_event)
{
ShortcutGuideLogger::GetLogger()->info("Shortcut Guide is disabling");

if (_enabled)
{
_enabled = false;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/shortcut_guide/shortcut_guide.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<ClInclude Include="Generated Files/resource.h" />
<None Include="resource.base.h" />
<ClInclude Include="ShortcutGuideConstants.h" />
<ClInclude Include="ShortcutGuideLogger.h" />
<ClInclude Include="shortcut_guide.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="target_state.h" />
Expand All @@ -125,6 +126,7 @@
<ClCompile Include="overlay_window.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="keyboard_state.cpp" />
<ClCompile Include="ShortcutGuideLogger.cpp" />
<ClCompile Include="shortcut_guide.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
Expand All @@ -136,6 +138,9 @@
<ProjectReference Include="..\..\common\common.vcxproj">
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
</ProjectReference>
<ProjectReference Include="..\..\common\logger\logger.vcxproj">
<Project>{d9b8fc84-322a-4f9f-bbb9-20915c47ddfd}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Generated Files/shortcut_guide.rc" />
Expand All @@ -148,6 +153,7 @@
<None Include="Resources.resx" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="..\..\..\deps\spdlog.props" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
Expand Down

0 comments on commit 65f8966

Please sign in to comment.