1 /* $Id: filter_log.cpp,v 1.16 2006-01-17 15:08:02 adam Exp $
2 Copyright (c) 2005, 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 yf = yp2::filter;
26 boost::mutex m_log_mutex;
32 yf::Log::Log(const std::string &x) : m_p(new Rep)
37 yf::Log::Log() : m_p(new Rep)
43 void yf::Log::process(yp2::Package &package) const
47 // getting timestamp for receiving of package
48 boost::posix_time::ptime receive_time
49 = boost::posix_time::microsec_clock::local_time();
51 // scope for locking Ostream
53 boost::mutex::scoped_lock scoped_lock(m_p->m_log_mutex);
54 std::cout << receive_time << " " << m_p->m_msg;
55 std::cout << " request id=" << package.session().id();
56 std::cout << " close="
57 << (package.session().is_closed() ? "yes" : "no")
59 gdu = package.request().get();
62 yp2::odr odr(ODR_PRINT);
63 z_GDU(odr, &gdu, 0, 0);
67 // unlocked during move
70 // getting timestamp for sending of package
71 boost::posix_time::ptime send_time
72 = boost::posix_time::microsec_clock::local_time();
74 boost::posix_time::time_duration duration = send_time - receive_time;
76 // scope for locking Ostream
78 boost::mutex::scoped_lock scoped_lock(m_p->m_log_mutex);
79 std::cout << send_time << " " << m_p->m_msg;
80 std::cout << " response id=" << package.session().id();
81 std::cout << " close="
82 << (package.session().is_closed() ? "yes " : "no ")
83 << "duration=" << duration
85 //<< "duration=" << duration.total_seconds()
86 // << "." << duration.fractional_seconds()
88 gdu = package.response().get();
91 yp2::odr odr(ODR_PRINT);
92 z_GDU(odr, &gdu, 0, 0);
97 void yf::Log::configure(const xmlNode *ptr)
99 for (ptr = ptr->children; ptr; ptr = ptr->next)
101 if (ptr->type != XML_ELEMENT_NODE)
103 if (!strcmp((const char *) ptr->name, "message"))
104 m_p->m_msg = yp2::xml::get_text(ptr);
107 throw yp2::filter::FilterException("Bad element "
108 + std::string((const char *)
114 static yp2::filter::Base* filter_creator()
116 return new yp2::filter::Log;
120 struct yp2_filter_struct yp2_filter_log = {
131 * indent-tabs-mode: nil
132 * c-file-style: "stroustrup"
134 * vim: shiftwidth=4 tabstop=8 expandtab