aboutsummaryrefslogtreecommitdiff
path: root/src/base/log/StdioLogTarget.cpp
blob: a17e91b649bd45ad677723d6e735561449ffdca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "cru/base/log/StdioLogTarget.h"

#ifdef _WIN32
#include "cru/base/String.h"
#endif

#include <iostream>

namespace cru::log {
StdioLogTarget::StdioLogTarget() {}

StdioLogTarget::~StdioLogTarget() {}

void StdioLogTarget::Write(log::LogLevel level, std::string message) {
#ifdef CRU_PLATFORM_WINDOWS
  String s = String::FromUtf8(message);
  if (level == log::LogLevel::Error) {
    std::wcerr.write(reinterpret_cast<const wchar_t*>(s.data()), s.size());
  } else {
    std::wcout.write(reinterpret_cast<const wchar_t*>(s.data()), s.size());
  }
#else
  if (level == log::LogLevel::Error) {
    std::cerr << message;
  } else {
    std::cout << message;
  }
#endif
}
}  // namespace cru::log