/*
 * 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
 */

#include <tango/common/log4tango/Portability.h>
#ifdef TANGO_HAVE_UNISTD_H
  #include <unistd.h>
#endif
#include <tango/common/log4tango/OstreamAppender.h>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

namespace log4tango
{

OstreamAppender::OstreamAppender(const std::string &name, std::ostream *stream) :
    LayoutAppender(name),
    _stream(stream)
{
}

OstreamAppender::~OstreamAppender()
{
    close();
}

void OstreamAppender::close()
{
    // empty
}

int OstreamAppender::_append(const LoggingEvent &event)
{
    (*_stream) << get_layout().format(event);
    (*_stream) << std::endl;
    if(!_stream->good())
    {
        return -1;
    }
    return 0;
}

bool OstreamAppender::reopen()
{
    return true;
}
} // namespace log4tango
