/*
 * SPDX-FileCopyrightText: 2000-2002 Copyright LifeLine Networks BV (www.lifeline.nl)
 * SPDX-FileCopyrightText: 2000-2002 Copyright Bastiaan Bakker
 * SPDX-FileCopyrightText: 2004 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#ifndef TANGO_COMMON_LOG4TANGO_LOGSTREAMBUF_H
#define TANGO_COMMON_LOG4TANGO_LOGSTREAMBUF_H

#include <tango/common/log4tango/Logger.h>
#include <tango/common/log4tango/Portability.h>

//-----------------------------------------------------------------------------
// #DEFINES
//-----------------------------------------------------------------------------
#define kDEFAULT_BUFFER_SIZE 512

namespace log4tango
{

//-----------------------------------------------------------------------------
// Class : LogStreamBuf
//-----------------------------------------------------------------------------
class LogStreamBuf : public std::streambuf
{
  public:
    LogStreamBuf(Logger *logger, Level::Value level, bool filter = true, size_t bsize = kDEFAULT_BUFFER_SIZE);

    virtual ~LogStreamBuf();

  protected:
    virtual std::streamsize xsputn(const char *, std::streamsize);

    virtual int sync(void);

  private:
    int flush_buffer(void);

    char *_buffer;

    Logger *_logger;

    Level::Value _level;

    bool _filter;
};

} // namespace log4tango

#endif // TANGO_COMMON_LOG4TANGO_LOGSTREAMBUF_H
