Skip to content

Commit

Permalink
Revert "Windows console code page handling (ANSI->OEM)"
Browse files Browse the repository at this point in the history
  • Loading branch information
zsummer committed Dec 2, 2015
1 parent 81ddfcb commit b831953
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
17 changes: 4 additions & 13 deletions log4z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include <shlwapi.h>
#include <process.h>
#pragma comment(lib, "shlwapi")
#pragma comment(lib, "User32.lib")
#pragma warning(disable:4996)

#else
Expand Down Expand Up @@ -1162,24 +1161,15 @@ LogerManager::~LogerManager()

void LogerManager::showColorText(const char *text, int level)
{

#ifdef WIN32
char oem[LOG4Z_LOG_BUF_SIZE] = { 0 };
CharToOemBuffA(text, oem, LOG4Z_LOG_BUF_SIZE);
#endif

if (level <= LOG_LEVEL_DEBUG || level > LOG_LEVEL_FATAL)
{
#ifdef WIN32
printf("%s", oem);
#else
printf("%s", text);
#endif
return;
}
#ifndef WIN32
printf("%s%s\e[0m", LOG_COLOR[level], text);
#else

AutoLock l(_scLock);
HANDLE hStd = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (hStd == INVALID_HANDLE_VALUE) return;
Expand All @@ -1188,10 +1178,10 @@ void LogerManager::showColorText(const char *text, int level)
{
return;
}
else
else
{
SetConsoleTextAttribute(hStd, LOG_COLOR[level]);
printf("%s", oem);
printf("%s", text);
SetConsoleTextAttribute(hStd, oldInfo.wAttributes);
}
#endif
Expand Down Expand Up @@ -1886,3 +1876,4 @@ ILog4zManager * ILog4zManager::getInstance()

_ZSUMMER_LOG4Z_END
_ZSUMMER_END

13 changes: 13 additions & 0 deletions log4z.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,15 @@ const bool LOG4Z_DEFAULT_MONTHDIR = false;
const int LOG4Z_DEFAULT_LIMITSIZE = 100;
//! default logger show suffix (file name and line number)
const bool LOG4Z_DEFAULT_SHOWSUFFIX = true;

///////////////////////////////////////////////////////////////////////////
//! -----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////





#ifndef _ZSUMMER_BEGIN
#define _ZSUMMER_BEGIN namespace zsummer {
#endif
Expand All @@ -257,6 +262,9 @@ const bool LOG4Z_DEFAULT_SHOWSUFFIX = true;
_ZSUMMER_BEGIN
_ZSUMMER_LOG4Z_BEGIN




//! log4z class
class ILog4zManager
{
Expand Down Expand Up @@ -633,3 +641,8 @@ _ZSUMMER_LOG4Z_END
_ZSUMMER_END

#endif





22 changes: 6 additions & 16 deletions test/fast_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ int main(int argc, char *argv[])
ILog4zManager::getRef().setLoggerLevel(LOG4Z_MAIN_LOGGER_ID,LOG_LEVEL_TRACE);
//LOGD: LOG WITH level LOG_DEBUG
//LOGI: LOG WITH level LOG_INFO
#ifdef WIN32
//begin test wstring(utf-16) log string input....
WCHAR checkWCHAR[100] = L"check unicode WCHAR log";
std::wstring check_wstring = L"check wstring log";
LOGF(L"PATH=" << checkWCHAR << ":" << check_wstring);
#endif

//begin test stream log input....
LOGT("stream input *** " << "LOGT LOGT LOGT LOGT" << " *** ");
Expand Down Expand Up @@ -68,22 +74,6 @@ int main(int argc, char *argv[])

//begin test stream log big string more than buff size input....
LOGD(str);

#ifdef WIN32
// test ANSI->OEM codepage converting, only interesting in Windows environment
// source file contains characters in ANSI CP1251
// log file should contain same coding as source ANSI CP1251
// console output should be OEM 866
// sorry guys, this test is in russian
LOGI("const char[]: ANSI->OEM test, Ýòà ñòðîêà äîëæíà áûòü ÷èòàåìà â ëîãôàéëå (1251) è â êîíñîëè (866)");
LOGT("Stream: " << "ANSI->OEM test, Ýòà ñòðîêà äîëæíà áûòü ÷èòàåìà â ëîãôàéëå (1251) è â êîíñîëè (866)");

//begin test wstring(utf-16) log string input....
WCHAR checkWCHAR[100] = L"ANSI->OEM test, Ýòà ñòðîêà äîëæíà áûòü ÷èòàåìà â ëîãôàéëå (1251)";
std::wstring check_wstring = L"è â êîíñîëè (866)";
LOGI(L"WCHAR[] & wstring: " << checkWCHAR << " " << check_wstring);
#endif

LOGA("main quit ...");
return 0;
}
Expand Down

0 comments on commit b831953

Please sign in to comment.