summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel/fstream.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-09-05 23:30:20 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-09-05 23:30:20 +0000
commita44b60593ab559f66ac3e984eb89133b8ca1e260 (patch)
tree2b7c230b3dae78c48e36f626c3b466b9eff9cb27 /sca-cpp/trunk/kernel/fstream.hpp
parent4f1cd537bc7c5a35f03660c4d04754954fae0487 (diff)
Improve logging with multiple threads and processes.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1165450 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel/fstream.hpp')
-rw-r--r--sca-cpp/trunk/kernel/fstream.hpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/sca-cpp/trunk/kernel/fstream.hpp b/sca-cpp/trunk/kernel/fstream.hpp
index 6888e7d14d..89d1909f15 100644
--- a/sca-cpp/trunk/kernel/fstream.hpp
+++ b/sca-cpp/trunk/kernel/fstream.hpp
@@ -29,6 +29,11 @@
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
+#include <sys/time.h>
+#include <unistd.h>
+#ifdef WANT_THREADS
+#include <pthread.h>
+#endif
#include "string.hpp"
#include "stream.hpp"
@@ -149,10 +154,14 @@ ifstream cin(stdin);
* Format the current time.
*/
const string logTime() {
- const time_t t = ::time(NULL);
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ const time_t t = tv.tv_sec;
const tm* lt = localtime(&t);
char ft[32];
- strftime(ft, 31, "%a %b %d %H:%M:%S %Y", lt);
+ strftime(ft, 20, "%a %b %d %H:%M:%S", lt);
+ sprintf(ft + 19, ".%06lu ", (unsigned long)tv.tv_usec);
+ strftime(ft + 27, 5, "%Y", lt);
return ft;
}
@@ -203,11 +212,19 @@ private:
bool owner;
bool head;
+ const unsigned long tid() const {
+#ifdef WANT_THREADS
+ return (unsigned long)pthread_self();
+#else
+ return 0;
+#endif
+ }
+
logfstream& whead() {
if (head)
return *this;
head = true;
- *this << "[" << logTime() << "] [" << type << "] ";
+ *this << "[" << logTime() << "] [" << type << "] [pid " << (unsigned long)getpid() << ":tid " << tid() << "] ";
return *this;
}
};