1 /* $Id: filter_log.cpp,v 1.17 2006-03-16 10:40:59 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
12 #include <boost/thread/mutex.hpp>
13 #include <boost/date_time/posix_time/posix_time.hpp>
16 #include "filter_log.hpp"
20 namespace mp = metaproxy_1;
21 namespace yf = mp::filter;
23 namespace metaproxy_1 {
27 boost::mutex m_log_mutex;
33 yf::Log::Log(const std::string &x) : m_p(new Rep)
38 yf::Log::Log() : m_p(new Rep)
44 void yf::Log::process(mp::Package &package) const
48 // getting timestamp for receiving of package
49 boost::posix_time::ptime receive_time
50 = boost::posix_time::microsec_clock::local_time();
52 // scope for locking Ostream
54 boost::mutex::scoped_lock scoped_lock(m_p->m_log_mutex);
55 std::cout << receive_time << " " << m_p->m_msg;
56 std::cout << " request id=" << package.session().id();
57 std::cout << " close="
58 << (package.session().is_closed() ? "yes" : "no")
60 gdu = package.request().get();
63 mp::odr odr(ODR_PRINT);
64 z_GDU(odr, &gdu, 0, 0);
68 // unlocked during move
71 // getting timestamp for sending of package
72 boost::posix_time::ptime send_time
73 = boost::posix_time::microsec_clock::local_time();
75 boost::posix_time::time_duration duration = send_time - receive_time;
77 // scope for locking Ostream
79 boost::mutex::scoped_lock scoped_lock(m_p->m_log_mutex);
80 std::cout << send_time << " " << m_p->m_msg;
81 std::cout << " response id=" << package.session().id();
82 std::cout << " close="
83 << (package.session().is_closed() ? "yes " : "no ")
84 << "duration=" << duration
86 //<< "duration=" << duration.total_seconds()
87 // << "." << duration.fractional_seconds()
89 gdu = package.response().get();
92 mp::odr odr(ODR_PRINT);
93 z_GDU(odr, &gdu, 0, 0);
98 void yf::Log::configure(const xmlNode *ptr)
100 for (ptr = ptr->children; ptr; ptr = ptr->next)
102 if (ptr->type != XML_ELEMENT_NODE)
104 if (!strcmp((const char *) ptr->name, "message"))
105 m_p->m_msg = mp::xml::get_text(ptr);
108 throw mp::filter::FilterException("Bad element "
109 + std::string((const char *)
115 static mp::filter::Base* filter_creator()
117 return new mp::filter::Log;
121 struct metaproxy_1_filter_struct metaproxy_1_filter_log = {
132 * indent-tabs-mode: nil
133 * c-file-style: "stroustrup"
135 * vim: shiftwidth=4 tabstop=8 expandtab