use C++11's put time to put the timestamp

This commit is contained in:
Dennis Luxen 2014-05-07 16:50:48 +02:00
parent 700747801c
commit 7b9b2fd23a
2 changed files with 9 additions and 15 deletions

View File

@ -37,7 +37,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/Reply.h>
#include <osrm/RouteParameters.h>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <iostream>
RequestHandler::RequestHandler() : routing_machine(NULL) { }
@ -48,19 +51,10 @@ void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){
std::string request;
URIDecode(req.uri, request);
time_t ltime;
struct tm *Tm;
std::time_t t = std::time(nullptr);
ltime=time(NULL);
Tm=localtime(&ltime);
SimpleLogger().Write() <<
(Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" <<
(Tm->tm_mon+1 < 10 ? "0" : "" ) << (Tm->tm_mon+1) << "-" <<
1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) <<
Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) <<
Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) <<
Tm->tm_sec << " " << req.endpoint.to_string() << " " <<
SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
" " << req.endpoint.to_string() << " " <<
req.referrer << ( 0 == req.referrer.length() ? "- " :" ") <<
req.agent << ( 0 == req.agent.length() ? "- " :" ") << request;

View File

@ -28,8 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef REQUEST_HANDLER_H
#define REQUEST_HANDLER_H
#include <boost/noncopyable.hpp>
#include <string>
template <typename Iterator, class HandlerT>
@ -42,12 +40,14 @@ namespace http {
struct Request;
}
class RequestHandler : private boost::noncopyable {
class RequestHandler
{
public:
typedef APIGrammar<std::string::iterator, RouteParameters> APIGrammarParser;
RequestHandler();
RequestHandler(const RequestHandler &) = delete;
void handle_request(const http::Request& req, http::Reply& rep);
void RegisterRoutingMachine(OSRM * osrm);