<commit_before>﻿//
// Copyright(c) 2016-2017 benikabocha.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//

#include "Log.h"
#include "UnicodeUtil.h"

#include <iostream>

#if _WIN32

#include <Windows.h>

#endif // _WIN32

namespace saba
{
	DefaultSink::DefaultSink()
	{
		m_defaultLogger = spdlog::stdout_color_mt("default");
	}

	void DefaultSink::log(const spdlog::details::log_msg & msg)
	{
#if _WIN32
		auto utf8Message = msg.raw.str();
		std::wstring wMessage;
		if (!TryToWString(utf8Message, wMessage))
		{
			m_defaultLogger->log(msg.level, "Failed to convert message.");
			return;
		}
		int chCount = WideCharToMultiByte(
			CP_OEMCP,
			0,
			wMessage.c_str(),
			(int)wMessage.size(),
			nullptr,
			0,
			0,
			FALSE
		);
		std::string oemMessage(chCount, '\0');
		WideCharToMultiByte(
			CP_OEMCP,
			0,
			wMessage.c_str(),
			(int)wMessage.size(),
			&oemMessage[0],
			chCount,
			0,
			FALSE
		);
		m_defaultLogger->log(msg.level, oemMessage);
#else // _WIN32
		m_defaultLogger->log(msg.level, msg.raw.c_str());
#endif // _WIN32
	}

	void DefaultSink::flush()
	{
		m_defaultLogger->flush();
	}
}<commit_msg>Set the output code page UTF-8.(Windows)<commit_after>﻿//
// Copyright(c) 2016-2017 benikabocha.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//

#include "Log.h"
#include "UnicodeUtil.h"

#include <iostream>

#if _WIN32

#include <Windows.h>

#endif // _WIN32

namespace saba
{
	DefaultSink::DefaultSink()
	{
		m_defaultLogger = spdlog::stdout_color_mt("default");
#if _WIN32
		SetConsoleOutputCP(CP_UTF8);
#endif // _WIN32
	}

	void DefaultSink::log(const spdlog::details::log_msg & msg)
	{
		m_defaultLogger->log(msg.level, msg.raw.c_str());
	}

	void DefaultSink::flush()
	{
		m_defaultLogger->flush();
	}
}
{'fraction_non_alphanumeric': 0.15933147632311978, 'fraction_numerical': 0.025069637883008356, 'mean_word_length': 4.030812324929972, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5248108', 'n_tokens_mistral': 783, 'n_tokens_neox': 704, 'n_words': 127}