summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-08-19 04:10:43 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-08-19 04:10:43 +0000
commit768a1e33e56c579edbcab1d4ea73d06b85cdd06c (patch)
tree5ea1f2c67ad34a17155c221711df7eff010034d2 /sca-cpp/trunk/kernel
parentd4184f1ab86fd589126f3de2ed9fa433cf1b54b2 (diff)
Script fixes to get database working with the HTTPS-enabled store-cluster sample configuration. Also some logging improvements and aggregation of the sample logs using scribe.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@987012 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel')
-rw-r--r--sca-cpp/trunk/kernel/fstream.hpp98
-rw-r--r--sca-cpp/trunk/kernel/monad.hpp9
-rw-r--r--sca-cpp/trunk/kernel/stream.hpp2
3 files changed, 102 insertions, 7 deletions
diff --git a/sca-cpp/trunk/kernel/fstream.hpp b/sca-cpp/trunk/kernel/fstream.hpp
index f5a9dcd981..033024de1d 100644
--- a/sca-cpp/trunk/kernel/fstream.hpp
+++ b/sca-cpp/trunk/kernel/fstream.hpp
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdarg.h>
+#include <time.h>
#include "string.hpp"
#include "stream.hpp"
@@ -137,20 +138,107 @@ ofstream cerr(stderr);
ifstream cin(stdin);
/**
- * Debug log stream.
+ * Streams used for logging.
*/
+
+/**
+ * Format the current time.
+ */
+const string logTime() {
+ const time_t t = ::time(NULL);
+ const tm* lt = localtime(&t);
+ char ft[32];
+ strftime(ft, 31, "%a %b %d %H:%M:%S %Y", lt);
+ return ft;
+}
+
+/*
+ * Log stream.
+ */
+class logfstream : public ostream {
+public:
+ logfstream(FILE* file, const string& type) : file(file), type(type), owner(false), head(false) {
+ }
+
+ logfstream(const logfstream& os) : file(os.file), type(type), owner(false), head(os.head) {
+ }
+
+ ~logfstream() {
+ if (!owner)
+ return;
+ if (file == NULL)
+ return;
+ fclose(file);
+ }
+
+ logfstream& vprintf(const char* fmt, ...) {
+ whead();
+ va_list args;
+ va_start (args, fmt);
+ vfprintf (file, fmt, args);
+ va_end (args);
+ return *this;
+ }
+
+ logfstream& write(const string& s) {
+ whead();
+ fwrite(c_str(s), 1, length(s), file);
+ if (s == "\n")
+ head = false;
+ return *this;
+ }
+
+ logfstream& flush() {
+ fflush(file);
+ return *this;
+ }
+
+private:
+ FILE* file;
+ const string type;
+ bool owner;
+ bool head;
+
+ logfstream& whead() {
+ if (head)
+ return *this;
+ head = true;
+ *this << "[" << logTime() << "] [" << type << "] ";
+ return *this;
+ }
+};
+
+/**
+ * Info and failure log streams.
+ */
+logfstream cinfo(stderr, "info");
+logfstream cfailure(stderr, "error");
+
#ifdef WANT_MAINTAINER_MODE
-template<typename V> const bool debug(const V& v, const string& msg) {
- cerr << msg << ": " << v << endl;
+/**
+ * Debug log stream and debug functions.
+ */
+logfstream cdebug(stderr, "debug");
+
+/**
+ * Log a debug message.
+ */
+const bool debugLog(const string& msg) {
+ cdebug << msg << endl;
return true;
}
-const bool debug(const string& msg) {
- cerr << msg << endl;
+/**
+ * Log a debug message and a value.
+ */
+template<typename V> const bool debugLog(const V& v, const string& msg) {
+ cdebug << msg << ": " << v << endl;
return true;
}
+#define debug(...) tuscany::debugLog(__VA_ARGS__)
+
#else
#define debug(...)
diff --git a/sca-cpp/trunk/kernel/monad.hpp b/sca-cpp/trunk/kernel/monad.hpp
index 8aa4bc1662..d87a382ee1 100644
--- a/sca-cpp/trunk/kernel/monad.hpp
+++ b/sca-cpp/trunk/kernel/monad.hpp
@@ -29,6 +29,8 @@
#include "function.hpp"
#include "string.hpp"
#include "stream.hpp"
+#include "sstream.hpp"
+#include "fstream.hpp"
namespace tuscany
{
@@ -275,7 +277,12 @@ template<typename V, typename F> const lambda<failable<V, F>(const V)> success()
* Returns a failable monad with a failure in it.
*/
template<typename V, typename F> const failable<V, F> mkfailure(const F& f) {
- debug(f, "failable::mkfailure");
+#ifdef WANT_MAINTAINER_MODE
+ ostringstream os;
+ os << f;
+ if (length(str(os)) != 0)
+ debug(f, "failable::mkfailure");
+#endif
return failable<V, F>(false, f);
}
diff --git a/sca-cpp/trunk/kernel/stream.hpp b/sca-cpp/trunk/kernel/stream.hpp
index 32b754f315..f9d5cc3afe 100644
--- a/sca-cpp/trunk/kernel/stream.hpp
+++ b/sca-cpp/trunk/kernel/stream.hpp
@@ -97,7 +97,7 @@ class stream_endl {
} endl;
ostream& operator<<(ostream& os, unused const stream_endl e) {
- os.vprintf("%s", "\n");
+ os.write("\n");
return os.flush();
}