Author: carnold
Date: Tue Oct 2 09:05:32 2007
New Revision: 581289
URL: http://svn.apache.org/viewvc?rev=581289&view=rev
Log:
LOGCXX-184: Crash when log level set to inherited
Added:
logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp
Modified:
logging/log4cxx/trunk/src/main/cpp/properties.cpp
logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/helpers/properties.h
logging/log4cxx/trunk/src/test/cpp/Makefile.am
Modified: logging/log4cxx/trunk/src/main/cpp/properties.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/properties.cpp?rev=581289&r1=581288&r2=581289&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/properties.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/properties.cpp Tue Oct 2 09:05:32 2007
@@ -314,7 +314,17 @@
LexemType;
};
-LogString Properties::setProperty(const LogString& key, const LogString& value)
+Properties::Properties() {
+}
+
+Properties::~Properties() {
+}
+
+LogString Properties::setProperty(const LogString& key, const LogString&
value) {
+ return put(key, value);
+}
+
+LogString Properties::put(const LogString& key, const LogString& value)
{
LogString oldValue(properties[key]);
properties[key] = value;
@@ -322,7 +332,11 @@
return oldValue;
}
-LogString Properties::getProperty(const LogString& key) const
+LogString Properties::getProperty(const LogString& key) const {
+ return get(key);
+}
+
+LogString Properties::get(const LogString& key) const
{
std::map<LogString, LogString>::const_iterator it =
properties.find(key);
return (it != properties.end()) ? it->second : LogString();
Modified: logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp?rev=581289&r1=581288&r2=581289&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp Tue Oct 2
09:05:32 2007
@@ -323,16 +323,19 @@
else
{
logger->setLevel(0);
+ LogLog::debug((LogString) LOG4CXX_STR("Logger
")
+ + loggerName + LOG4CXX_STR(" set to
null"));
}
}
else
{
logger->setLevel(OptionConverter::toLevel(levelStr,
Level::getDebug()));
+
+ LogLog::debug((LogString) LOG4CXX_STR("Logger ")
+ + loggerName + LOG4CXX_STR(" set to ")
+ + logger->getLevel()->toString());
}
- LogLog::debug((LogString) LOG4CXX_STR("Logger ")
- + loggerName + LOG4CXX_STR(" set to ")
- + logger->getLevel()->toString());
}
// Begin by removing all existing appenders.
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/properties.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/properties.h?rev=581289&r1=581288&r2=581289&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/properties.h
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/properties.h Tue Oct
2 09:05:32 2007
@@ -35,9 +35,19 @@
private:
typedef std::map<LogString, LogString> PropertyMap;
PropertyMap properties;
+ Properties(const Properties&);
+ Properties& operator=(const Properties&);
public:
/**
+ * Create new instance.
+ */
+ Properties();
+ /**
+ * Destructor.
+ */
+ ~Properties();
+ /**
Reads a property list (key and element pairs) from the
input stream.
The stream is assumed to be using the ISO 8859-1
character encoding.
@@ -117,28 +127,37 @@
void load(InputStreamPtr inStream);
/**
- Calls the Hashtable method put. Provided for
parallelism with the
- getProperty method. Enforces use of strings for
property keys and
- values. The value returned is the result of the
Hashtable call to
- put.
- @param key the key to be placed into this property
list.
- @param value the value corresponding to key.
- @return the previous value of the specified key in this
- property list, or an empty string if it did not have
one.
+ * Calls Properties::put.
+ * @param key the key to be placed into this
property list.
+ * @param value the value corresponding to key.
+ * @return the previous value of the specified key
in this
+ * property list, or an empty string if it did not
have one.
*/
LogString setProperty(const LogString& key, const
LogString& value);
+ /**
+ * Puts a property value into the collection.
+ * @param key the key to be placed into this
property list.
+ * @param value the value corresponding to key.
+ * @return the previous value of the specified key
in this
+ * property list, or an empty string if it did not
have one.
+ */
+ LogString put(const LogString& key, const LogString&
value);
/**
- Searches for the property with the specified key in
this property
- list. If the key is not found in this property list,
the default
- property list, and its defaults, recursively, are then
checked.
- The method returns an empty string if the property is
not found.
- @param key the property key.
- @return the value in this property list with the specified
- key value.
+ * Calls Properties::get.
+ * @param key the property key.
+ * @return the value in this property list with the
specified
+ * key value or empty string.
*/
LogString getProperty(const LogString& key) const;
+ /**
+ * Gets a property value.
+ * @param key the property key.
+ * @return the value in this property list with the
specified
+ * key value or empty string.
+ */
+ LogString get(const LogString& key) const;
/**
Returns an enumeration of all the keys in this
property list,
Modified: logging/log4cxx/trunk/src/test/cpp/Makefile.am
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/Makefile.am?rev=581289&r1=581288&r2=581289&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/Makefile.am (original)
+++ logging/log4cxx/trunk/src/test/cpp/Makefile.am Tue Oct 2 09:05:32 2007
@@ -146,7 +146,8 @@
rollingfileappendertestcase.cpp\
streamtestcase.cpp\
writerappendertestcase.cpp \
- ndctestcase.cpp
+ ndctestcase.cpp \
+ propertyconfiguratortest.cpp
testsuite_LDADD = \
$(top_builddir)/src/main/cpp/liblog4cxx.la
Added: logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp?rev=581289&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp (added)
+++ logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp Tue Oct 2
09:05:32 2007
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <log4cxx/helpers/properties.h>
+#include <log4cxx/propertyconfigurator.h>
+#include <log4cxx/logmanager.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+
+class PropertyConfiguratorTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(PropertyConfiguratorTest);
+ CPPUNIT_TEST(testInherited);
+ CPPUNIT_TEST(testNull);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void testInherited() {
+ Properties props;
+
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
+
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
LOG4CXX_STR("inherited,VECTOR2"));
+ props.put(LOG4CXX_STR("log4j.appender.VECTOR1"),
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+ props.put(LOG4CXX_STR("log4j.appender.VECTOR2"),
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+ PropertyConfigurator::configure(props);
+ LoggerPtr logger =
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
+ CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
+ logger->getEffectiveLevel()->toInt());
+ Logger::getRootLogger()->setLevel(Level::getError());
+ CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
+ logger->getEffectiveLevel()->toInt());
+ LogManager::resetConfiguration();
+ }
+
+ void testNull() {
+ Properties props;
+
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
+
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
LOG4CXX_STR("NuLL,VECTOR2"));
+ props.put(LOG4CXX_STR("log4j.appender.VECTOR1"),
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+ props.put(LOG4CXX_STR("log4j.appender.VECTOR2"),
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+ PropertyConfigurator::configure(props);
+ LoggerPtr logger =
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
+ CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
+ logger->getEffectiveLevel()->toInt());
+ Logger::getRootLogger()->setLevel(Level::getError());
+ CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
+ logger->getEffectiveLevel()->toInt());
+ LogManager::resetConfiguration();
+ }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PropertyConfiguratorTest);