From 8262f6efdd9bf0b99e566e3b7017c1a361f4dd99 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 23 May 2010 18:52:42 +0000 Subject: 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 --- sca-cpp/trunk/components/log/Makefile.am | 8 ++- sca-cpp/trunk/components/log/adder-test.scm | 20 ++++++ sca-cpp/trunk/components/log/client-test.cpp | 13 +++- sca-cpp/trunk/components/log/client-test.scm | 20 ++++++ sca-cpp/trunk/components/log/log.composite | 24 ++++++++ sca-cpp/trunk/components/log/logger.cpp | 92 ++++++++++++++++++++++++++++ sca-cpp/trunk/components/log/scribe-test | 2 +- sca-cpp/trunk/components/log/server-test | 14 ++++- 8 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 sca-cpp/trunk/components/log/adder-test.scm create mode 100644 sca-cpp/trunk/components/log/client-test.scm create mode 100644 sca-cpp/trunk/components/log/logger.cpp 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 i = list() + (list() + "name" + string("Apple")) - + (list() + "price" + string("$4.55")); + + (list() + "price" + string("$2.99")); const value a = mklist(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 res = http::evalExpr(mklist(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 @@ + + + + + + + + + + + default + + + + + + + + + + + + + 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&)>& relay, const value& category, scribe::Scribe& sc) : relay(relay), category(category), sc(sc) { + } + + const value operator()(const list& params) const { + // Log the function params + debug(params, "logger::apply::params"); + scribe::log(params, category, sc); + + // Relay the function + const failable res = relay(params); + + // Log the result + scribe::log(res, category, sc); + return res; + } + +private: + const lambda&)> relay; + const value category; + scribe::Scribe& sc; +}; + +/** + * Start the component. + */ +const failable start(unused const list& params) { + // Connect to Scribe + scribe::Scribe& sc = *(new (gc_new()) scribe::Scribe("localhost", 1464)); + + // Extract the configured relay service and category + const value rel = car(params); + const value category = ((lambda)>)cadr(params))(list()); + debug(category, "logger::start::category"); + + // Return the component implementation lambda function + return value(lambda&)>(applyLog(rel, category, sc))); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list& params) { + const tuscany::value func(car(params)); + if (func == "start") + return tuscany::logger::start(cdr(params)); + return tuscany::mkfailure(); +} + +} 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 -- cgit v1.2.3