diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-23 18:52:42 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-23 18:52:42 +0000 |
commit | 8262f6efdd9bf0b99e566e3b7017c1a361f4dd99 (patch) | |
tree | a5b49b3ed69c5f9945addf20071cf5f9692ea680 /sca-cpp | |
parent | 2a73f2e3cc8324450d564578e804a31ca6003e10 (diff) |
Add a logger component that logs and relays all invocations through a reference.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@947467 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r-- | sca-cpp/trunk/components/log/Makefile.am | 8 | ||||
-rw-r--r-- | sca-cpp/trunk/components/log/adder-test.scm | 20 | ||||
-rw-r--r-- | sca-cpp/trunk/components/log/client-test.cpp | 13 | ||||
-rw-r--r-- | sca-cpp/trunk/components/log/client-test.scm | 20 | ||||
-rw-r--r-- | sca-cpp/trunk/components/log/log.composite | 24 | ||||
-rw-r--r-- | sca-cpp/trunk/components/log/logger.cpp | 92 | ||||
-rwxr-xr-x | sca-cpp/trunk/components/log/scribe-test | 2 | ||||
-rwxr-xr-x | sca-cpp/trunk/components/log/server-test | 14 |
8 files changed, 189 insertions, 4 deletions
diff --git a/sca-cpp/trunk/components/log/Makefile.am b/sca-cpp/trunk/components/log/Makefile.am index 5083ac48a2..b572a7ca80 100644 --- a/sca-cpp/trunk/components/log/Makefile.am +++ b/sca-cpp/trunk/components/log/Makefile.am @@ -35,12 +35,18 @@ gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp CLEANFILES = gen-cpp/* -comp_LTLIBRARIES = liblog.la +comp_LTLIBRARIES = liblog.la liblogger.la + nodist_liblog_la_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h liblog_la_CXXFLAGS = -Wno-unused-parameter liblog_la_SOURCES = log.cpp liblog_la_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe +nodist_liblogger_la_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h +liblogger_la_CXXFLAGS = -Wno-unused-parameter +liblogger_la_SOURCES = logger.cpp +liblogger_la_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe + client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs diff --git a/sca-cpp/trunk/components/log/adder-test.scm b/sca-cpp/trunk/components/log/adder-test.scm new file mode 100644 index 0000000000..ccd5bc555f --- /dev/null +++ b/sca-cpp/trunk/components/log/adder-test.scm @@ -0,0 +1,20 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. + +; Logger test case + +(define (add a b) (+ a b)) diff --git a/sca-cpp/trunk/components/log/client-test.cpp b/sca-cpp/trunk/components/log/client-test.cpp index 685534df8a..d35a892f8a 100644 --- a/sca-cpp/trunk/components/log/client-test.cpp +++ b/sca-cpp/trunk/components/log/client-test.cpp @@ -68,7 +68,7 @@ struct logLoop { bool testLogPerf() { const list<value> i = list<value>() + (list<value>() + "name" + string("Apple")) - + (list<value>() + "price" + string("$4.55")); + + (list<value>() + "price" + string("$2.99")); const value a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); http::CURLSession cs; @@ -81,6 +81,16 @@ bool testLogPerf() { return true; } +bool testLogger() { + http::CURLSession cs; + + const failable<value> res = http::evalExpr(mklist<value>(string("sum"), 33, 22), string("http://localhost:8090/client"), cs); + assert(hasContent(res)); + assert((int)content(res) == 55); + + return true; +} + } } @@ -89,6 +99,7 @@ int main() { tuscany::log::testLog(); tuscany::log::testLogPerf(); + tuscany::log::testLogger(); tuscany::cout << "OK" << tuscany::endl; diff --git a/sca-cpp/trunk/components/log/client-test.scm b/sca-cpp/trunk/components/log/client-test.scm new file mode 100644 index 0000000000..1da6ca3564 --- /dev/null +++ b/sca-cpp/trunk/components/log/client-test.scm @@ -0,0 +1,20 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. + +; Logger test case + +(define (sum a b adder) (adder "add" a b)) diff --git a/sca-cpp/trunk/components/log/log.composite b/sca-cpp/trunk/components/log/log.composite index 9b3747d142..b39a6a6c49 100644 --- a/sca-cpp/trunk/components/log/log.composite +++ b/sca-cpp/trunk/components/log/log.composite @@ -30,4 +30,28 @@ </service> </component> + <component name="client"> + <implementation.scheme script="client-test.scm"/> + <service name="client"> + <t:binding.http uri="client"/> + </service> + <reference name="adder" target="logger"/> + </component> + + <component name="logger"> + <implementation.cpp path=".libs" library="liblogger"/> + <property name="category">default</property> + <service name="logger"> + <t:binding.http uri="logger"/> + </service> + <reference name="relay" target="adder"/> + </component> + + <component name="adder"> + <implementation.scheme script="adder-test.scm"/> + <service name="adder"> + <t:binding.http uri="adder"/> + </service> + </component> + </composite> diff --git a/sca-cpp/trunk/components/log/logger.cpp b/sca-cpp/trunk/components/log/logger.cpp new file mode 100644 index 0000000000..e1f4712d61 --- /dev/null +++ b/sca-cpp/trunk/components/log/logger.cpp @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +/** + * Scribe-based logger component implementation, used to intercept + * and log service invocations. + */ + +#include "string.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" +#include "scribe.hpp" + +namespace tuscany { +namespace logger { + +/** + * Component implementation lambda function. + */ +class applyLog { +public: + applyLog(const lambda<value(const list<value>&)>& relay, const value& category, scribe::Scribe& sc) : relay(relay), 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); + + // Relay the function + const failable<value> res = relay(params); + + // Log the result + scribe::log(res, category, sc); + return res; + } + +private: + const lambda<value(const list<value>&)> relay; + const value category; + scribe::Scribe& sc; +}; + +/** + * Start the component. + */ +const failable<value> start(unused 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>()); + debug(category, "logger::start::category"); + + // Return the component implementation lambda function + return value(lambda<value(const list<value>&)>(applyLog(rel, category, sc))); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list<tuscany::value>& params) { + const tuscany::value func(car(params)); + if (func == "start") + return tuscany::logger::start(cdr(params)); + return tuscany::mkfailure<tuscany::value>(); +} + +} diff --git a/sca-cpp/trunk/components/log/scribe-test b/sca-cpp/trunk/components/log/scribe-test index 77bf795c9f..1c76b2eb58 100755 --- a/sca-cpp/trunk/components/log/scribe-test +++ b/sca-cpp/trunk/components/log/scribe-test @@ -30,7 +30,7 @@ sleep 1 # Test logging a message echo test | ./scribe-cat sleep 4 -grep test tmp/scribe/logs/central/default/* >/dev/null +grep test tmp/scribe/logs/central/default/default_current >/dev/null rc=$? # Cleanup diff --git a/sca-cpp/trunk/components/log/server-test b/sca-cpp/trunk/components/log/server-test index 9f14bcee8d..631487c77a 100755 --- a/sca-cpp/trunk/components/log/server-test +++ b/sca-cpp/trunk/components/log/server-test @@ -39,8 +39,17 @@ sleep 2 ./client-test 2>/dev/null rc=$? if [ "$rc" = "0" ]; then + echo "Testing..." sleep 4 - grep "Apple" tmp/scribe/logs/central/default/* >/dev/null + grep "Apple" tmp/scribe/logs/central/default/default_current >/dev/null + rc=$? +fi +if [ "$rc" = "0" ]; then + grep "(add 33 22)" tmp/scribe/logs/central/default/default_current >/dev/null + rc=$? +fi +if [ "$rc" = "0" ]; then + grep "55" tmp/scribe/logs/central/default/default_current >/dev/null rc=$? fi @@ -50,4 +59,7 @@ sleep 1 ./scribed-client-stop tmp ./scribed-central-stop tmp sleep 1 +if [ "$rc" = "0" ]; then + echo "OK" +fi return $rc |