summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/db.cpp4
-rw-r--r--db/pdfile.cpp2
-rw-r--r--stdafx.cpp3
-rw-r--r--stdafx.h1
-rw-r--r--util/log.h44
-rw-r--r--util/util.cpp2
6 files changed, 37 insertions, 19 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 53194a35059..0c1568cebfb 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -16,7 +16,7 @@
extern const char *dbpath;
extern int curOp;
-/* only off if --nocursors which is for debugging. */
+/* only off if --nocursor which is for debugging. */
bool useCursors = true;
boost::mutex dbMutex;
@@ -352,7 +352,7 @@ public:
115 replay, opLogging
*/
void listen(int port) {
- const char *Version = "db version: 119 30jun2008";
+ const char *Version = "db version: 120 09jul2008 logging fix";
problem() << Version << endl;
cout << Version << endl;
pdfileInit();
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index e4167b91625..1f6282ccb86 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -598,7 +598,7 @@ auto_ptr<Cursor> DataFileMgr::findAll(const char *ns) {
/* todo: if extent is empty, free it for reuse elsewhere.
that is a bit complicated have to clean up the freelists.
*/
- OCCASIONALLY cout << "info DFM::findAll(): extent " << loc.toString() << " was empty, skipping ahead" << endl;
+ RARELY cout << "info DFM::findAll(): extent " << loc.toString() << " was empty, skipping ahead " << ns << endl;
// find a nonempty extent
// it might be nice to free the whole extent here! but have to clean up free recs then.
e = e->getNextExtent();
diff --git a/stdafx.cpp b/stdafx.cpp
index 35a718e2b66..aa22e5e1b73 100644
--- a/stdafx.cpp
+++ b/stdafx.cpp
@@ -22,9 +22,6 @@ void sayDbContext(const char *p = 0);
void wasserted(const char *msg, const char *file, unsigned line) {
problem() << "Assertion failure " << msg << ' ' << file << ' ' << line << endl;
- cout << "Assertion failure " << msg << endl;
- cout << ' ' << file << ' ';
- cout << line << endl;
sayDbContext();
}
diff --git a/stdafx.h b/stdafx.h
index eb9d75adbf9..8ff133a8eba 100644
--- a/stdafx.h
+++ b/stdafx.h
@@ -110,6 +110,7 @@ extern const char *curNs;
extern unsigned occasion;
#define OCCASIONALLY if( ++occasion % 16 == 0 )
+#define RARELY if( ++occasion % 128 == 0 )
#if defined(_WIN32)
inline void our_debug_free(void *p) {
diff --git a/util/log.h b/util/log.h
index 90e7141706c..2c560843009 100644
--- a/util/log.h
+++ b/util/log.h
@@ -16,22 +16,40 @@ public:
Nullstream& operator<< (ostream& ( *endl )(ostream&)) { return *this; }
Nullstream& operator<< (ios_base& (*hex)(ios_base&)) { return *this; }
};
-
inline Nullstream& endl ( Nullstream& os ) { }
-
extern Nullstream nullstream;
-//#define cout nullstream
+#define LOGIT { lock lk(mutex); cout << x; return *this; }
+class Logstream {
+ static boost::mutex mutex;
+public:
+ Logstream& operator<<(const char *x) LOGIT
+ Logstream& operator<<(int x) LOGIT
+ Logstream& operator<<(unsigned long x) LOGIT
+ Logstream& operator<<(unsigned x) LOGIT
+ Logstream& operator<<(double x) LOGIT
+ Logstream& operator<<(void *x) LOGIT
+ Logstream& operator<<(long long x) LOGIT
+ Logstream& operator<<(unsigned long long x) LOGIT
+ Logstream& operator<<(const string& x) LOGIT
+ Logstream& operator<< (ostream& ( *_endl )(ostream&)) { lock lk(mutex); cout << _endl; return *this; }
+ Logstream& operator<< (ios_base& (*_hex)(ios_base&)) { lock lk(mutex); cout << _hex; return *this; }
+ Logstream& prolog() {
+ lock lk(mutex);
+ time_t t;
+ time(&t);
+ string now(ctime(&t),0,20);
+ cout << "~ " << now;
+ if( client )
+ cout << curNs << ' ';
+ return *this;
+ }
+};
+inline Logstream& endl ( Logstream& os ) { }
+extern Logstream logstream;
// not threadsafe
-inline ostream& problem() {
- ostream& problems = cout;
- time_t t;
- time(&t);
- string now(ctime(&t),0,20);
- problems << "~ " << now;
- if( client )
- problems << curNs << ' ';
- return problems;
-}
+inline Logstream& problem() { return logstream.prolog(); }
+
+#define cout logstream
diff --git a/util/util.cpp b/util/util.cpp
index ddb96921ef5..3edb6f2b436 100644
--- a/util/util.cpp
+++ b/util/util.cpp
@@ -2,6 +2,8 @@
#include "goodies.h"
Nullstream nullstream;
+Logstream logstream;
+boost::mutex Logstream::mutex;
unsigned occasion = 0;
bool goingAway = false;