summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/log
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/components/log')
-rw-r--r--sca-cpp/trunk/components/log/log.composite2
-rw-r--r--sca-cpp/trunk/components/log/log.cpp22
-rw-r--r--sca-cpp/trunk/components/log/logger.cpp18
-rw-r--r--sca-cpp/trunk/components/log/scribe-cat.cpp10
-rw-r--r--sca-cpp/trunk/components/log/scribe-status.cpp2
-rwxr-xr-xsca-cpp/trunk/components/log/scribe-tail-stop5
-rw-r--r--sca-cpp/trunk/components/log/scribe.hpp8
-rwxr-xr-xsca-cpp/trunk/components/log/scribed-central-stop6
-rwxr-xr-xsca-cpp/trunk/components/log/scribed-client-stop6
-rwxr-xr-xsca-cpp/trunk/components/log/server-test1
10 files changed, 52 insertions, 28 deletions
diff --git a/sca-cpp/trunk/components/log/log.composite b/sca-cpp/trunk/components/log/log.composite
index 97754b534c..c6755f3655 100644
--- a/sca-cpp/trunk/components/log/log.composite
+++ b/sca-cpp/trunk/components/log/log.composite
@@ -23,6 +23,7 @@
<component name="log">
<implementation.cpp path="." library="liblog"/>
+ <property name="host"></property>
<property name="category">default</property>
<service name="log">
<binding.http uri="log"/>
@@ -39,6 +40,7 @@
<component name="logger">
<implementation.cpp path="." library="liblogger"/>
+ <property name="host"></property>
<property name="category">default</property>
<service name="logger">
<binding.http uri="logger"/>
diff --git a/sca-cpp/trunk/components/log/log.cpp b/sca-cpp/trunk/components/log/log.cpp
index d43833680d..2e7742cfd7 100644
--- a/sca-cpp/trunk/components/log/log.cpp
+++ b/sca-cpp/trunk/components/log/log.cpp
@@ -29,6 +29,7 @@
#include "list.hpp"
#include "value.hpp"
#include "monad.hpp"
+#include "../../modules/http/http.hpp"
#include "scribe.hpp"
namespace tuscany {
@@ -37,11 +38,11 @@ namespace log {
/**
* Post an item to the Scribe log.
*/
-const failable<value> post(const list<value>& params, const value& category, scribe::Scribe& sc) {
+const failable<value> post(const list<value>& params, const value& host, const value& category, scribe::Scribe& sc) {
debug(cadr(params), "log::post::value");
- const failable<bool> val = scribe::log(cadr(params), category, sc);
+ const failable<bool> val = scribe::log(cadr(params), host, category, sc);
if (!hasContent(val))
- return mkfailure<value>(reason(val));
+ return mkfailure<value>(val);
return value(mklist<value>(true));
}
@@ -50,17 +51,18 @@ const failable<value> post(const list<value>& params, const value& category, scr
*/
class applyLog {
public:
- applyLog(const value& category, scribe::Scribe& sc) : category(category), sc(sc) {
+ applyLog(const value& host, const value& category, scribe::Scribe& sc) : host(host), category(category), sc(sc) {
}
const value operator()(const list<value>& params) const {
const value func(car(params));
if (func == "post")
- return post(cdr(params), category, sc);
- return tuscany::mkfailure<tuscany::value>();
+ return post(cdr(params), host, category, sc);
+ return mkfailure<value>();
}
private:
+ const value host;
const value category;
scribe::Scribe& sc;
};
@@ -68,16 +70,18 @@ private:
/**
* Start the component.
*/
-const failable<value> start(unused const list<value>& params) {
+const failable<value> start(const list<value>& params) {
// Connect to Scribe
scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
// Extract the configured category
- const value category = ((lambda<value(list<value>)>)car(params))(list<value>());
+ const value host = ((lambda<value(list<value>)>)car(params))(list<value>());
+ const value category = ((lambda<value(list<value>)>)cadr(params))(list<value>());
+ debug(host, "log::start::host");
debug(category, "log::start::category");
// Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applyLog(category, sc)));
+ return value(lambda<value(const list<value>&)>(applyLog(host, category, sc)));
}
}
diff --git a/sca-cpp/trunk/components/log/logger.cpp b/sca-cpp/trunk/components/log/logger.cpp
index eb18ed30db..d7a54507fb 100644
--- a/sca-cpp/trunk/components/log/logger.cpp
+++ b/sca-cpp/trunk/components/log/logger.cpp
@@ -30,6 +30,7 @@
#include "list.hpp"
#include "value.hpp"
#include "monad.hpp"
+#include "../../modules/http/http.hpp"
#include "scribe.hpp"
namespace tuscany {
@@ -40,24 +41,25 @@ namespace logger {
*/
class applyLog {
public:
- applyLog(const lambda<value(const list<value>&)>& relay, const value& category, scribe::Scribe& sc) : relay(relay), category(category), sc(sc) {
+ applyLog(const lambda<value(const list<value>&)>& relay, const value& host, const value& category, scribe::Scribe& sc) : relay(relay), host(host), category(category), sc(sc) {
}
const value operator()(const list<value>& params) const {
// Log the function params
debug(params, "logger::apply::params");
- scribe::log(params, category, sc);
+ scribe::log(params, host, category, sc);
- // Relay the function
+ // Relay the function call
const failable<value> res = relay(params);
// Log the result
- scribe::log(res, category, sc);
+ scribe::log(res, host, category, sc);
return res;
}
private:
const lambda<value(const list<value>&)> relay;
+ const value host;
const value category;
scribe::Scribe& sc;
};
@@ -65,17 +67,19 @@ private:
/**
* Start the component.
*/
-const failable<value> start(unused const list<value>& params) {
+const failable<value> start(const list<value>& params) {
// Connect to Scribe
scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
// Extract the configured relay service and category
const value rel = car(params);
- const value category = ((lambda<value(list<value>)>)cadr(params))(list<value>());
+ const value host = ((lambda<value(list<value>)>)cadr(params))(list<value>());
+ const value category = ((lambda<value(list<value>)>)caddr(params))(list<value>());
+ debug(host, "logger::start::host");
debug(category, "logger::start::category");
// Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applyLog(rel, category, sc)));
+ return value(lambda<value(const list<value>&)>(applyLog(rel, host, category, sc)));
}
}
diff --git a/sca-cpp/trunk/components/log/scribe-cat.cpp b/sca-cpp/trunk/components/log/scribe-cat.cpp
index 7f48ddb59b..fbfdaca533 100644
--- a/sca-cpp/trunk/components/log/scribe-cat.cpp
+++ b/sca-cpp/trunk/components/log/scribe-cat.cpp
@@ -47,7 +47,6 @@ int cat(const string& host, const string& category, const string& type) {
// Write line prefix
ostringstream os;
- os << "[" << host << "] ";
if (length(type) != 0)
os << "[" << logTime() << "] [" << type << "] ";
const string prefix = str(os);
@@ -58,13 +57,14 @@ int cat(const string& host, const string& category, const string& type) {
const char* s = fgets(buf + pl, 8192 - pl, stdin);
if (s == NULL)
return 0;
+
+ // Remove trailing '\n'
const size_t l = strlen(s);
- if (l < 2)
- return 0;
- buf[pl + l - 1] = '\0';
+ if (l > 0)
+ buf[pl + l - 1] = '\0';
// Log the line
- const failable<bool> val = scribe::log(buf, category, sc);
+ const failable<bool> val = scribe::log(buf, host, category, sc);
if (!hasContent(val))
return 1;
}
diff --git a/sca-cpp/trunk/components/log/scribe-status.cpp b/sca-cpp/trunk/components/log/scribe-status.cpp
index 0e5f03f501..79f7572947 100644
--- a/sca-cpp/trunk/components/log/scribe-status.cpp
+++ b/sca-cpp/trunk/components/log/scribe-status.cpp
@@ -45,7 +45,7 @@ const int status(const string& host, const int port) {
// Interpret and display results
if (!hasContent(fs)) {
- cerr << reason(fs) << endl;
+ cerr << reason(fs) << " : " << rcode(fs) << endl;
return 2;
}
const string s = content(fs);
diff --git a/sca-cpp/trunk/components/log/scribe-tail-stop b/sca-cpp/trunk/components/log/scribe-tail-stop
index b46c1ecca6..0d43570a6f 100755
--- a/sca-cpp/trunk/components/log/scribe-tail-stop
+++ b/sca-cpp/trunk/components/log/scribe-tail-stop
@@ -38,5 +38,8 @@ fi
file=`echo "import os; print os.path.realpath('$file')" | python`
cmd="tail -f -n 0 $file"
-kill `ps -ef | grep -v grep | grep "${cmd}" | awk '{ print $2 }'`
+k=`ps -ef | grep -v grep | grep "${cmd}" | awk '{ print $2 }'`
+if [ "$k" != "" ]; then
+ kill $k
+fi
diff --git a/sca-cpp/trunk/components/log/scribe.hpp b/sca-cpp/trunk/components/log/scribe.hpp
index 7fa420f945..5ae8a50776 100644
--- a/sca-cpp/trunk/components/log/scribe.hpp
+++ b/sca-cpp/trunk/components/log/scribe.hpp
@@ -98,7 +98,7 @@ private:
::scribe::thrift::scribeClient* client;
boost::shared_ptr<apache::thrift::transport::TTransport> transport;
- friend const failable<bool> log(const value& val, const value& category, const Scribe& sc);
+ friend const failable<bool> log(const value& val, const string& host, const value& category, const Scribe& sc);
friend const failable<string> status(const Scribe& sc);
/**
@@ -122,18 +122,20 @@ private:
/**
* Log an item.
*/
-const failable<bool> log(const value& val, const value& category, const Scribe& sc) {
+const failable<bool> log(const value& val, const string& host, const value& category, const Scribe& sc) {
debug(val, "scribe::log::value");
debug(category, "scribe::log::category");
const value cat = isString(category)? value(c_str(category)):category;
const string cs(scheme::writeValue(cat));
const string vs(scheme::writeValue(val));
+ ostringstream os;
+ os << "[" << host << "] " << vs;
try {
::scribe::thrift::LogEntry entry;
entry.category = c_str(cs);
- entry.message = c_str(vs);
+ entry.message = c_str(str(os));
std::vector< ::scribe::thrift::LogEntry> msgs;
msgs.push_back(entry);
diff --git a/sca-cpp/trunk/components/log/scribed-central-stop b/sca-cpp/trunk/components/log/scribed-central-stop
index acded2a482..2d301149b8 100755
--- a/sca-cpp/trunk/components/log/scribed-central-stop
+++ b/sca-cpp/trunk/components/log/scribed-central-stop
@@ -25,4 +25,8 @@ scribe_prefix=`cat $here/scribe.prefix`
thrift_prefix=`cat $here/thrift.prefix`
scribed="$scribe_prefix/bin/scribed -c $root/scribe/conf/scribe-central.conf"
-kill `ps -ef | grep -v grep | grep "${scribed}" | awk '{ print $2 }'`
+k=`ps -ef | grep -v grep | grep "${scribed}" | awk '{ print $2 }'`
+if [ "$k" != "" ]; then
+ kill $k
+fi
+
diff --git a/sca-cpp/trunk/components/log/scribed-client-stop b/sca-cpp/trunk/components/log/scribed-client-stop
index 0f9c409183..d6a6345f29 100755
--- a/sca-cpp/trunk/components/log/scribed-client-stop
+++ b/sca-cpp/trunk/components/log/scribed-client-stop
@@ -25,4 +25,8 @@ scribe_prefix=`cat $here/scribe.prefix`
thrift_prefix=`cat $here/thrift.prefix`
scribed="$scribe_prefix/bin/scribed -c $root/scribe/conf/scribe-client.conf"
-kill `ps -ef | grep -v grep | grep "${scribed}" | awk '{ print $2 }'`
+k=`ps -ef | grep -v grep | grep "${scribed}" | awk '{ print $2 }'`
+if [ "$k" != "" ]; then
+ kill $k
+fi
+
diff --git a/sca-cpp/trunk/components/log/server-test b/sca-cpp/trunk/components/log/server-test
index 015691f958..6c9cf47135 100755
--- a/sca-cpp/trunk/components/log/server-test
+++ b/sca-cpp/trunk/components/log/server-test
@@ -18,6 +18,7 @@
# under the License.
# Setup
+rm -rf tmp
../../modules/http/httpd-conf tmp localhost 8090 ../../modules/http/htdocs
../../modules/http/httpd-event-conf tmp
../../modules/server/server-conf tmp