You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2017/06/09 13:27:37 UTC
logging-log4cxx git commit: LOGCXX-488: Loglevels with space at the
end from e.g. config files were not handled properly. Added a test and fixed
the problem itself,
as StringHelper::trim was already available. Focussing on the case with spaces
at the end
Repository: logging-log4cxx
Updated Branches:
refs/heads/master 03c581216 -> f043526b3
LOGCXX-488: Loglevels with space at the end from e.g. config files were
not handled properly. Added a test and fixed the problem itself, as
StringHelper::trim was already available. Focussing on the case with
spaces at the end no, though, because "trim" doesn't seem to support more.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/commit/f043526b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/tree/f043526b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/diff/f043526b
Branch: refs/heads/master
Commit: f043526b3d27e16680f551e4c1238a7fefaa6dc9
Parents: 03c5812
Author: Thorsten Schöning <ts...@am-soft.de>
Authored: Fri Jun 9 15:25:55 2017 +0200
Committer: Thorsten Schöning <ts...@am-soft.de>
Committed: Fri Jun 9 15:25:55 2017 +0200
----------------------------------------------------------------------
src/main/cpp/level.cpp | 19 ++++++++++---------
src/test/cpp/leveltestcase.cpp | 24 ++++++++++++++++--------
2 files changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/f043526b/src/main/cpp/level.cpp
----------------------------------------------------------------------
diff --git a/src/main/cpp/level.cpp b/src/main/cpp/level.cpp
index 953b27a..ce679a4 100644
--- a/src/main/cpp/level.cpp
+++ b/src/main/cpp/level.cpp
@@ -175,35 +175,36 @@ void Level::toString(CFStringRef& dst) const {
LevelPtr Level::toLevelLS(const LogString& sArg, const LevelPtr& defaultLevel)
{
- const size_t len = sArg.length();
+ const LogString trimmed(StringHelper::trim(sArg));
+ const size_t len = trimmed.length();
if (len == 4) {
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("INFO"), LOG4CXX_STR("info"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("INFO"), LOG4CXX_STR("info"))) {
return getInfo();
}
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("WARN"), LOG4CXX_STR("warn"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("WARN"), LOG4CXX_STR("warn"))) {
return getWarn();
}
} else {
if (len == 5) {
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("DEBUG"), LOG4CXX_STR("debug"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("DEBUG"), LOG4CXX_STR("debug"))) {
return getDebug();
}
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("TRACE"), LOG4CXX_STR("trace"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("TRACE"), LOG4CXX_STR("trace"))) {
return getTrace();
}
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("ERROR"), LOG4CXX_STR("error"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("ERROR"), LOG4CXX_STR("error"))) {
return getError();
}
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("FATAL"), LOG4CXX_STR("fatal"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("FATAL"), LOG4CXX_STR("fatal"))) {
return getFatal();
}
} else {
if (len == 3) {
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("OFF"), LOG4CXX_STR("off"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("OFF"), LOG4CXX_STR("off"))) {
return getOff();
}
- if (StringHelper::equalsIgnoreCase(sArg, LOG4CXX_STR("ALL"), LOG4CXX_STR("all"))) {
+ if (StringHelper::equalsIgnoreCase(trimmed, LOG4CXX_STR("ALL"), LOG4CXX_STR("all"))) {
return getAll();
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/f043526b/src/test/cpp/leveltestcase.cpp
----------------------------------------------------------------------
diff --git a/src/test/cpp/leveltestcase.cpp b/src/test/cpp/leveltestcase.cpp
index 15893ae..7de78aa 100644
--- a/src/test/cpp/leveltestcase.cpp
+++ b/src/test/cpp/leveltestcase.cpp
@@ -36,13 +36,14 @@ LOGUNIT_CLASS(LevelTestCase)
LOGUNIT_TEST(testStringToTrace);
#if LOG4CXX_WCHAR_T_API
LOGUNIT_TEST(testWideStringToTrace);
-#endif
+#endif
#if LOG4CXX_UNICHAR_API
LOGUNIT_TEST(testUniCharStringToTrace);
-#endif
+#endif
#if LOG4CXX_CFSTRING_API
LOGUNIT_TEST(testCFStringToTrace);
-#endif
+#endif
+ LOGUNIT_TEST(testTrimmedToTrace);
LOGUNIT_TEST_SUITE_END();
public:
@@ -51,7 +52,7 @@ public:
LevelPtr level(Level::toLevel(LOG4CXX_TEST_STR("fATal")));
LOGUNIT_ASSERT_EQUAL((int) Level::FATAL_INT, level->toInt());
}
-
+
/**
* Tests Level::TRACE_INT.
*/
@@ -92,7 +93,7 @@ public:
LevelPtr trace(Level::toLevel(L"TRACE"));
LOGUNIT_ASSERT(trace->toString() == LOG4CXX_STR("TRACE"));
}
-#endif
+#endif
#if LOG4CXX_UNICHAR_API
/**
@@ -103,7 +104,7 @@ public:
LevelPtr trace(Level::toLevel(name));
LOGUNIT_ASSERT(trace->toString() == LOG4CXX_STR("TRACE"));
}
-#endif
+#endif
#if LOG4CXX_CFSTRING_API
/**
@@ -113,8 +114,15 @@ public:
LevelPtr trace(Level::toLevel(CFSTR("TRACE")));
LOGUNIT_ASSERT(trace->toString() == LOG4CXX_STR("TRACE"));
}
-#endif
-
+#endif
+
+ /**
+ * Tests Level.toLevel("TRACE ");
+ */
+ void testTrimmedToTrace() {
+ LevelPtr trace(Level::toLevel("TRACE "));
+ LOGUNIT_ASSERT(trace->toString() == LOG4CXX_STR("TRACE"));
+ }
};