#include "tile/base/logging/console_sink.h"

#include <stdio.h>

namespace tile {

ConsoleSink::Ptr
ConsoleSink::Create()
{
    return std::shared_ptr<ConsoleSink>(new ConsoleSink());
}

ConsoleSink::~ConsoleSink() {}

void
ConsoleSink::Send(LogSeverity severity,
                  const char *full_filename,
                  const char *base_filename,
                  int line,
                  const LogMessageTime &logmsgtime,
                  const char *message,
                  size_t message_len)
{
    auto msg = ToString(severity, full_filename, base_filename, line, logmsgtime, message, message_len);
    if (!msg.empty() && msg.back() != '\n') { msg.push_back('\n'); }
    ColoredWriteToStdout(severity, msg.c_str(), msg.size());
}

void
ConsoleSink::Flush()
{}

ConsoleSink::ConsoleSink() {}

}// namespace tile
