]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
logging: add DoutStreambuf::set_prio
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 7 Dec 2010 07:46:07 +0000 (23:46 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 7 Dec 2010 07:46:07 +0000 (23:46 -0800)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/common/DoutStreambuf.cc
src/common/DoutStreambuf.h
src/test/TestDoutStreambuf.cc

index 3e2a77ed3b74d3065144e12bd9347a0402ae24eb..1df324f2e5fcf142d787c2645d06db0867a3baaa 100644 (file)
@@ -183,6 +183,16 @@ set_flags(int flags_)
   flags = flags_;
 }
 
+template <typename charT, typename traits>
+void DoutStreambuf<charT, traits>::
+set_prio(int prio)
+{
+  charT* p = this->pptr();
+  *p++ = '\1';
+  *p++ = ((unsigned char)prio);
+  this->pbump(2);
+}
+
 // This is called to flush the buffer.
 // This is called when we're done with the file stream (or when .flush() is called).
 template <typename charT, typename traits>
index 4e416c07cf3ffd8790231eb0b4300482277e122f..2f4e87aaea0afaefab1ab4ea98ef6b8e5f8057d8 100644 (file)
@@ -54,6 +54,9 @@ public:
   // Set the flags directly (for debug use only)
   void set_flags(int flags_);
 
+  // Set the priority of the messages being put into the stream
+  void set_prio(int prio);
+
 protected:
   // Called when the buffer fills up
   virtual int_type overflow(int_type c);
index 82b5dd2ad683c0f698d3063ed8332ff11dafb09f..b4820ea2d55596990e885a6c520640590c205a16 100644 (file)
@@ -45,18 +45,24 @@ int main(int argc, const char **argv)
 
   _dout_lock.Lock();
   dos->set_flags(DoutStreambuf<char>::DOUTSB_FLAG_SYSLOG |
-                DoutStreambuf<char>::DOUTSB_FLAG_STDOUT);
+                DoutStreambuf<char>::DOUTSB_FLAG_STDERR);
   _dout_lock.Unlock();
 
   std::ostream oss(dos);
   syslog(LOG_USER | LOG_NOTICE, "TestDoutStreambuf: starting test\n");
 
+  dos->set_prio(1);
   oss << "I am logging to dout now!" << std::endl;
 
+  dos->set_prio(2);
   oss << "And here is another line!" << std::endl;
 
   oss.flush();
 
+  dos->set_prio(3);
+  oss << "And here is another line!" << std::endl;
+
+  dos->set_prio(16);
   oss << "Stuff ";
   oss << "that ";
   oss << "will ";
@@ -67,6 +73,7 @@ int main(int argc, const char **argv)
   oss << "line.";
   oss.flush();
 
+  dos->set_prio(10);
   oss << "There will be no blank lines here." << std::endl;
   oss.flush();
   oss.flush();