1 /* $Id: filter_log.cpp,v 1.13 2006-01-09 21:20:15 adam Exp $
2 Copyright (c) 2005, Index Data.
10 #include "package.hpp"
13 #include <boost/thread/mutex.hpp>
14 #include <boost/date_time/posix_time/posix_time.hpp>
17 #include "filter_log.hpp"
21 namespace yf = yp2::filter;
27 static boost::mutex m_log_mutex;
33 boost::mutex yf::Log::Rep::m_log_mutex;
35 yf::Log::Log(const std::string &x) : m_p(new Rep)
40 yf::Log::Log() : m_p(new Rep)
46 void yf::Log::process(yp2::Package &package) const
50 // getting timestamp for receiving of package
51 boost::posix_time::ptime receive_time
52 = boost::posix_time::microsec_clock::local_time();
54 // scope for locking Ostream
56 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
57 std::cout << receive_time << " " << m_p->m_msg;
58 std::cout << " request id=" << package.session().id();
59 std::cout << " close="
60 << (package.session().is_closed() ? "yes" : "no")
62 gdu = package.request().get();
65 yp2::odr odr(ODR_PRINT);
66 z_GDU(odr, &gdu, 0, 0);
70 // unlocked during move
73 // getting timestamp for sending of package
74 boost::posix_time::ptime send_time
75 = boost::posix_time::microsec_clock::local_time();
77 boost::posix_time::time_duration duration = send_time - receive_time;
79 // scope for locking Ostream
81 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
82 std::cout << send_time << " " << m_p->m_msg;
83 std::cout << " response id=" << package.session().id();
84 std::cout << " close="
85 << (package.session().is_closed() ? "yes " : "no ")
86 << "duration=" << duration
88 //<< "duration=" << duration.total_seconds()
89 // << "." << duration.fractional_seconds()
91 gdu = package.response().get();
94 yp2::odr odr(ODR_PRINT);
95 z_GDU(odr, &gdu, 0, 0);
100 static yp2::filter::Base* filter_creator()
102 return new yp2::filter::Log;
106 struct yp2_filter_struct yp2_filter_log = {
117 * indent-tabs-mode: nil
118 * c-file-style: "stroustrup"
120 * vim: shiftwidth=4 tabstop=8 expandtab