[Color Picker] Logs (#12157)

* - Fixed module interface logs

- Added logs to correlate logs between the runner and color picker process

* Fix logs
This commit is contained in:
Mykhailo Pylyp 2021-07-02 19:54:44 +03:00 committed by GitHub
parent 6ad6ff7fb6
commit 25ab4afe78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View file

@ -10,6 +10,8 @@
#include <colorPicker/ColorPicker/ColorPickerConstants.h> #include <colorPicker/ColorPicker/ColorPickerConstants.h>
#include <common/interop/shared_constants.h> #include <common/interop/shared_constants.h>
#include <common/utils/logger_helper.h>
#include <common/utils/winapi_error.h>
BOOL APIENTRY DllMain(HMODULE hModule, BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call, DWORD ul_reason_for_call,
@ -108,7 +110,7 @@ private:
void launch_process() void launch_process()
{ {
Logger::trace(L"Launching ColorPicker process"); Logger::trace(L"Starting ColorPicker process");
unsigned long powertoys_pid = GetCurrentProcessId(); unsigned long powertoys_pid = GetCurrentProcessId();
std::wstring executable_args = L""; std::wstring executable_args = L"";
@ -119,12 +121,13 @@ private:
sei.lpFile = L"modules\\ColorPicker\\ColorPickerUI.exe"; sei.lpFile = L"modules\\ColorPicker\\ColorPickerUI.exe";
sei.nShow = SW_SHOWNORMAL; sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = executable_args.data(); sei.lpParameters = executable_args.data();
if (!ShellExecuteExW(&sei)) if (ShellExecuteExW(&sei))
{ {
DWORD error = GetLastError(); Logger::trace("Successfully started the Color Picker process");
std::wstring message = L"ColorPicker failed to start with error = "; }
message += std::to_wstring(error); else
Logger::error(message); {
Logger::error( L"ColorPicker failed to start. {}", get_last_error_or_default(GetLastError()));
} }
m_hProcess = sei.hProcess; m_hProcess = sei.hProcess;
@ -153,6 +156,7 @@ public:
{ {
app_name = GET_RESOURCE_STRING(IDS_COLORPICKER_NAME); app_name = GET_RESOURCE_STRING(IDS_COLORPICKER_NAME);
app_key = ColorPickerConstants::ModuleKey; app_key = ColorPickerConstants::ModuleKey;
LoggerHelpers::init_logger(app_key, L"ModuleInterface", "ColorPicker");
send_telemetry_event = CreateDefaultEvent(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT); send_telemetry_event = CreateDefaultEvent(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
m_hInvokeEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT); m_hInvokeEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT);
init_settings(); init_settings();
@ -169,6 +173,7 @@ public:
// Destroy the powertoy and free memory // Destroy the powertoy and free memory
virtual void destroy() override virtual void destroy() override
{ {
Logger::trace("ColorPicker::destroy()");
delete this; delete this;
} }
@ -224,6 +229,7 @@ public:
virtual void enable() virtual void enable()
{ {
Logger::trace("ColorPicker::enable()");
ResetEvent(send_telemetry_event); ResetEvent(send_telemetry_event);
ResetEvent(m_hInvokeEvent); ResetEvent(m_hInvokeEvent);
launch_process(); launch_process();
@ -232,6 +238,7 @@ public:
virtual void disable() virtual void disable()
{ {
Logger::trace("ColorPicker::disable()");
if (m_enabled) if (m_enabled)
{ {
ResetEvent(send_telemetry_event); ResetEvent(send_telemetry_event);

View file

@ -5,6 +5,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using ColorPicker.Helpers;
using ColorPicker.Mouse; using ColorPicker.Mouse;
using ManagedCommon; using ManagedCommon;
using Microsoft.PowerToys.Common.UI; using Microsoft.PowerToys.Common.UI;
@ -30,6 +31,7 @@ namespace ColorPickerUI
_instanceMutex = new Mutex(true, @"Local\PowerToys_ColorPicker_InstanceMutex", out bool createdNew); _instanceMutex = new Mutex(true, @"Local\PowerToys_ColorPicker_InstanceMutex", out bool createdNew);
if (!createdNew) if (!createdNew)
{ {
Logger.LogWarning("There is ColorPicker instance running. Exiting Color Picker");
_instanceMutex = null; _instanceMutex = null;
Environment.Exit(0); Environment.Exit(0);
return; return;
@ -39,8 +41,10 @@ namespace ColorPickerUI
{ {
_ = int.TryParse(_args[0], out _powerToysRunnerPid); _ = int.TryParse(_args[0], out _powerToysRunnerPid);
Logger.LogInfo($"Color Picker started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}");
RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () => RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
{ {
Logger.LogInfo("PowerToys Runner exited. Exiting ColorPicker");
Environment.Exit(0); Environment.Exit(0);
}); });
} }

View file

@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Diagnostics;
using ColorPicker.Helpers; using ColorPicker.Helpers;
using ColorPicker.Mouse; using ColorPicker.Mouse;
@ -19,6 +19,7 @@ namespace ColorPicker
public static void Main(string[] args) public static void Main(string[] args)
{ {
_args = args; _args = args;
Logger.LogInfo($"Color Picker started with pid={Process.GetCurrentProcess().Id}");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
try try
{ {