Date: Tuesday, February 28, 2006 @ 11:59:54
  Author: gilles
    Path: /cvsroot/carob/carob/src

Modified: Common.cpp (1.25 -> 1.26)

Added double check on logLevel before logging
Removed common logging function that has become obsolete since log4cxx addition


------------+
 Common.cpp |  102 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 46 insertions(+), 56 deletions(-)


Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.25 carob/src/Common.cpp:1.26
--- carob/src/Common.cpp:1.25   Tue Feb 14 18:35:47 2006
+++ carob/src/Common.cpp        Tue Feb 28 11:59:54 2006
@@ -64,57 +64,6 @@
 
 #define NAME_OF_ANY_UTF8_LOCALE_AVAILABLE "en_US.utf8"
 
-namespace {
-  inline void
-  carobLog(const CarobNS::LogLevel& level, const wstring& fctName, const 
wstring& msg)
-  {
-#ifdef CAROB_USE_LOG4CXX
-    // Log4cxx <= 0.9.7 doesn't accept wstrings - we have to convert the string
-    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + msg);
-#endif
-    if (level == CarobNS::LOG_LEVEL_DEBUG)
-    {
-#ifdef CAROB_USE_LOG4CXX
-      LOG4CXX_DEBUG(logger, tmp);
-#else
-      wcerr << DEBUG_PRE << L'(' << fctName << L") " << msg << endl;
-#endif
-    }
-    else if (level == CarobNS::LOG_LEVEL_INFO)
-    {
-#ifdef CAROB_USE_LOG4CXX
-      LOG4CXX_INFO(logger, tmp);
-#else
-      wcerr << INFO_PRE << L'(' << fctName << L") " << msg << endl;
-#endif
-    }
-    else if (level == CarobNS::LOG_LEVEL_WARN)
-    {
-#ifdef CAROB_USE_LOG4CXX
-      LOG4CXX_WARN(logger, tmp);
-#else
-      wcerr << WARN_PRE << L'(' << fctName << L") " << msg << endl;
-#endif
-    }
-    else if (level == CarobNS::LOG_LEVEL_ERROR)
-    {
-#ifdef CAROB_USE_LOG4CXX
-      LOG4CXX_ERROR(logger, tmp);
-#else
-      wcerr << ERROR_PRE << L'(' << fctName << L") " << msg << endl;
-#endif
-    }
-    else //if (level == CarobNS::LOG_LEVEL_FATAL)
-    {
-#ifdef CAROB_USE_LOG4CXX
-      LOG4CXX_FATAL(logger, tmp);
-#else
-      wcerr << FATAL_PRE << L'(' << fctName << L") " << msg << endl;
-#endif
-    }
-  }
-}
-
 void CarobNS::setLogLevel(const LogLevel l)
 {
 #ifdef CAROB_USE_LOG4CXX
@@ -136,23 +85,64 @@
 
 void CarobNS::logDebug(const wstring& fctName, const wstring& s)
 {
-  carobLog(LOG_LEVEL_DEBUG, fctName, s);
+  if (isDebugEnabled())
+  {
+#ifdef CAROB_USE_LOG4CXX
+    // Log4cxx <= 0.9.7 doesn't accept wstrings - we have to convert the string
+    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + s);
+    LOG4CXX_DEBUG(logger, tmp);
+#else
+    wcerr << DEBUG_PRE << L'(' << fctName << L") " << s << endl;
+#endif
+  }
 }
 void CarobNS::logInfo(const wstring& fctName, const wstring& s)
 {
-  carobLog(LOG_LEVEL_INFO, fctName, s);
+  if (isInfoEnabled())
+  {
+#ifdef CAROB_USE_LOG4CXX
+    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + s);
+    LOG4CXX_INFO(logger, tmp);
+#else
+    wcerr << INFO_PRE << L'(' << fctName << L") " << s << endl;
+#endif
+  }
 }
 void CarobNS::logWarn(const wstring& fctName, const wstring& s)
 {
-  carobLog(LOG_LEVEL_WARN, fctName, s);
+  if (isWarnEnabled())
+  {
+#ifdef CAROB_USE_LOG4CXX
+    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + s);
+    LOG4CXX_WARN(logger, tmp);
+#else
+    wcerr << WARN_PRE << L'(' << fctName << L") " << s << endl;
+#endif
+  }
 }
 void CarobNS::logError(const wstring& fctName, const wstring& s)
 {
-  carobLog(LOG_LEVEL_ERROR, fctName, s);
+  if (isErrorEnabled())
+  {
+#ifdef CAROB_USE_LOG4CXX
+    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + s);
+    LOG4CXX_ERROR(logger, tmp);
+#else
+    wcerr << ERROR_PRE << L'(' << fctName << L") " << s << endl;
+#endif
+  }
 }
 void CarobNS::logFatal(const wstring& fctName, const wstring& s)
 {
-  carobLog(LOG_LEVEL_FATAL, fctName, s);
+  if (isFatalEnabled())
+  {
+#ifdef CAROB_USE_LOG4CXX
+    std::string tmp = CarobNS::StaticCodecs::toString(fctName + L": " + s);
+    LOG4CXX_FATAL(logger, tmp);
+#else
+    wcerr << FATAL_PRE << L'(' << fctName << L") " << s << endl;
+#endif
+  }
 }
 
 bool CarobNS::isDebugEnabled()

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to