diff options
| author | randomdan <randomdan@localhost> | 2011-02-10 10:33:36 +0000 |
|---|---|---|
| committer | randomdan <randomdan@localhost> | 2011-02-10 10:33:36 +0000 |
| commit | 66ead1d7832333feb2be2e42fb88af84b59f690b (patch) | |
| tree | 705a8548c3df1048e6bcef70f703a01d3867a758 /project2/cgi/cgiCommon.cpp | |
| parent | Make different DB connectors optional (diff) | |
| download | project2-66ead1d7832333feb2be2e42fb88af84b59f690b.tar.bz2 project2-66ead1d7832333feb2be2e42fb88af84b59f690b.tar.xz project2-66ead1d7832333feb2be2e42fb88af84b59f690b.zip | |
Fix silly bug loading readonly RDBMS config entries
Add centralised logging system
Add code for runtime configuration
Add support for configuring logging
Move all existing logging to new logging system
Diffstat (limited to 'project2/cgi/cgiCommon.cpp')
| -rw-r--r-- | project2/cgi/cgiCommon.cpp | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/project2/cgi/cgiCommon.cpp b/project2/cgi/cgiCommon.cpp index bfbec36..322bdf7 100644 --- a/project2/cgi/cgiCommon.cpp +++ b/project2/cgi/cgiCommon.cpp @@ -1,10 +1,10 @@ #include "cgiCommon.h" +#include "../logger.h" #include <libxml/tree.h> #include <glibmm/exception.h> #include <cgicc/CgiEnvironment.h> #include <cgicc/HTTPContentHeader.h> #include <cgicc/HTTPStatusHeader.h> -#include <fcgi_stdio.h> #include "cgiEnvironment.h" #include "cgiAppEngine.h" #include <boost/bind.hpp> @@ -19,41 +19,62 @@ xmlWrite(void * _out, const char * buf, int len) return len; } +// These are templates because some people don't inherit their +// exceptions from std::exception like normal people (Glib) +const char * +what(const Glib::Exception & e) +{ + return e.what().c_str(); +} +const char * +what(const std::exception & e) +{ + return e.what(); +} +template <typename E> +void +doExceptionReporting(const E & e, std::ostream & IO) +{ + char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL); + Logger()->messagef(LOG_ERR, "%s: Request errored: %s: %s", __FUNCTION__, buf, what(e)); + cgicc::HTTPStatusHeader header(500, e.what()); + header.render(IO); + IO << "Kaboom!" << std::endl + << std::endl + << buf << std::endl + << e.what() << std::endl; + free(buf); +} + void cgiServe(cgicc::CgiInput * i, std::ostream & IO) { + cgicc::Cgicc cgi(i); + CgiEnvironment env(&cgi); + env.init(); try { - cgicc::Cgicc cgi(i); - CgiEnvironment env(&cgi); CgiApplicationEngine app(&env); + + Logger()->messagef(LOG_DEBUG, "%s: Processing request", __FUNCTION__); app.process(); + + Logger()->messagef(LOG_DEBUG, "%s: Sending request result", __FUNCTION__); IO << "Cache-control: no-cache" << std::endl; app.getHeader()->render(IO); xmlOutputBufferPtr out = xmlOutputBufferCreateIO( xmlWrite, NULL, &IO, xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8)); app.write(boost::bind(xmlSaveFileTo, out, _1, "utf-8")); + + Logger()->messagef(LOG_DEBUG, "%s: Completed request", __FUNCTION__); } catch (const std::exception & e) { - cgicc::HTTPStatusHeader header(500, e.what()); - header.render(IO); - char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL); - IO << "Kaboom!" << std::endl - << std::endl - << buf << std::endl - << e.what() << std::endl; - free(buf); + doExceptionReporting(e, IO); } catch (const Glib::Exception & e) { - cgicc::HTTPStatusHeader header(500, e.what()); - header.render(IO); - char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL); - IO << "Kaboom!" << std::endl - << std::endl - << buf << std::endl - << e.what() << std::endl; - free(buf); + doExceptionReporting(e, IO); } catch (...) { + Logger()->messagef(LOG_ERR, "%s: Request errored: Unknown exception", __FUNCTION__); cgicc::HTTPStatusHeader header(500, "Unknown exception"); header.render(IO); IO << "Kaboom!" << std::endl |
