<commit_before>// Copyright (C) 2018 <NAME>
// This file is part of the Ouzel engine.

#include "core/Setup.h"
#include <iostream>
#include <string>

#if OUZEL_PLATFORM_IOS || OUZEL_PLATFORM_TVOS
#include <sys/syslog.h>
#endif

#if OUZEL_PLATFORM_WINDOWS
#include <windows.h>
#include <strsafe.h>
#endif

#if OUZEL_PLATFORM_ANDROID
#include <android/log.h>
#endif

#if OUZEL_PLATFORM_EMSCRIPTEN
#include <emscripten.h>
#endif

#include "Log.hpp"

namespace ouzel
{
#ifdef DEBUG
    Log::Level Log::threshold = Log::Level::ALL;
#else
    Log::Level Log::threshold = Log::Level::INFO;

#endif

    Log::~Log()
    {
        if (!s.empty())
        {
#if OUZEL_PLATFORM_MACOS || OUZEL_PLATFORM_LINUX || OUZEL_PLATFORM_RASPBIAN
            switch (level)
            {
                case Level::ERR:
                case Level::WARN:
                    std::cerr << s << std::endl;
                    break;
                case Level::INFO:
                case Level::ALL:
                    std::cout << s << std::endl;
                    break;
                default: break;
            }
#elif OUZEL_PLATFORM_IOS || OUZEL_PLATFORM_TVOS
            int priority = 0;
            switch (level)
            {
                case Level::ERR: priority = LOG_ERR; break;
                case Level::WARN: priority = LOG_WARNING; break;
                case Level::INFO: priority = LOG_INFO; break;
                case Level::ALL: priority = LOG_DEBUG; break;
                default: break;
            }
            syslog(priority, "%s", s.c_str());
#elif OUZEL_PLATFORM_WINDOWS
            std::vector<wchar_t> szBuffer(s.length() + 2);
            if (MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, szBuffer.data(), static_cast<int>(szBuffer.size())) == 0)
            {
                Log(Log::Level::ERR) << "Failed to convert UTF-8 to wide char";
                return;
            }

            StringCchCatW(szBuffer.data(), szBuffer.size(), L"\n");
            OutputDebugStringW(szBuffer.data());

    #if DEBUG
            HANDLE handle = 0;
            switch (level)
            {
            case Level::ERR:
            case Level::WARN:
                handle = GetStdHandle(STD_ERROR_HANDLE);
                break;
            case Level::INFO:
            case Level::ALL:
                handle = GetStdHandle(STD_OUTPUT_HANDLE);
                break;
            default: break;
            }

            if (handle)
            {
                DWORD bytesWritten;
                WriteConsoleW(handle, szBuffer.data(), static_cast<DWORD>(wcslen(szBuffer.data())), &bytesWritten, nullptr);
            }
    #endif<commit_msg>Add one char to szBuffer instead of two<commit_after>// Copyright (C) 2018 <NAME>
// This file is part of the Ouzel engine.

#include "core/Setup.h"
#include <iostream>
#include <string>

#if OUZEL_PLATFORM_IOS || OUZEL_PLATFORM_TVOS
#include <sys/syslog.h>
#endif

#if OUZEL_PLATFORM_WINDOWS
#include <windows.h>
#include <strsafe.h>
#endif

#if OUZEL_PLATFORM_ANDROID
#include <android/log.h>
#endif

#if OUZEL_PLATFORM_EMSCRIPTEN
#include <emscripten.h>
#endif

#include "Log.hpp"

namespace ouzel
{
#ifdef DEBUG
    Log::Level Log::threshold = Log::Level::ALL;
#else
    Log::Level Log::threshold = Log::Level::INFO;

#endif

    Log::~Log()
    {
        if (!s.empty())
        {
#if OUZEL_PLATFORM_MACOS || OUZEL_PLATFORM_LINUX || OUZEL_PLATFORM_RASPBIAN
            switch (level)
            {
                case Level::ERR:
                case Level::WARN:
                    std::cerr << s << std::endl;
                    break;
                case Level::INFO:
                case Level::ALL:
                    std::cout << s << std::endl;
                    break;
                default: break;
            }
#elif OUZEL_PLATFORM_IOS || OUZEL_PLATFORM_TVOS
            int priority = 0;
            switch (level)
            {
                case Level::ERR: priority = LOG_ERR; break;
                case Level::WARN: priority = LOG_WARNING; break;
                case Level::INFO: priority = LOG_INFO; break;
                case Level::ALL: priority = LOG_DEBUG; break;
                default: break;
            }
            syslog(priority, "%s", s.c_str());
#elif OUZEL_PLATFORM_WINDOWS
            std::vector<wchar_t> szBuffer(s.length() + 1);
            if (MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, szBuffer.data(), static_cast<int>(szBuffer.size())) == 0)
            {
                Log(Log::Level::ERR) << "Failed to convert UTF-8 to wide char";
                return;
            }

            StringCchCatW(szBuffer.data(), szBuffer.size(), L"\n");
            OutputDebugStringW(szBuffer.data());

    #if DEBUG
            HANDLE handle = 0;
            switch (level)
            {
            case Level::ERR:
            case Level::WARN:
                handle = GetStdHandle(STD_ERROR_HANDLE);
                break;
            case Level::INFO:
            case Level::ALL:
                handle = GetStdHandle(STD_OUTPUT_HANDLE);
                break;
            default: break;
            }

            if (handle)
            {
                DWORD bytesWritten;
                WriteConsoleW(handle, szBuffer.data(), static_cast<DWORD>(wcslen(szBuffer.data())), &bytesWritten, nullptr);
            }
    #endif
{'fraction_non_alphanumeric': 0.11742707554225879, 'fraction_numerical': 0.004487658937920718, 'mean_word_length': 1.745893223819302, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 25, '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': '1414680', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1636, 'n_words': 356}