<commit_before>#include "atlas/core/Platform.hpp"
#include "atlas/core/Log.hpp"

#ifdef ATLAS_PLATFORM_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include <chrono>
#include <ctime>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <vector>

static const int kMaxLogLength = 16 * 1024;
static const std::vector<std::string> kLevelStrings =
std::vector<std::string>
{
    "debug",
    "info",
    "log",
    "error",
    "critical"
};


namespace atlas
{
    namespace core
    {
        static void _log(std::string const& message)
        {
            char buf[kMaxLogLength];
            memcpy(buf, message.c_str(), kMaxLogLength);

#ifdef ATLAS_PLATFORM_WINDOWS
            strncat_s(buf, "\n", 3);

            WCHAR wszBuf[kMaxLogLength] = { 0 };
            MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf));
            OutputDebugStringW(wszBuf);
            WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, buf, sizeof(buf),
                nullptr, FALSE);
            printf("%s", buf);
            fflush(stdout);
#else
            strncat(buf, "\n", 3);

            fprintf(stdout, "%s", buf);
            fflush(stdout);
#endif
        }

        static std::string getTimeStamp()
        {
            auto now = std::chrono::system_clock::now();
            auto nowTime = std::chrono::system_clock::to_time_t(now);

            std::stringstream stream;
            stream << std::put_time(std::localtime(&nowTime), "%T");
            return stream.str();
        }

        void Log::log(SeverityLevel level, std::string const& message)
        {
            std::string logMessage = "";

            // Get the current time stamp
            logMessage.append(getTimeStamp());
            logMessage.append("    ");

            std::string sevLevel = "[";
            int levelNum = static_cast<int>(level);
            sevLevel.append(kLevelStrings[levelNum]);
            sevLevel.append("] : ");

            logMessage.append(sevLevel);
            logMessage.append(message);
            _log(logMessage);
        }
    }
}<commit_msg>[brief] Fixes intermittent crash on Windows.<commit_after>#include "atlas/core/Platform.hpp"
#include "atlas/core/Log.hpp"

#ifdef ATLAS_PLATFORM_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include <chrono>
#include <ctime>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <vector>

static const int kMaxLogLength = 16 * 1024;
static const std::vector<std::string> kLevelStrings =
std::vector<std::string>
{
    "debug",
    "info",
    "log",
    "error",
    "critical"
};


namespace atlas
{
    namespace core
    {
        static void _log(std::string const& message)
        {
            char buf[kMaxLogLength];
            memcpy(buf, message.c_str(), message.size() + 1);

#ifdef ATLAS_PLATFORM_WINDOWS
            strncat_s(buf, "\n", 3);

            WCHAR wszBuf[kMaxLogLength] = { 0 };
            MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf));
            OutputDebugStringW(wszBuf);
            WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, buf, sizeof(buf),
                nullptr, FALSE);
            printf("%s", buf);
            fflush(stdout);
#else
            strncat(buf, "\n", 3);

            fprintf(stdout, "%s", buf);
            fflush(stdout);
#endif
        }

        static std::string getTimeStamp()
        {
            auto now = std::chrono::system_clock::now();
            auto nowTime = std::chrono::system_clock::to_time_t(now);

            std::stringstream stream;
            stream << std::put_time(std::localtime(&nowTime), "%T");
            return stream.str();
        }

        void Log::log(SeverityLevel level, std::string const& message)
        {
            std::string logMessage = "";

            // Get the current time stamp
            logMessage.append(getTimeStamp());
            logMessage.append("    ");

            std::string sevLevel = "[";
            int levelNum = static_cast<int>(level);
            sevLevel.append(kLevelStrings[levelNum]);
            sevLevel.append("] : ");

            logMessage.append(sevLevel);
            logMessage.append(message);
            _log(logMessage);
        }
    }
}
{'fraction_non_alphanumeric': 0.13563704748472027, 'fraction_numerical': 0.007757404795486601, 'mean_word_length': 2.2382039573820394, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, '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': '2328364', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1318, 'n_words': 264}