<commit_before>/**
 * \authors <NAME>, <NAME>
 *
 * Copyright (c) 2014, <NAME>. All rights reserved.
 * This file is licensed under the "BSD 3-Clause License".
 * Full license text is under the file "LICENSE" provided with this code.
 */

#include "Vout.hpp"

#include "Logging.hpp"

#include <iomanip>
#include <iostream>

namespace Vesper {

struct LoggingMessage {
    std::string message;
    LoggingTypes::LoggingClientType type;
    int id;
};

}; /* namespace Vesper */

using namespace Vesper;

Vout Vout::staticInstance = {};

Vout::Vout() : loggingThread(), threadRunning(false), lMutex(), messages()
{
    std::cout << "[logclass] starting: starting thread..." << std::endl;
    loggingThread = std::thread(&Vout::threadFunction, this);
    while (!threadRunning);
}

Vout::~Vout()
{
    threadRunning = false;
    loggingThread.join();
    std::cout << "[logclass] stopping: logging finished successfully!";
    std::cout << std::endl;
}

void Vout::pushMessage(std::string messageStr,
    LoggingTypes::LoggingClientType type, int id)
{
    // thread-safe add message to queue
    staticInstance.lMutex.lock();
    staticInstance.messages.push(new LoggingMessage{messageStr, type, id});
    staticInstance.lMutex.unlock();
}

void Vout::threadFunction()
{
    threadRunning = true;

    std::cout << "[logclass] loggingThread: started!" << std::endl;

    while (threadRunning || (messages.empty() == false)) {
        // thread-safe pop message from queue
        lMutex.lock();
        if (messages.empty()) {
            lMutex.unlock();
            continue;
        }

        LoggingMessage *loggingMessage = messages.front();
        messages.pop();
        lMutex.unlock();

        //print the header:
        if (loggingMessage->type == LoggingTypes::client) {
            std::cout << "[client ";
        } else {
            std::cout << "[server ";
        }
        std::cout << "|" << std::setw(5);
        std::cout << loggingMessage->id << "] ";
        std::cout << loggingMessage->message << '\n';
    }
    std::cout << "[logclass] loggingThread: stopped!" << std::endl;
    return;
}<commit_msg>Improved visual appearance of logging messages.<commit_after>/**
 * \authors <NAME>, <NAME>
 *
 * Copyright (c) 2014, <NAME>. All rights reserved.
 * This file is licensed under the "BSD 3-Clause License".
 * Full license text is under the file "LICENSE" provided with this code.
 */

#include "Vout.hpp"

#include "Logging.hpp"

#include <iomanip>
#include <iostream>

namespace Vesper {

struct LoggingMessage {
    std::string message;
    LoggingTypes::LoggingClientType type;
    int id;
};

}; /* namespace Vesper */

using namespace Vesper;

Vout Vout::staticInstance = {};

Vout::Vout() : loggingThread(), threadRunning(false), lMutex(), messages()
{
    std::cout << "[ logclass      ] starting: starting thread..." << std::endl;
    loggingThread = std::thread(&Vout::threadFunction, this);
    while (!threadRunning);
}

Vout::~Vout()
{
    threadRunning = false;
    loggingThread.join();
    std::cout << "[ logclass      ] stopping: logging finished successfully!";
    std::cout << std::endl;
}

void Vout::pushMessage(std::string messageStr,
    LoggingTypes::LoggingClientType type, int id)
{
    // thread-safe add message to queue
    staticInstance.lMutex.lock();
    staticInstance.messages.push(new LoggingMessage{messageStr, type, id});
    staticInstance.lMutex.unlock();
}

void Vout::threadFunction()
{
    threadRunning = true;

    std::cout << "[ logclass      ] loggingThread: started!" << std::endl;

    while (threadRunning || (messages.empty() == false)) {
        // thread-safe pop message from queue
        lMutex.lock();
        if (messages.empty()) {
            lMutex.unlock();
            continue;
        }

        LoggingMessage *loggingMessage = messages.front();
        messages.pop();
        lMutex.unlock();

        //print the header:
        if (loggingMessage->type == LoggingTypes::client) {
            std::cout << "[ client ";
        } else {
            std::cout << "[ server ";
        }
        std::cout << "|" << std::setw(5);
        std::cout << loggingMessage->id << " ] ";
        std::cout << loggingMessage->message << '\n';
    }
    std::cout << "[ logclass      ] loggingThread: stopped!" << std::endl;
    return;
}
{'fraction_non_alphanumeric': 0.15706685172334028, 'fraction_numerical': 0.002775850104094379, 'mean_word_length': 2.9963031423290203, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 19, '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': '1735558', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1269, 'n_words': 315}