From d5a8c51d4010285be02f3252520300a737799872 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Apr 2015 16:29:15 +0200 Subject: Add diagnostics support --- brep/module.cxx | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'brep/module.cxx') diff --git a/brep/module.cxx b/brep/module.cxx index 1837ccd..31e5f99 100644 --- a/brep/module.cxx +++ b/brep/module.cxx @@ -4,10 +4,13 @@ #include +#include // bind() + using namespace std; namespace brep { + void module:: handle (request& rq, response& rs, log& l) { @@ -19,10 +22,16 @@ namespace brep } catch (const invalid_request& e) { - // @@ Format as HTML in proper style. + // @@ Both log and format as HTML in proper style, etc. // rs.content (e.status, "text/html;charset=utf-8") << e.description; } + catch (const server_error& e) + { + // @@ Both log and return as 505. + // + write (move (e.data)); + } catch (const exception& e) { // @@ Exception: log e.what () & 505. @@ -36,4 +45,23 @@ namespace brep rs.status (505); } } + + module:: + module () + : error (severity::error, log_writer_), + warn (severity::warn, log_writer_), + info (severity::info, log_writer_), + log_writer_ (bind (&module::write, this, _1)) + { + } + + void module:: + log_write (diag_data&& d) const + { + if (log_ == nullptr) + return; // No backend yet. + + //@@ Cast log_ to apache::log and write the records. + // + } } -- cgit v1.1