2017-12-18 06:28:33 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
2018-03-16 21:36:11 +08:00
|
|
|
#include "precomp.hpp"
|
2017-12-18 06:28:33 +08:00
|
|
|
|
|
|
|
#include <opencv2/core/utils/configuration.private.hpp>
|
|
|
|
#include <opencv2/core/utils/logger.hpp>
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
#include "utils/logtagmanager.hpp"
|
|
|
|
#include "utils/logtagconfigparser.hpp"
|
2017-12-18 06:28:33 +08:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
2018-03-14 20:33:02 +08:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
# include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
2017-12-18 06:28:33 +08:00
|
|
|
namespace cv {
|
|
|
|
namespace utils {
|
|
|
|
namespace logging {
|
|
|
|
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
namespace internal
|
2017-12-18 06:28:33 +08:00
|
|
|
{
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
|
|
|
|
// Combining several things that require static dynamic initialization in a
|
|
|
|
// well-defined order into a struct.
|
|
|
|
//
|
|
|
|
struct GlobalLoggingInitStruct
|
|
|
|
{
|
|
|
|
public:
|
2018-06-05 17:40:43 +08:00
|
|
|
#if defined NDEBUG
|
2019-04-22 20:41:27 +08:00
|
|
|
static const bool m_isDebugBuild = false;
|
2018-06-05 17:40:43 +08:00
|
|
|
#else
|
2019-04-22 20:41:27 +08:00
|
|
|
static const bool m_isDebugBuild = true;
|
2018-06-05 17:40:43 +08:00
|
|
|
#endif
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
|
|
|
|
public:
|
2019-04-22 20:41:27 +08:00
|
|
|
static LogLevel m_defaultUnconfiguredGlobalLevel;
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
LogTagManager logTagManager;
|
|
|
|
|
|
|
|
GlobalLoggingInitStruct()
|
|
|
|
: logTagManager(m_defaultUnconfiguredGlobalLevel)
|
|
|
|
{
|
|
|
|
applyConfigString();
|
|
|
|
handleMalformed();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void applyConfigString()
|
|
|
|
{
|
|
|
|
logTagManager.setConfigString(utils::getConfigurationParameterString("OPENCV_LOG_LEVEL", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleMalformed()
|
|
|
|
{
|
|
|
|
// need to print warning for malformed log tag config strings?
|
|
|
|
if (m_isDebugBuild)
|
|
|
|
{
|
|
|
|
const auto& parser = logTagManager.getConfigParser();
|
|
|
|
if (parser.hasMalformed())
|
|
|
|
{
|
|
|
|
const auto& malformedList = parser.getMalformed();
|
|
|
|
for (const auto& malformed : malformedList)
|
|
|
|
{
|
|
|
|
std::cout << "Malformed log level config: \"" << malformed << "\"\n";
|
|
|
|
}
|
|
|
|
std::cout.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-22 20:41:27 +08:00
|
|
|
LogLevel GlobalLoggingInitStruct::m_defaultUnconfiguredGlobalLevel = GlobalLoggingInitStruct::m_isDebugBuild
|
|
|
|
? LOG_LEVEL_DEBUG
|
|
|
|
: LOG_LEVEL_WARNING;
|
|
|
|
|
|
|
|
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
// Static dynamic initialization guard function for the combined struct
|
|
|
|
// just defined above
|
|
|
|
//
|
|
|
|
// An initialization guard function guarantees that outside code cannot
|
|
|
|
// accidentally see not-yet-dynamically-initialized data, by routing
|
|
|
|
// all outside access request to this function, so that this function
|
|
|
|
// has a chance to run the initialization code if necessary.
|
|
|
|
//
|
|
|
|
// An initialization guard function only guarantees initialization upon
|
|
|
|
// the first call to this function.
|
|
|
|
//
|
|
|
|
static GlobalLoggingInitStruct& getGlobalLoggingInitStruct()
|
|
|
|
{
|
|
|
|
static GlobalLoggingInitStruct globalLoggingInitInstance;
|
|
|
|
return globalLoggingInitInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// To ensure that the combined struct defined above is initialized even
|
|
|
|
// if the initialization guard function wasn't called, a dummy static
|
|
|
|
// instance of a struct is defined below, which will call the
|
|
|
|
// initialization guard function.
|
|
|
|
//
|
|
|
|
struct GlobalLoggingInitCall
|
|
|
|
{
|
|
|
|
GlobalLoggingInitCall()
|
|
|
|
{
|
|
|
|
getGlobalLoggingInitStruct();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static GlobalLoggingInitCall globalLoggingInitCall;
|
|
|
|
|
|
|
|
static LogTagManager& getLogTagManager()
|
|
|
|
{
|
|
|
|
static LogTagManager& logTagManagerInstance = getGlobalLoggingInitStruct().logTagManager;
|
|
|
|
return logTagManagerInstance;
|
2017-12-18 06:28:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static LogLevel& getLogLevelVariable()
|
|
|
|
{
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
static LogLevel& refGlobalLogLevel = getGlobalLogTag()->level;
|
|
|
|
return refGlobalLogLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogTag* getGlobalLogTag()
|
|
|
|
{
|
|
|
|
static LogTag* globalLogTagPtr = getGlobalLoggingInitStruct().logTagManager.get("global");
|
|
|
|
return globalLogTagPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void registerLogTag(LogTag* plogtag)
|
|
|
|
{
|
|
|
|
if (!plogtag || !plogtag->name)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
internal::getLogTagManager().assign(plogtag->name, plogtag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLogTagLevel(const char* tag, LogLevel level)
|
|
|
|
{
|
|
|
|
if (!tag)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
internal::getLogTagManager().setLevelByFullName(std::string(tag), level);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogLevel getLogTagLevel(const char* tag)
|
|
|
|
{
|
|
|
|
if (!tag)
|
|
|
|
{
|
|
|
|
return getLogLevel();
|
|
|
|
}
|
|
|
|
const LogTag* ptr = internal::getLogTagManager().get(std::string(tag));
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
return getLogLevel();
|
|
|
|
}
|
|
|
|
return ptr->level;
|
2017-12-18 06:28:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LogLevel setLogLevel(LogLevel logLevel)
|
|
|
|
{
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
// note: not thread safe, use sparingly and do not critically depend on outcome
|
|
|
|
LogLevel& refGlobalLevel = internal::getLogLevelVariable();
|
|
|
|
const LogLevel old = refGlobalLevel;
|
|
|
|
refGlobalLevel = logLevel;
|
2017-12-18 06:28:33 +08:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogLevel getLogLevel()
|
|
|
|
{
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
return internal::getLogLevelVariable();
|
2017-12-18 06:28:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
void writeLogMessage(LogLevel logLevel, const char* message)
|
|
|
|
{
|
|
|
|
const int threadID = cv::utils::getThreadID();
|
2018-03-14 20:33:02 +08:00
|
|
|
std::ostringstream ss;
|
2017-12-18 06:28:33 +08:00
|
|
|
switch (logLevel)
|
|
|
|
{
|
|
|
|
case LOG_LEVEL_FATAL: ss << "[FATAL:" << threadID << "] " << message << std::endl; break;
|
|
|
|
case LOG_LEVEL_ERROR: ss << "[ERROR:" << threadID << "] " << message << std::endl; break;
|
|
|
|
case LOG_LEVEL_WARNING: ss << "[ WARN:" << threadID << "] " << message << std::endl; break;
|
|
|
|
case LOG_LEVEL_INFO: ss << "[ INFO:" << threadID << "] " << message << std::endl; break;
|
|
|
|
case LOG_LEVEL_DEBUG: ss << "[DEBUG:" << threadID << "] " << message << std::endl; break;
|
|
|
|
case LOG_LEVEL_VERBOSE: ss << message << std::endl; break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 20:33:02 +08:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
int android_logLevel = ANDROID_LOG_INFO;
|
|
|
|
switch (logLevel)
|
|
|
|
{
|
|
|
|
case LOG_LEVEL_FATAL: android_logLevel = ANDROID_LOG_FATAL; break;
|
|
|
|
case LOG_LEVEL_ERROR: android_logLevel = ANDROID_LOG_ERROR; break;
|
|
|
|
case LOG_LEVEL_WARNING: android_logLevel = ANDROID_LOG_WARN; break;
|
|
|
|
case LOG_LEVEL_INFO: android_logLevel = ANDROID_LOG_INFO; break;
|
|
|
|
case LOG_LEVEL_DEBUG: android_logLevel = ANDROID_LOG_DEBUG; break;
|
|
|
|
case LOG_LEVEL_VERBOSE: android_logLevel = ANDROID_LOG_VERBOSE; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__android_log_print(android_logLevel, "OpenCV/" CV_VERSION, "%s", ss.str().c_str());
|
|
|
|
#endif
|
|
|
|
std::ostream* out = (logLevel <= LOG_LEVEL_WARNING) ? &std::cerr : &std::cout;
|
2017-12-18 06:28:33 +08:00
|
|
|
(*out) << ss.str();
|
|
|
|
if (logLevel <= LOG_LEVEL_WARNING)
|
|
|
|
(*out) << std::flush;
|
|
|
|
}
|
|
|
|
|
Merge pull request #13909 from kinchungwong:logging_20190220
OE-11 Logging revamp (#13909)
* Initial commit for log tag support.
Part of #11003, incomplete. Should pass build.
Moved LogLevel enum to logger.defines.hpp
LogTag struct used to convey both name and log level threshold as
one argument to the new logging macro. See logtag.hpp file, and
CV_LOG_WITH_TAG macro.
Global log level is now associated with a global log tag, when a
logging statement doesn't specify any log tag. See getLogLevel and
getGlobalLogTag functions.
A macro CV_LOGTAG_FALLBACK is allowed to be re-defined by other modules
or compilation units, internally, so that logging statements inside
that unit that specify NULL as tag will fall back to the re-defined tag.
Line-of-code information (file name, line number, function name),
together with tag name, are passed into the new log message sink.
See writeLogMessageEx function.
Fixed old incorrect CV_LOG_VERBOSE usage in ocl4dnn_conv_spatial.cpp.
* Implemented tag-based log filtering
Added LogTagManager. This is an initial version, using standard C++
approach as much as possible, to allow easier code review. Will
optimize later.
A workaround for all static dynamic initialization issues is
implemented. Refer to code comments.
* Added LogTagConfigParser.
Note: new code does not fully handle old log config parsing behavior.
* Fix log tag config vs registering ordering issue.
* Started testing LogTagConfigParser, incomplete.
The intention of this commit is to illustrate the capabilities of
the current design of LogTagConfigParser.
The test contained in this commit is not complete. Also, design changes
may require throwing away this commit and rewriting test code from
scratch.
Does not test whitespace segmentation (multiple tags on the config);
will do in next commit.
* Added CV_LOGTAG_EXPAND_NAME macro
This macro allows to be re-defined locally in other compilation units
to apply a prefix to whatever argument is passed as the "tag" argument
into CV_LOG_WITH_TAG. The default definition in logger.hpp does not
modify the argument. It is recommended to include the address-of
operator (ampersand) when re-defined locally.
* Added a few tests for LogTagManager, some fail.
See test_logtagmanager.cpp
Failed tests are: non-global ("something"), setting level by name-part
(first part or any part) has no effect at all.
* LogTagManagerTests substring non-confusion tests
* Fix major bugs in LogTagManager
The code change is intended to approximate the spec documented in
https://gist.github.com/kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6
Refer to test suite in test_logtagmanager.cpp
Filter test result in "opencv_test_core" ...
with gtest_filter "LogTagManager*"
To see the test code that finds the bugs, refer to original commits
(before rebase; might be gone)
.. f3451208 (2019-03-03T19:45:17Z)
.... LogTagManagerTests substring non-confusion tests
.. 1b848f5f (2019-03-03T01:55:18Z)
.... Added a few tests for LogTagManager, some fail.
* Added LogTagManagerNamePartNonConfusionTest.
See test_logtagmanager.cpp in modules/core/test.
* Added LogTagAuto for auto registration in ctor
* Rewritten LogTagManager to resolve issues.
* Resolves code review issues around 2019-04-10
LogTagConfigParser::parseLogLevel - as part of resolving code review
issues, this function is rewritten to simplify control flow and to
improve conformance with legacy usage (for string values "OFF",
"DISABLED", and "WARNINGS").
2019-04-22 05:01:10 +08:00
|
|
|
void writeLogMessageEx(LogLevel logLevel, const char* tag, const char* file, int line, const char* func, const char* message)
|
|
|
|
{
|
|
|
|
std::ostringstream strm;
|
|
|
|
if (tag)
|
|
|
|
{
|
|
|
|
strm << tag << " ";
|
|
|
|
}
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
strm << file << " ";
|
|
|
|
}
|
|
|
|
if (line > 0)
|
|
|
|
{
|
|
|
|
strm << "(" << line << ") ";
|
|
|
|
}
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
strm << func << " ";
|
|
|
|
}
|
|
|
|
strm << message;
|
|
|
|
writeLogMessage(logLevel, strm.str().c_str());
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:28:33 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
}}} // namespace
|