From e950a9bf429fe62797409db42296b17f79ed7f98 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 11 Jul 2018 10:36:26 +0200 Subject: [PATCH] Improve logging on RestApi --- src/RestApi.cpp | 20 +++++++++++++++----- src/RestApi.hpp | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/RestApi.cpp b/src/RestApi.cpp index 105e193..e595237 100644 --- a/src/RestApi.cpp +++ b/src/RestApi.cpp @@ -82,13 +82,17 @@ void RestApi::start_rest_api(WriterManager& writer_manager, uint16_t port) } catch (const boost::bad_any_cast& exception) { stringstream error_message; - error_message << "Cannot cast parameter " << parameter_name << " into specified type." << endl; + using namespace date; + error_message << "[" << std::chrono::system_clock::now() << "]"; + error_message << "[RestApi::parameters(get)] Cannot cast parameter " << parameter_name << " into specified type." << endl; throw runtime_error(error_message.str()); } catch (const out_of_range& exception){ stringstream error_message; - error_message << "No type mapping for parameter " << parameter_name << " in file format."<< endl; + using namespace date; + error_message << "[" << std::chrono::system_clock::now() << "]"; + error_message << "[RestApi::parameters(get)] No type mapping for parameter " << parameter_name << " in file format."<< endl; throw runtime_error(error_message.str()); } @@ -115,20 +119,26 @@ void RestApi::start_rest_api(WriterManager& writer_manager, uint16_t port) new_parameters[parameter_name] = string(item.s()); } else { stringstream error_message; - error_message << "No NX type mapping for parameter " << parameter_name << endl; + using namespace date; + error_message << "[" << std::chrono::system_clock::now() << "]"; + error_message << "[RestApi::parameters(post)] No NX type mapping for parameter " << parameter_name << endl; throw runtime_error(error_message.str()); } } catch (const out_of_range& exception){ stringstream error_message; - error_message << "No type mapping for received parameter " << parameter_name << " in file format."<< endl; + using namespace date; + error_message << "[" << std::chrono::system_clock::now() << "]"; + error_message << "[RestApi::parameters(post)] No type mapping for received parameter " << parameter_name << " in file format."<< endl; throw runtime_error(error_message.str()); } catch (const boost::bad_any_cast& exception) { stringstream error_message; - error_message << "Cannot cast parameter " << parameter_name << " into specified type." << endl; + using namespace date; + error_message << "[" << std::chrono::system_clock::now() << "]"; + error_message << "[RestApi::parameters(post)] Cannot cast parameter " << parameter_name << " into specified type." << endl; throw runtime_error(error_message.str()); diff --git a/src/RestApi.hpp b/src/RestApi.hpp index dde9ed3..01c0259 100644 --- a/src/RestApi.hpp +++ b/src/RestApi.hpp @@ -2,6 +2,8 @@ #define RESTAPI_H #include "WriterManager.hpp" +#include +#include "date.h" namespace RestApi {