view Core/LoggingUtils.h @ 3700:5cbbf14e516b

Fix issue #103 ("queries/.../retrieve" API returns HTTP code 200 even on server errors)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Feb 2020 13:21:41 +0100
parents 815b81142ff7
children
line wrap: on
line source

#include <sstream>
#include <iostream>

namespace Orthanc
{
  namespace Logging
  {

    /**
      std::streambuf subclass used in FunctionCallingStream
    */
    template<typename T>
    class FuncStreamBuf : public std::stringbuf
    {
    public:
      FuncStreamBuf(T func) : func_(func) {}

      virtual int sync()
      {
        std::string text = this->str();
        const char* buf = text.c_str();
        func_(buf);
        this->str("");
        return 0;
      }
    private:
      T func_;
    };
  }
}