1 /* $Id: filter_log.cpp,v 1.11 2006-01-04 11:55:31 adam Exp $
2 Copyright (c) 2005, Index Data.
11 #include "package.hpp"
14 #include <boost/thread/mutex.hpp>
15 #include <boost/date_time/posix_time/posix_time.hpp>
18 #include "filter_log.hpp"
22 namespace yf = yp2::filter;
28 static boost::mutex m_log_mutex;
34 boost::mutex yf::Log::Rep::m_log_mutex;
36 yf::Log::Log(const std::string &x) : m_p(new Rep)
41 yf::Log::Log() : m_p(new Rep)
47 void yf::Log::process(Package &package) const
51 // getting timestamp for receiving of package
52 boost::posix_time::ptime receive_time
53 = boost::posix_time::microsec_clock::local_time();
55 // scope for locking Ostream
57 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
58 std::cout << receive_time << " " << m_p->m_msg;
59 std::cout << " request id=" << package.session().id();
60 std::cout << " close="
61 << (package.session().is_closed() ? "yes" : "no")
63 gdu = package.request().get();
66 yp2::odr odr(ODR_PRINT);
67 z_GDU(odr, &gdu, 0, 0);
71 // unlocked during move
74 // getting timestamp for sending of package
75 boost::posix_time::ptime send_time
76 = boost::posix_time::microsec_clock::local_time();
78 boost::posix_time::time_duration duration = send_time - receive_time;
80 // scope for locking Ostream
82 boost::mutex::scoped_lock scoped_lock(Rep::m_log_mutex);
83 std::cout << send_time << " " << m_p->m_msg;
84 std::cout << " response id=" << package.session().id();
85 std::cout << " close="
86 << (package.session().is_closed() ? "yes " : "no ")
87 << "duration=" << duration
89 //<< "duration=" << duration.total_seconds()
90 // << "." << duration.fractional_seconds()
92 gdu = package.response().get();
95 yp2::odr odr(ODR_PRINT);
96 z_GDU(odr, &gdu, 0, 0);
101 static yp2::filter::Base* filter_creator()
103 return new yp2::filter::Log;
107 struct yp2_filter_struct yp2_filter_log = {
118 * indent-tabs-mode: nil
119 * c-file-style: "stroustrup"
121 * vim: shiftwidth=4 tabstop=8 expandtab