Commit 46a4232c authored by Pavel Vainerman's avatar Pavel Vainerman

(DebugStream): добавил поддержку знака '-'(минус) при задании

уровней логов строкой. Для возможности написать напримери так: --ulog-add-levels any,-level8 Включить все логи и исключить level8.
parent bef5dade
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.5 Version: 2.5
Release: alt10 Release: alt11
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: LGPL License: LGPL
...@@ -486,6 +486,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -486,6 +486,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# .. # ..
%changelog %changelog
* Thu Sep 08 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt11
- DebugStream: added support format: level1,level2,-level3
for set or delete debug levels.
* Wed Sep 07 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt10 * Wed Sep 07 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt10
- fixed bug in millisecToPoco() function - fixed bug in millisecToPoco() function
......
...@@ -84,6 +84,8 @@ struct Debug ...@@ -84,6 +84,8 @@ struct Debug
/** A function to convert symbolic string names on debug levels /** A function to convert symbolic string names on debug levels
to their numerical value. to their numerical value.
example: level1,level2,-level3
supported '-' for disable debug level
*/ */
static Debug::type value(std::string const& val); static Debug::type value(std::string const& val);
......
...@@ -75,18 +75,25 @@ Debug::type Debug::value(string const& val) ...@@ -75,18 +75,25 @@ Debug::type Debug::value(string const& val)
//string tmp(lowercase(v.substr(0, st))); //string tmp(lowercase(v.substr(0, st)));
string tmp(v.substr(0, st)); string tmp(v.substr(0, st));
if (tmp.empty())
if(tmp.empty())
break; break;
// Is it a number? bool del = false;
//if (isStrInt(tmp)) if( tmp[0] == '-' )
// l |= static_cast<type>(strToInt(tmp)); {
//else del = true;
// Search for an explicit name tmp = tmp.substr(1,tmp.size());
}
for (int i = 0 ; i < numErrorTags ; ++i) for (int i = 0 ; i < numErrorTags ; ++i)
if (tmp == errorTags[i].name) if (tmp == errorTags[i].name)
{ {
if( del )
l = Debug::type(l & ~(errorTags[i].level));
else
l |= errorTags[i].level; l |= errorTags[i].level;
break; break;
} }
......
...@@ -28,7 +28,8 @@ test_mutex.cc \ ...@@ -28,7 +28,8 @@ test_mutex.cc \
test_logserver.cc \ test_logserver.cc \
test_tcpcheck.cc \ test_tcpcheck.cc \
test_utcpsocket.cc \ test_utcpsocket.cc \
test_iocontroller_types.cc test_iocontroller_types.cc \
test_debugstream.cc
tests_with_conf_LDADD = $(top_builddir)/lib/libUniSet2.la tests_with_conf_LDADD = $(top_builddir)/lib/libUniSet2.la
tests_with_conf_CPPFLAGS = -I$(top_builddir)/include tests_with_conf_CPPFLAGS = -I$(top_builddir)/include
......
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <sstream>
#include "DebugStream.h"
// -----------------------------------------------------------------------------
using namespace std;
// -----------------------------------------------------------------------------
//! \todo Дописать тесты по DebugStream
// -----------------------------------------------------------------------------
TEST_CASE("Debugstream: set levels", "[debugstream][set]" )
{
DebugStream d;
d.level(Debug::value("level1"));
REQUIRE(d.is_level1());
d.level( Debug::value("level2"));
REQUIRE(d.is_level2());
REQUIRE_FALSE(d.is_level1());
d.level( Debug::type(Debug::LEVEL1 | Debug::LEVEL2) );
REQUIRE(d.is_level2());
REQUIRE(d.is_level1());
d.level(Debug::value("level1,level2"));
REQUIRE(d.is_level2());
REQUIRE(d.is_level1());
d.level(Debug::value("level1,-level2"));
REQUIRE(d.is_level1());
REQUIRE_FALSE(d.is_level2());
d.level(Debug::value("any,-level2"));
REQUIRE(d.is_level1());
REQUIRE(d.is_level9());
REQUIRE_FALSE(d.is_level2());
}
// -----------------------------------------------------------------------------
TEST_CASE("Debugstream: add levels", "[debugstream][add]" )
{
DebugStream d;
d.level(Debug::LEVEL1);
REQUIRE(d.is_level1());
d.addLevel(Debug::LEVEL2);
REQUIRE(d.is_level1());
REQUIRE(d.is_level2());
d.addLevel(Debug::value("level3"));
REQUIRE(d.is_level1());
REQUIRE(d.is_level2());
REQUIRE(d.is_level3());
}
// -----------------------------------------------------------------------------
TEST_CASE("Debugstream: del levels", "[debugstream][del]" )
{
DebugStream d;
d.level(Debug::ANY);
REQUIRE(d.is_level1());
REQUIRE(d.is_level2());
d.delLevel(Debug::LEVEL1);
REQUIRE_FALSE(d.is_level1());
REQUIRE(d.is_level2());
d.delLevel(Debug::value("level2"));
REQUIRE_FALSE(d.is_level1());
REQUIRE_FALSE(d.is_level2());
REQUIRE(d.is_level3());
}
// -----------------------------------------------------------------------------
...@@ -465,6 +465,7 @@ tests/test_mqueue.cc ...@@ -465,6 +465,7 @@ tests/test_mqueue.cc
tests/test_uobject.cc tests/test_uobject.cc
tests/test_utcpsocket.cc tests/test_utcpsocket.cc
tests/test_iocontroller_types.cc tests/test_iocontroller_types.cc
tests/test_debugstream.cc
tests/TestUObject.h tests/TestUObject.h
tests/tests-junit.xml tests/tests-junit.xml
tests/tests.cc tests/tests.cc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment