#ifndef _KLOG2_H_
#define _KLOG2_H_

#include <log4cpp/Category.hh>
#include <ostream>
#include <klog/klog.h>

class cLogOStream;

class cLogBuffer : public std::basic_streambuf<char, std::char_traits<char> >
{
private:
   cLogOStream & mStream;
   char mLogBuffer[1024];

public:
   cLogBuffer(cLogOStream &p) : mStream(p)
   {
      setp(&mLogBuffer[0],&mLogBuffer[1023]);
   }
protected:
   virtual int sync();
};


class cLogOStream : public std::basic_ostream< char, std::char_traits< char > >
{
private:
   cLogBuffer mBuffer;
public:
   cLogOStream() : mBuffer(*this)
    {
       init(&mBuffer);
    }
   virtual void logOutput(char *str) = 0;
};


class cLog : public cLogOStream
{
public:
   cLog(const char * log_name) : mLogName(log_name)
   {

   }
   virtual void logOutput(char *str)
   {
      log4cpp::Category & cat = log4cpp::Category::getInstance(mLogName);
      cat.info(str);
   }
private:
   const char * mLogName;
};

class cDebug : public cLogOStream
{
public:
   cDebug(const char * log_name) : mLogName(log_name)
   {

   }
   virtual void logOutput(char *str)
   {
      log4cpp::Category & cat = log4cpp::Category::getInstance(mLogName);
      cat.debug(str);
   }
private:
   const char * mLogName;
};

class cError : public cLogOStream
{
public:
   cError(const char * log_name) : mLogName(log_name)
   {

   }
   virtual void logOutput(char *str)
   {
      log4cpp::Category & cat = log4cpp::Category::getInstance(mLogName);
      cat.error(str);
   }
private:
   const char * mLogName;
};


class cKlog2 : public cKlog
{
private:

   class cLogOStream;

public:
   cKlog2(const char * cat_name);
   cLog log;
   cDebug dbg;
   cError err;

};
#endif


