Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: explicitly write wide string characters to console #193

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions LogMonitor/src/LogMonitor/LogWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ class LogWriter final
InitializeSRWLock(&m_stdoutLock);

DWORD dwMode;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

if (!GetConsoleMode(hConsole, &dwMode)) {
if (!GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &dwMode))
{
m_isConsole = false;
}
else {
m_isConsole = true;
}

m_isConsole = true;
iankingori marked this conversation as resolved.
Show resolved Hide resolved

_setmode(_fileno(stdout), _O_U8TEXT);
};
Expand All @@ -30,7 +29,6 @@ class LogWriter final
private:
SRWLOCK m_stdoutLock;
bool m_isConsole;
HANDLE hConsole;

void FlushStdOut()
{
Expand Down Expand Up @@ -66,14 +64,7 @@ public :
{
AcquireSRWLockExclusive(&m_stdoutLock);

std::wstring output = LogMessage + L"\n";

if (m_isConsole) {
WriteConsoleW(hConsole, output.c_str(), wcslen(output.c_str()), NULL, NULL);
} else {
wprintf(output.c_str());
}

wprintf(L"%s\n", LogMessage.c_str());
iankingori marked this conversation as resolved.
Show resolved Hide resolved
FlushStdOut();

ReleaseSRWLockExclusive(&m_stdoutLock);
Expand All @@ -85,14 +76,7 @@ public :
{
AcquireSRWLockExclusive(&m_stdoutLock);

std::wstring output = LogMessage + L"\n";

if (m_isConsole) {
WriteConsoleW(hConsole, output.c_str(), wcslen(output.c_str()), NULL, NULL);
} else {
wprintf(output.c_str());
}

wprintf(L"%s\n", LogMessage.c_str());
FlushStdOut();

ReleaseSRWLockExclusive(&m_stdoutLock);
Expand Down
2 changes: 1 addition & 1 deletion LogMonitor/src/LogMonitor/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define LM_MAJORNUMBER 2
#define LM_MINORNUMBER 1
#define LM_PATCHNUMBER 0
#define LM_PATCHNUMBER 1
// removed in support of semantic versioning - https://semver.org
// major.minor.patch
// #define LM_BUILDMINORVERSION 0
Expand Down