Date: Thursday, December 21, 2006 @ 22:10:11
Author: marc
Path: /cvsroot/carob/carob/src
Modified: Common.cpp (1.50 -> 1.51)
When using log4cxx, no more duplicating currentLogLevel by us. No more using
log4cxx in static initializers.
------------+
Common.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 48 insertions(+), 10 deletions(-)
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.50 carob/src/Common.cpp:1.51
--- carob/src/Common.cpp:1.50 Thu Dec 21 21:34:34 2006
+++ carob/src/Common.cpp Thu Dec 21 22:10:10 2006
@@ -47,9 +47,12 @@
#include <stdexcept>
#include <locale>
+#if ! defined(CAROB_USE_LOG4CXX)
namespace {
+ /** The current log level (set by setLogLevel) */
CarobNS::LogLevel currentLogLevel = CarobNS::LOG_LEVEL_WARN;
}
+#endif
using std::wstring;
using std::string;
@@ -94,8 +97,9 @@
logger->setLevel(log4cxx::Level::FATAL);
else if (l == LOG_LEVEL_OFF)
logger->setLevel(log4cxx::Level::OFF);
-#endif
+#else
currentLogLevel = l;
+#endif
}
void CarobNS::logDebug(const wstring& fctName, const wstring& s)
@@ -160,25 +164,59 @@
}
}
+namespace {
+/**
+ Special function for logs during initialization
+ can't use LOG4CXX loggers, initialization problem (order?)
+*/
+void logInit(CarobNS::LogLevel level, const wstring& fctName, const wstring& s)
+{
+ // TODO
+ if (level>=CarobNS::LOG_LEVEL_FATAL)
+ wcerr << L'(' << fctName << L") " << s << endl;
+}
+
+}
+
bool CarobNS::isDebugEnabled()
{
+#ifdef CAROB_USE_LOG4CXX
+ return log4cxx::Level::DEBUG->isGreaterOrEqual(logger->getLevel());
+#else
return currentLogLevel <= LOG_LEVEL_DEBUG;
+#endif
}
bool CarobNS::isInfoEnabled()
{
+#ifdef CAROB_USE_LOG4CXX
+ return log4cxx::Level::INFO->isGreaterOrEqual(logger->getLevel());
+#else
return currentLogLevel <= LOG_LEVEL_INFO;
+#endif
}
bool CarobNS::isWarnEnabled()
{
+#ifdef CAROB_USE_LOG4CXX
+ return log4cxx::Level::WARN->isGreaterOrEqual(logger->getLevel());
+#else
return currentLogLevel <= LOG_LEVEL_WARN;
+#endif
}
bool CarobNS::isErrorEnabled()
{
+#ifdef CAROB_USE_LOG4CXX
+ return log4cxx::Level::ERROR->isGreaterOrEqual(logger->getLevel());
+#else
return currentLogLevel <= LOG_LEVEL_ERROR;
+#endif
}
bool CarobNS::isFatalEnabled()
{
+#ifdef CAROB_USE_LOG4CXX
+ return log4cxx::Level::FATAL->isGreaterOrEqual(logger->getLevel());
+#else
return currentLogLevel <= LOG_LEVEL_FATAL;
+#endif
}
wstring CarobNS::trim(const wstring& source,
@@ -209,12 +247,12 @@
// 1. trying hardwired macro
try {
- logInfo(funcname,
+ logInit(LOG_LEVEL_INFO, funcname,
L"1. trying to use locale: " NAME_OF_ANY_UTF8_LOCALE_AVAILABLE);
return trylocale(NAME_OF_ANY_UTF8_LOCALE_AVAILABLE);
} catch (CodecException& ce) {
- logWarn(funcname,
- L"please install the " NAME_OF_ANY_UTF8_LOCALE_AVAILABLE "
locale");
+ logInit(LOG_LEVEL_WARN, funcname,
+ L"please install the " NAME_OF_ANY_UTF8_LOCALE_AVAILABLE "
locale");
}
// 2. try to fallback on the user defined locale
@@ -224,7 +262,7 @@
} catch (std::runtime_error&) {
user_loc = std::locale().name();
}
- logInfo(funcname,
+ logInit(LOG_LEVEL_INFO,funcname,
std::wstring(L"2. trying to fallback on locale: ")
+ fromString(user_loc));
@@ -246,7 +284,7 @@
// out_of_range => not found
}
- logWarn(funcname, fromString(user_loc)
+ logInit(LOG_LEVEL_WARN, funcname, fromString(user_loc)
+ L" does not seem to be an utf8 locale either");
@@ -266,17 +304,17 @@
for (int i=0; i<2; i++)
try {
- logInfo(funcname, std::wstring(L"3n. trying to fall back on locale ")
+ logInit(LOG_LEVEL_INFO, funcname, std::wstring(L"3n. trying to fall
back on locale ")
+ fromString(hacked_names[i]));
return trylocale(hacked_names[i].c_str());
} catch (CodecException&) {
- logWarn(funcname,
+ logInit(LOG_LEVEL_WARN, funcname,
std::wstring(L"or please install locale ")
+ fromString(hacked_names[i]));
}
// 4. nothing found
- logFatal(funcname,
+ logInit(LOG_LEVEL_FATAL, funcname,
std::wstring(L"Please install one of the following locales: "
NAME_OF_ANY_UTF8_LOCALE_AVAILABLE ", ")
+ fromString(user_loc) + L", "
@@ -299,7 +337,7 @@
try {
return std::locale("");
} catch (std::runtime_error& ) {
- logWarn(__WFILE__ L":tryuserlocale()",
+ logInit(LOG_LEVEL_WARN, __WFILE__ L":tryuserlocale()",
L"Missing user-preferred locale (check LANG). "
"Falling back on current global locale.");
return std::locale();
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits