1 /* $Id: filter_log.cpp,v 1.15 2006-01-11 11:51:49 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 static boost::mutex m_log_mutex;
32 boost::mutex yf::Log::Rep::m_log_mutex;
34 yf::Log::Log(const std::string &x) : m_p(new Rep)
39 yf::Log::Log() : m_p(new Rep)
45 void yf::Log::process(yp2::Package &package) const
49 // getting timestamp for receiving of package
50 boost::posix_time::ptime receive_time
51 = boost::posix_time::microsec_clock::local_time();
53 // scope for locking Ostream
55 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
56 std::cout << receive_time << " " << m_p->m_msg;
57 std::cout << " request id=" << package.session().id();
58 std::cout << " close="
59 << (package.session().is_closed() ? "yes" : "no")
61 gdu = package.request().get();
64 yp2::odr odr(ODR_PRINT);
65 z_GDU(odr, &gdu, 0, 0);
69 // unlocked during move
72 // getting timestamp for sending of package
73 boost::posix_time::ptime send_time
74 = boost::posix_time::microsec_clock::local_time();
76 boost::posix_time::time_duration duration = send_time - receive_time;
78 // scope for locking Ostream
80 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
81 std::cout << send_time << " " << m_p->m_msg;
82 std::cout << " response id=" << package.session().id();
83 std::cout << " close="
84 << (package.session().is_closed() ? "yes " : "no ")
85 << "duration=" << duration
87 //<< "duration=" << duration.total_seconds()
88 // << "." << duration.fractional_seconds()
90 gdu = package.response().get();
93 yp2::odr odr(ODR_PRINT);
94 z_GDU(odr, &gdu, 0, 0);
99 void yf::Log::configure(const xmlNode *ptr)
101 for (ptr = ptr->children; ptr; ptr = ptr->next)
103 if (ptr->type != XML_ELEMENT_NODE)
105 if (!strcmp((const char *) ptr->name, "message"))
106 m_p->m_msg = yp2::xml::get_text(ptr);
109 throw yp2::filter::FilterException("Bad element "
110 + std::string((const char *)
116 static yp2::filter::Base* filter_creator()
118 return new yp2::filter::Log;
122 struct yp2_filter_struct yp2_filter_log = {
133 * indent-tabs-mode: nil
134 * c-file-style: "stroustrup"
136 * vim: shiftwidth=4 tabstop=8 expandtab