This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 2584214 Add short filename to location info (#95)
2584214 is described below
commit 2584214e32e9aa3e0cfd6e320bf7ea6a275326de
Author: Robert Middleton <[email protected]>
AuthorDate: Thu Jan 6 17:09:46 2022 -0500
Add short filename to location info (#95)
Add short filename to location info.
If supported by the current compiler, the short filename will be calculated
using a constexpr string_view. Runtime overhead should thus be minimal.
Co-authored-by: cc <[email protected]>
---
src/main/cpp-qt/messagehandler.cpp | 5 +-
src/main/cpp/CMakeLists.txt | 5 +-
src/main/cpp/locationinfo.cpp | 8 +++
src/main/cpp/patternlayout.cpp | 3 +
src/main/cpp/shortfilelocationpatternconverter.cpp | 49 ++++++++++++++
.../pattern/shortfilelocationpatternconverter.h | 67 +++++++++++++++++++
src/main/include/log4cxx/patternlayout.h | 6 ++
.../include/log4cxx/spi/location/locationinfo.h | 52 +++++++++++++--
src/site/markdown/usage.md | 10 +++
src/test/cpp/CMakeLists.txt | 4 ++
src/test/cpp/jsonlayouttest.cpp | 8 +--
src/test/cpp/locationdisabledtest.cpp | 75 ++++++++++++++++++++++
src/test/cpp/locationtest.cpp | 75 ++++++++++++++++++++++
src/test/cpp/patternlayouttest.cpp | 8 +++
src/test/cpp/rolling/timebasedrollingtest.cpp | 2 +
src/test/cpp/throughput/CMakeLists.txt | 2 +
src/test/resources/input/location1.properties | 21 ++++++
.../resources/input/locationdisabled.properties | 21 ++++++
.../resources/input/patternLayout14.properties | 21 ++++++
src/test/resources/witness/location1-disabled | 1 +
src/test/resources/witness/location1-good | 1 +
src/test/resources/witness/patternLayout.14 | 10 +++
22 files changed, 442 insertions(+), 12 deletions(-)
diff --git a/src/main/cpp-qt/messagehandler.cpp
b/src/main/cpp-qt/messagehandler.cpp
index 4946602..aa0de1d 100644
--- a/src/main/cpp-qt/messagehandler.cpp
+++ b/src/main/cpp-qt/messagehandler.cpp
@@ -24,7 +24,10 @@ namespace qt {
void messageHandler(QtMsgType type, const QMessageLogContext& context, const
QString& message )
{
log4cxx::LoggerPtr qtLogger = log4cxx::Logger::getLogger(
context.category );
- log4cxx::spi::LocationInfo location( context.file, context.function,
context.line );
+ log4cxx::spi::LocationInfo location( context.file,
+
log4cxx::spi::LocationInfo::calcShortFileName(context.file),
+
context.function,
+
context.line );
switch ( type )
{
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 9bb0765..66d3460 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -30,8 +30,8 @@ target_sources(log4cxx
class.cpp
classnamepatternconverter.cpp
classregistration.cpp
- colorstartpatternconverter.cpp
- colorendpatternconverter.cpp
+ colorstartpatternconverter.cpp
+ colorendpatternconverter.cpp
configurator.cpp
consoleappender.cpp
cyclicbuffer.cpp
@@ -127,6 +127,7 @@ target_sources(log4cxx
rolloverdescription.cpp
rootlogger.cpp
serversocket.cpp
+ shortfilelocationpatternconverter.cpp
simpledateformat.cpp
simplelayout.cpp
sizebasedtriggeringpolicy.cpp
diff --git a/src/main/cpp/locationinfo.cpp b/src/main/cpp/locationinfo.cpp
index 6106687..a6a74cb 100644
--- a/src/main/cpp/locationinfo.cpp
+++ b/src/main/cpp/locationinfo.cpp
@@ -41,10 +41,12 @@ const LocationInfo& LocationInfo::getLocationUnavailable()
* location info for current code site
*/
LocationInfo::LocationInfo( const char* const fileName1,
+ const char* const shortFileName1,
const char* const methodName1,
int lineNumber1 )
: lineNumber( lineNumber1 ),
fileName( fileName1 ),
+ shortFileName(shortFileName1),
methodName( methodName1 )
{
}
@@ -55,6 +57,7 @@ LocationInfo::LocationInfo( const char* const fileName1,
LocationInfo::LocationInfo()
: lineNumber( -1 ),
fileName(LocationInfo::NA),
+ shortFileName(LocationInfo::NA),
methodName(LocationInfo::NA_METHOD)
{
}
@@ -66,6 +69,7 @@ LocationInfo::LocationInfo()
LocationInfo::LocationInfo( const LocationInfo& src )
: lineNumber( src.lineNumber ),
fileName( src.fileName ),
+ shortFileName( src.shortFileName ),
methodName( src.methodName )
{
}
@@ -102,6 +106,10 @@ const char* LocationInfo::getFileName() const
return fileName;
}
+const char* LocationInfo::getShortFileName() const{
+ return shortFileName;
+}
+
/**
* Returns the line number of the caller.
* @returns line number, -1 if not available.
diff --git a/src/main/cpp/patternlayout.cpp b/src/main/cpp/patternlayout.cpp
index 11d59e0..3070085 100644
--- a/src/main/cpp/patternlayout.cpp
+++ b/src/main/cpp/patternlayout.cpp
@@ -30,6 +30,7 @@
#include <log4cxx/pattern/loggerpatternconverter.h>
#include <log4cxx/pattern/colorendpatternconverter.h>
#include <log4cxx/pattern/colorstartpatternconverter.h>
+#include <log4cxx/pattern/shortfilelocationpatternconverter.h>
#include <log4cxx/pattern/literalpatternconverter.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/pattern/classnamepatternconverter.h>
@@ -162,6 +163,8 @@ log4cxx::pattern::PatternMap
PatternLayout::getFormatSpecifiers()
RULES_PUT("d", DatePatternConverter);
RULES_PUT("date", DatePatternConverter);
+ RULES_PUT("f", ShortFileLocationPatternConverter);
+
RULES_PUT("F", FileLocationPatternConverter);
RULES_PUT("file", FileLocationPatternConverter);
diff --git a/src/main/cpp/shortfilelocationpatternconverter.cpp
b/src/main/cpp/shortfilelocationpatternconverter.cpp
new file mode 100644
index 0000000..2de8b6e
--- /dev/null
+++ b/src/main/cpp/shortfilelocationpatternconverter.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+#if defined(_MSC_VER)
+#pragma warning ( disable: 4231 4251 4275 4786 )
+#endif
+
+#include <log4cxx/logstring.h>
+#include <log4cxx/pattern/shortfilelocationpatternconverter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/spi/location/locationinfo.h>
+
+using namespace log4cxx;
+using namespace log4cxx::pattern;
+using namespace log4cxx::spi;
+using namespace helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(ShortFileLocationPatternConverter)
+
+ShortFileLocationPatternConverter::ShortFileLocationPatternConverter() :
+ LoggingEventPatternConverter(LOG4CXX_STR("Short File Location"),
+ LOG4CXX_STR("shortFile")) {
+}
+
+PatternConverterPtr ShortFileLocationPatternConverter::newInstance(
+ const std::vector<LogString> & /* options */ ) {
+ static PatternConverterPtr instance(new ShortFileLocationPatternConverter());
+ return instance;
+}
+
+void ShortFileLocationPatternConverter::format(
+ const LoggingEventPtr &event,
+ LogString &toAppendTo,
+ Pool & /* p */ ) const {
+ append(toAppendTo, event->getLocationInformation().getShortFileName());
+}
diff --git
a/src/main/include/log4cxx/pattern/shortfilelocationpatternconverter.h
b/src/main/include/log4cxx/pattern/shortfilelocationpatternconverter.h
new file mode 100644
index 0000000..db17d0b
--- /dev/null
+++ b/src/main/include/log4cxx/pattern/shortfilelocationpatternconverter.h
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#ifndef _LOG4CXX_PATTERN_SHORT_FILE_LOCATION_PATTERN_CONVERTER
+#define _LOG4CXX_PATTERN_SHORT_FILE_LOCATION_PATTERN_CONVERTER
+
+#include <log4cxx/pattern/loggingeventpatternconverter.h>
+
+namespace log4cxx
+{
+namespace pattern
+{
+
+
+/**
+ * Return the event's line location information in a StringBuffer.
+ *
+ *
+ *
+ */
+class LOG4CXX_EXPORT ShortFileLocationPatternConverter
+ : public LoggingEventPatternConverter
+{
+ /**
+ * Private constructor.
+ */
+ ShortFileLocationPatternConverter();
+
+ public:
+ DECLARE_LOG4CXX_PATTERN(ShortFileLocationPatternConverter)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(ShortFileLocationPatternConverter)
+ LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter)
+ END_LOG4CXX_CAST_MAP()
+
+ /**
+ * Obtains an instance of pattern converter.
+ * @param options options, may be null.
+ * @return instance of pattern converter.
+ */
+ static PatternConverterPtr newInstance(
+ const std::vector<LogString>& options);
+
+ using LoggingEventPatternConverter::format;
+
+ void format(const log4cxx::spi::LoggingEventPtr& event,
+ LogString& toAppendTo,
+ log4cxx::helpers::Pool& p) const;
+};
+
+}
+}
+#endif
diff --git a/src/main/include/log4cxx/patternlayout.h
b/src/main/include/log4cxx/patternlayout.h
index 552d962..7b695d7 100644
--- a/src/main/include/log4cxx/patternlayout.h
+++ b/src/main/include/log4cxx/patternlayout.h
@@ -134,6 +134,12 @@ LOG4CXX_LIST_DEF(FormattingInfoList,
log4cxx::pattern::FormattingInfoPtr);
* </td>
* </tr>
* <tr>
+ * <td align="center"><strong>f</strong></td>
+ * <td>
+ * Used to output the short file name where the logging request was
issued.
+ * </td>
+ * </tr>
+ * <tr>
* <td align="center"><strong>F</strong></td>
* <td>
* Used to output the file name where the logging request was issued.
diff --git a/src/main/include/log4cxx/spi/location/locationinfo.h
b/src/main/include/log4cxx/spi/location/locationinfo.h
index 6616780..51b1ce4 100644
--- a/src/main/include/log4cxx/spi/location/locationinfo.h
+++ b/src/main/include/log4cxx/spi/location/locationinfo.h
@@ -22,6 +22,19 @@
#include <string>
#include <log4cxx/helpers/objectoutputstream.h>
+#if __cpp_lib_string_view || (_MSVC_LANG >= 201703L)
+#include <string_view>
+#define LOG4CXX_HAS_STRING_VIEW
+#else
+#include <string.h>
+#endif
+
+#if defined(_WIN32)
+#define LOG4CXX_SHORT_FILENAME_SPLIT_CHAR '\\'
+#else
+#define LOG4CXX_SHORT_FILENAME_SPLIT_CHAR '/'
+#endif
+
namespace log4cxx
{
namespace spi
@@ -45,7 +58,19 @@ class LOG4CXX_EXPORT LocationInfo
static const LocationInfo& getLocationUnavailable();
-
+#ifdef LOG4CXX_HAS_STRING_VIEW
+ static constexpr const char* calcShortFileName(const char*
fileName){
+ std::string_view view(fileName);
+ // If the separator is not found, rfind will return -1.
Adding 1 to
+ // that will have it pointing at fileName, which is a
good fallback.
+ return fileName +
view.rfind(LOG4CXX_SHORT_FILENAME_SPLIT_CHAR) + 1;
+ }
+#else
+ static const char* calcShortFileName(const char* fileName){
+ const char* location = strrchr(fileName,
LOG4CXX_SHORT_FILENAME_SPLIT_CHAR);
+ return location == nullptr ? fileName : location + 1;
+ }
+#endif
/**
* Constructor.
@@ -53,8 +78,9 @@ class LOG4CXX_EXPORT LocationInfo
* location info for current code site
*/
LocationInfo( const char* const fileName,
- const char* const functionName,
- int lineNumber);
+ const char* const shortFileName,
+ const char* const functionName,
+ int lineNumber);
/**
* Default constructor.
@@ -89,6 +115,13 @@ class LOG4CXX_EXPORT LocationInfo
const char* getFileName() const;
/**
+ * Return the short file name of the caller.
+ * @returns file name. Note that this will fallback to the
full filename when using
+ * calcShortFileName to calculate the filename at
compile-time.
+ */
+ const char* getShortFileName() const;
+
+ /**
* Returns the line number of the caller.
* @returns line number, -1 if not available.
*/
@@ -107,6 +140,9 @@ class LOG4CXX_EXPORT LocationInfo
/** Caller's file name. */
const char* fileName;
+ /** Caller's short file name. */
+ const char* shortFileName;
+
/** Caller's method name. */
const char* methodName;
@@ -115,7 +151,7 @@ class LOG4CXX_EXPORT LocationInfo
}
}
-#if !defined(LOG4CXX_LOCATION)
+#if !defined(LOG4CXX_LOCATION) && !LOG4CXX_DISABLE_LOCATION_INFO
#if defined(_MSC_VER)
#if _MSC_VER >= 1300
#define __LOG4CXX_FUNC__ __FUNCSIG__
@@ -132,9 +168,15 @@ class LOG4CXX_EXPORT LocationInfo
#if !defined(__LOG4CXX_FUNC__)
#define __LOG4CXX_FUNC__ ""
#endif
+
+
#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo(__FILE__, \
+ ::log4cxx::spi::LocationInfo::calcShortFileName(__FILE__), \
__LOG4CXX_FUNC__, \
__LINE__)
-#endif
+
+#else
+#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo::getLocationUnavailable()
+#endif // LOG4CXX_LOCATION
#endif //_LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md
index 0536f83..232aa7c 100644
--- a/src/site/markdown/usage.md
+++ b/src/site/markdown/usage.md
@@ -765,6 +765,16 @@ The levels are set as follows:
Note that this has no effect on other macros, such as using the
`LOG4CXX_LOG`, `LOG4CXX_LOGLS`, or `LOG4CXX_L7DLOG` family of macros.
+# Removing location information {#removing-location information}
+
+Whenever you log a message with Log4cxx, metadata about the location of the
+logging statement is captured as well through the preprocessor. This includes
+the file name, the method name, and the line number. If you would not like to
+include this information in your build but you still wish to keep the log
+statements, define `LOG4CXX_DISABLE_LOCATION_INFO` in your build system. This
+will allow log messages to still be created, but the location information
+will be invalid.
+
# Logging Custom Types {#custom-types}
Often, the data that needs to be logged is not just standard data types
diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt
index 11701da..bd985f9 100644
--- a/src/test/cpp/CMakeLists.txt
+++ b/src/test/cpp/CMakeLists.txt
@@ -38,6 +38,8 @@ set(ALL_LOG4CXX_TESTS
rollingfileappendertestcase
streamtestcase
multithreadtest
+ locationtest
+ locationdisabledtest
)
foreach(fileName IN LISTS ALL_LOG4CXX_TESTS)
add_executable(${fileName} "${fileName}.cpp")
@@ -129,3 +131,5 @@ foreach(testName IN LISTS ALL_LOG4CXX_TESTS)
endif()
endif()
endforeach()
+
+target_compile_definitions(locationdisabledtest PRIVATE
LOG4CXX_DISABLE_LOCATION_INFO)
diff --git a/src/test/cpp/jsonlayouttest.cpp b/src/test/cpp/jsonlayouttest.cpp
index 8e99b99..5ddc6b9 100644
--- a/src/test/cpp/jsonlayouttest.cpp
+++ b/src/test/cpp/jsonlayouttest.cpp
@@ -285,7 +285,7 @@ public:
LoggingEventPtr event1 = LoggingEventPtr(new
LoggingEvent(LOG4CXX_STR("Logger"),
Level::getInfo(),
LOG4CXX_STR("A message goes here."),
- spi::LocationInfo("FooFile", "BarFunc",
42)));
+ spi::LocationInfo("FooFile", "FooFile",
"BarFunc", 42)));
LogString output1;
LogString expected1;
@@ -311,7 +311,7 @@ public:
LoggingEventPtr event1 = LoggingEventPtr(new
LoggingEvent(LOG4CXX_STR("Logger"),
Level::getInfo(),
LOG4CXX_STR("A message goes here."),
- spi::LocationInfo("FooFile", "BarFunc",
42)));
+ spi::LocationInfo("FooFile", "FooFile",
"BarFunc", 42)));
LogString output1;
LogString expected1;
@@ -351,7 +351,7 @@ public:
LoggingEventPtr event1 = LoggingEventPtr(new
LoggingEvent(LOG4CXX_STR("Logger"),
Level::getInfo(),
LOG4CXX_STR("A message goes here."),
- spi::LocationInfo("FooFile", "BarFunc",
42)));
+ spi::LocationInfo("FooFile", "FooFile",
"BarFunc", 42)));
LogString timestamp;
helpers::ISO8601DateFormat dateFormat;
@@ -399,7 +399,7 @@ public:
LoggingEventPtr event1 = LoggingEventPtr(new
LoggingEvent(LOG4CXX_STR("Logger"),
Level::getInfo(),
LOG4CXX_STR("A message goes here."),
- spi::LocationInfo("FooFile", "BarFunc",
42)));
+ spi::LocationInfo("FooFile", "FooFile",
"BarFunc", 42)));
LogString timestamp;
helpers::ISO8601DateFormat dateFormat;
diff --git a/src/test/cpp/locationdisabledtest.cpp
b/src/test/cpp/locationdisabledtest.cpp
new file mode 100644
index 0000000..fa682f6
--- /dev/null
+++ b/src/test/cpp/locationdisabledtest.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 <log4cxx/logger.h>
+#include <log4cxx/propertyconfigurator.h>
+
+#include "testchar.h"
+#include "logunit.h"
+#include "util/compare.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+LOGUNIT_CLASS(LocationDisabledTest)
+{
+ LOGUNIT_TEST_SUITE(LocationDisabledTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST_SUITE_END();
+
+ LoggerPtr root;
+ LoggerPtr logger;
+
+public:
+ void setUp()
+ {
+ root = Logger::getRootLogger();
+ }
+
+ void tearDown()
+ {
+ if (auto rep = root->getLoggerRepository())
+ rep->resetConfiguration();
+ }
+
+ void test1()
+ {
+
PropertyConfigurator::configure(LOG4CXX_FILE("input/locationdisabled.properties"));
+ common();
+
LOGUNIT_ASSERT(Compare::compare(LOG4CXX_STR("output/location-disabled-test"),
LOG4CXX_FILE("witness/location1-disabled")));
+ }
+
+ std::string createMessage(Pool & pool, int i)
+ {
+ std::string msg("Message ");
+ msg.append(pool.itoa(i));
+ return msg;
+ }
+
+ void common()
+ {
+ int i = -1;
+
+ Pool pool;
+
+ LOG4CXX_DEBUG(root, createMessage(pool, i));
+ }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LocationDisabledTest);
diff --git a/src/test/cpp/locationtest.cpp b/src/test/cpp/locationtest.cpp
new file mode 100644
index 0000000..aa98a63
--- /dev/null
+++ b/src/test/cpp/locationtest.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 <log4cxx/logger.h>
+#include <log4cxx/propertyconfigurator.h>
+
+#include "testchar.h"
+#include "logunit.h"
+#include "util/compare.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+LOGUNIT_CLASS(LocationTest)
+{
+ LOGUNIT_TEST_SUITE(LocationTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST_SUITE_END();
+
+ LoggerPtr root;
+ LoggerPtr logger;
+
+public:
+ void setUp()
+ {
+ root = Logger::getRootLogger();
+ }
+
+ void tearDown()
+ {
+ if (auto rep = root->getLoggerRepository())
+ rep->resetConfiguration();
+ }
+
+ void test1()
+ {
+
PropertyConfigurator::configure(LOG4CXX_FILE("input/location1.properties"));
+ common();
+
LOGUNIT_ASSERT(Compare::compare(LOG4CXX_STR("output/location-good-test"),
LOG4CXX_FILE("witness/location1-good")));
+ }
+
+ std::string createMessage(Pool & pool, int i)
+ {
+ std::string msg("Message ");
+ msg.append(pool.itoa(i));
+ return msg;
+ }
+
+ void common()
+ {
+ int i = -1;
+
+ Pool pool;
+
+ LOG4CXX_DEBUG(root, createMessage(pool, i));
+ }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LocationTest);
diff --git a/src/test/cpp/patternlayouttest.cpp
b/src/test/cpp/patternlayouttest.cpp
index 1db3676..41661d9 100644
--- a/src/test/cpp/patternlayouttest.cpp
+++ b/src/test/cpp/patternlayouttest.cpp
@@ -76,6 +76,7 @@ LOGUNIT_CLASS(PatternLayoutTest)
LOGUNIT_TEST(test11);
LOGUNIT_TEST(test12);
LOGUNIT_TEST(test13);
+ LOGUNIT_TEST(test14);
LOGUNIT_TEST(testMDC1);
LOGUNIT_TEST(testMDC2);
LOGUNIT_TEST_SUITE_END();
@@ -427,6 +428,13 @@ public:
LOGUNIT_ASSERT(Compare::compare(TEMP,
LOG4CXX_FILE("witness/patternLayout.13")));
}
+ void test14()
+ {
+
PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout14.properties"));
+ common();
+ LOGUNIT_ASSERT(Compare::compare(TEMP,
LOG4CXX_FILE("witness/patternLayout.14")));
+ }
+
void testMDC1()
{
PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout.mdc.1.properties"));
diff --git a/src/test/cpp/rolling/timebasedrollingtest.cpp
b/src/test/cpp/rolling/timebasedrollingtest.cpp
index a080f6b..316328e 100644
--- a/src/test/cpp/rolling/timebasedrollingtest.cpp
+++ b/src/test/cpp/rolling/timebasedrollingtest.cpp
@@ -185,6 +185,7 @@ private:
#undef LOG4CXX_LOCATION
#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
__FILE__, \
+ __FILE__, \
srcFunc.c_str(), \
srcLine)
@@ -200,6 +201,7 @@ private:
#undef LOG4CXX_LOCATION
#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
__FILE__, \
+ __FILE__, \
__LOG4CXX_FUNC__, \
__LINE__)
}
diff --git a/src/test/cpp/throughput/CMakeLists.txt
b/src/test/cpp/throughput/CMakeLists.txt
index 154a6ae..3315484 100644
--- a/src/test/cpp/throughput/CMakeLists.txt
+++ b/src/test/cpp/throughput/CMakeLists.txt
@@ -38,3 +38,5 @@ endif( WIN32 )
target_compile_definitions(throughputtests PRIVATE
${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS}
${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(throughputtests PRIVATE ${CMAKE_CURRENT_LIST_DIR}
$<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
target_link_libraries(throughputtests PRIVATE log4cxx ${APR_LIBRARIES}
${APR_SYSTEM_LIBS} Threads::Threads fmt::fmt)
+
+add_custom_target(run-throughput COMMAND throughputtests DEPENDS
throughputtests)
diff --git a/src/test/resources/input/location1.properties
b/src/test/resources/input/location1.properties
new file mode 100644
index 0000000..f220ebd
--- /dev/null
+++ b/src/test/resources/input/location1.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+log4j.rootCategory=DEBUG, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.file=output/location-good-test
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%-5p(%f) - %m%n
diff --git a/src/test/resources/input/locationdisabled.properties
b/src/test/resources/input/locationdisabled.properties
new file mode 100644
index 0000000..191b3b4
--- /dev/null
+++ b/src/test/resources/input/locationdisabled.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+log4j.rootCategory=DEBUG, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.file=output/location-disabled-test
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%-5p[%F](%f)%L|%M| - %m%n
diff --git a/src/test/resources/input/patternLayout14.properties
b/src/test/resources/input/patternLayout14.properties
new file mode 100644
index 0000000..7c3c831
--- /dev/null
+++ b/src/test/resources/input/patternLayout14.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+log4j.rootCategory=DEBUG, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.File=output/patternlayout
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%-5p %f: %m%n
diff --git a/src/test/resources/witness/location1-disabled
b/src/test/resources/witness/location1-disabled
new file mode 100644
index 0000000..f63de46
--- /dev/null
+++ b/src/test/resources/witness/location1-disabled
@@ -0,0 +1 @@
+DEBUG[?](?)-1|?| - Message -1
diff --git a/src/test/resources/witness/location1-good
b/src/test/resources/witness/location1-good
new file mode 100644
index 0000000..6ee4319
--- /dev/null
+++ b/src/test/resources/witness/location1-good
@@ -0,0 +1 @@
+DEBUG(locationtest.cpp) - Message -1
diff --git a/src/test/resources/witness/patternLayout.14
b/src/test/resources/witness/patternLayout.14
new file mode 100644
index 0000000..e398ba3
--- /dev/null
+++ b/src/test/resources/witness/patternLayout.14
@@ -0,0 +1,10 @@
+DEBUG patternlayouttest.cpp: Message 0
+DEBUG patternlayouttest.cpp: Message 0
+INFO patternlayouttest.cpp: Message 1
+INFO patternlayouttest.cpp: Message 1
+WARN patternlayouttest.cpp: Message 2
+WARN patternlayouttest.cpp: Message 2
+ERROR patternlayouttest.cpp: Message 3
+ERROR patternlayouttest.cpp: Message 3
+FATAL patternlayouttest.cpp: Message 4
+FATAL patternlayouttest.cpp: Message 4