Skip to content

Commit

Permalink
Tune ANSI->OEM, now configurable, off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
n506 committed Dec 13, 2015
1 parent bc5bb7b commit 1dd4299
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions log4z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,14 +1163,14 @@ LogerManager::~LogerManager()
void LogerManager::showColorText(const char *text, int level)
{

#ifdef WIN32
#if defined(WIN32) && defined(LOG4Z_OEM_CONSOLE)
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
#if defined(WIN32) && defined(LOG4Z_OEM_CONSOLE)
printf("%s", oem);
#else
printf("%s", text);
Expand All @@ -1191,8 +1191,12 @@ void LogerManager::showColorText(const char *text, int level)
else
{
SetConsoleTextAttribute(hStd, LOG_COLOR[level]);
printf("%s", oem);
SetConsoleTextAttribute(hStd, oldInfo.wAttributes);
#ifdef LOG4Z_OEM_CONSOLE
printf("%s", oem);
#else
printf("%s", text);
#endif
SetConsoleTextAttribute(hStd, oldInfo.wAttributes);
}
#endif
return;
Expand Down
8 changes: 5 additions & 3 deletions log4z.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ 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;
//! support ANSI->OEM console conversion on Windows
#undef LOG4Z_OEM_CONSOLE
///////////////////////////////////////////////////////////////////////////
//! -----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -333,7 +335,7 @@ _ZSUMMER_END



//! base micro.
//! base macro.
#define LOG_STREAM(id, level, log)\
do{\
if (zsummer::log4z::ILog4zManager::getPtr()->prePushLog(id,level)) \
Expand All @@ -346,7 +348,7 @@ do{\
} while (0)


//! fast micro
//! fast macro
#define LOG_TRACE(id, log) LOG_STREAM(id, LOG_LEVEL_TRACE, log)
#define LOG_DEBUG(id, log) LOG_STREAM(id, LOG_LEVEL_DEBUG, log)
#define LOG_INFO(id, log) LOG_STREAM(id, LOG_LEVEL_INFO, log)
Expand All @@ -355,7 +357,7 @@ do{\
#define LOG_ALARM(id, log) LOG_STREAM(id, LOG_LEVEL_ALARM, log)
#define LOG_FATAL(id, log) LOG_STREAM(id, LOG_LEVEL_FATAL, log)

//! super micro.
//! super macro.
#define LOGT( log ) LOG_TRACE(LOG4Z_MAIN_LOGGER_ID, log )
#define LOGD( log ) LOG_DEBUG(LOG4Z_MAIN_LOGGER_ID, log )
#define LOGI( log ) LOG_INFO(LOG4Z_MAIN_LOGGER_ID, log )
Expand Down

0 comments on commit 1dd4299

Please sign in to comment.