r3293 - in trunk/libmutil: include/libmutil source
erik at minisip.org
erik at minisip.org
Mon Jun 11 10:16:43 CEST 2007
Author: erik
Date: 2007-06-11 10:16:42 +0200 (Mon, 11 Jun 2007)
New Revision: 3293
Modified:
trunk/libmutil/include/libmutil/dbg.h
trunk/libmutil/source/dbg.cxx
Log:
* The debug output can be a bit overwhelming. You turn it on, but you
don't find your problem because of the large amount of output.
This is an experiment with letting merr/mout/mdbg having filters.
You can now do:
mdbg("signaling/sdp") << "..."<<endl;
We don't have to modify existing output.
mdbg << "..." <<endl;
is equal to
mdbg("")<< "..." <<endl;
If you want to filter out a "class" of output you can call
mdbg.exclude("signaling")
which would filter out any output class starting with the string
"signaling".
You can make the output default to ignoring all output, and then
include what you want:
mdbg.exclude(""); // default exclude
mdbg.include("media/rtp");
What output class is used is reset at each "endl".
Modified: trunk/libmutil/include/libmutil/dbg.h
===================================================================
--- trunk/libmutil/include/libmutil/dbg.h 2007-06-08 20:45:23 UTC (rev 3292)
+++ trunk/libmutil/include/libmutil/dbg.h 2007-06-11 08:16:42 UTC (rev 3293)
@@ -94,11 +94,23 @@
bool getEnabled();
void setExternalHandler(DbgHandler * dbgHandler);
+ Dbg& operator()(std::string oClass);
+ void include(std::string);
+ void exclude(std::string);
+
+
private:
+ void updateFilter();
bool error_out;
bool enabled;
std::string str;
DbgHandler * debugHandler;
+
+ bool defaultInclude; // include or exclude by default
+ std::string curClass; // currently set output class. Reset by endl.
+ std::set< std::string > includeSet;
+ std::set< std::string > excludeSet;
+ bool filterBlocking;
};
extern LIBMUTIL_API Dbg mout;
Modified: trunk/libmutil/source/dbg.cxx
===================================================================
--- trunk/libmutil/source/dbg.cxx 2007-06-08 20:45:23 UTC (rev 3292)
+++ trunk/libmutil/source/dbg.cxx 2007-06-11 08:16:42 UTC (rev 3293)
@@ -43,7 +43,13 @@
LIBMUTIL_API bool outputStateMachineDebug = false;
-Dbg::Dbg(bool error_output, bool isEnabled):error_out(error_output), enabled(isEnabled), debugHandler(NULL){
+Dbg::Dbg(bool error_output, bool isEnabled):
+ error_out(error_output),
+ enabled(isEnabled),
+ debugHandler(NULL),
+ defaultInclude(true),
+ filterBlocking(false)
+{
}
void Dbg::setEnabled(bool e){
@@ -55,7 +61,8 @@
}
Dbg &Dbg::operator<<(const std::string& s){
- if (!enabled)
+
+ if (!enabled || filterBlocking)
return *this;
bool doFlush = s.size()>0 && (s[s.size()-1]=='\n');
@@ -84,11 +91,17 @@
}
Dbg &Dbg::operator<<( std::ostream&(*)(std::ostream&) ){
- return (*this)<<"\n";
+ (*this)<<"\n";
+ curClass="";
+ updateFilter();
+ return (*this);
}
Dbg &Dbg::operator<<(const DbgEndl &){
- return (*this)<<"\n";
+ (*this)<<"\n";
+ curClass="";
+ updateFilter();
+ return (*this);
}
Dbg& Dbg::operator<<(int i){
@@ -116,3 +129,120 @@
this->debugHandler = dh;
}
+/*
+ merr("media/rtp") << "hello" << endl;
+
+
+
+
+
+
+*/
+
+
+/**
+ *
+ * set contains
+ * a/b
+ * filter
+ * a
+ * result: false
+ *
+ * set contains
+ * a
+ * filter
+ * a/b
+ * result: true
+ */
+static bool inSet( std::set< std::string > &set, std::string filter ){
+ std::set< std::string >::const_iterator i;
+ for (i=set.begin() ; i!=set.end(); i++){
+ std::string setfilt = (*i);
+ if ( setfilt[0]=='/' )
+ setfilt = setfilt.substr(1);
+ if ( filter.substr(0,setfilt.size()) == setfilt ){
+ return true;
+ }
+ }
+ return false;
+}
+
+void Dbg::updateFilter(){
+ if (inSet( excludeSet, curClass ))
+ filterBlocking=true;
+ else if (inSet( includeSet, curClass ))
+ filterBlocking=false;
+ else
+ filterBlocking = ! defaultInclude;
+}
+
+Dbg& Dbg::operator()(std::string oClass){
+ curClass = oClass;
+ updateFilter();
+ return *this;
+}
+
+
+/**
+ *
+ * Removes all filters from a set that is equal to or begins with
+ * a string.
+ * Example:
+ * If the set contains
+ * a
+ * a/b
+ * a/c
+ * b
+ * And you remove
+ * a
+ * then the resulting set contains
+ * b
+ */
+static void removeStartingWith( std::set< std::string > &set, std::string filter ){
+ std::set< std::string >::iterator i;
+ if (filter.size()<=0)
+ return;
+
+ if (filter[0]=='/')
+ filter = filter.substr(1);
+
+ if (filter[filter.size()-1]=='/')
+ filter = filter.substr(0, filter.size()-1);
+
+ for (i=set.begin() ; i!=set.end(); i++){
+ std::string tmp = (*i);
+ if ( tmp[0]=='/' )
+ tmp = tmp.substr(1);
+ if ( tmp.substr( 0, filter.size() ) == filter ){
+ set.erase(i);
+ i=set.begin();
+ }
+ if (i==set.end())
+ break;
+ }
+}
+
+void Dbg::include(std::string s){
+ if (s==""){
+ defaultInclude=true;
+ includeSet.clear();
+ excludeSet.clear();
+ }else{
+ includeSet.insert(s);
+ removeStartingWith(excludeSet, s);
+ }
+ updateFilter();
+}
+
+void Dbg::exclude(std::string s){
+ if (s==""){
+ defaultInclude=false;
+ includeSet.clear();
+ excludeSet.clear();
+ }else{
+ excludeSet.insert(s);
+ removeStartingWith(includeSet, s);
+ }
+ updateFilter();
+}
+
More information about the Minisip-devel
mailing list