Removed redundant 'Bloom' namespace from entire codebase

This commit is contained in:
Nav
2023-08-13 15:47:51 +01:00
parent 0935ba65cf
commit 5896306f1a
555 changed files with 6254 additions and 6510 deletions

View File

@@ -2,64 +2,61 @@
#include <iostream>
namespace Bloom
{
void Logger::configure(const ProjectConfig& projectConfig) {
if (projectConfig.debugLoggingEnabled) {
Logger::debugPrintingEnabled = true;
Logger::debug("Debug log printing has been enabled");
}
}
void Logger::silence() {
Logger::debugPrintingEnabled = false;
Logger::infoPrintingEnabled = false;
Logger::errorPrintingEnabled = false;
Logger::warningPrintingEnabled = false;
}
void Logger::log(const LogEntry& logEntry) {
static auto timezoneAbbreviation = Services::DateTimeService::getTimeZoneAbbreviation(
logEntry.timestamp
).toStdString();
const auto lock = std::unique_lock(Logger::printMutex);
// Print the timestamp and id in a green font color:
std::cout << "\033[32m";
std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString()
+ timezoneAbbreviation;
if (!logEntry.threadName.empty()) {
std::cout << " [" << logEntry.threadName << "]";
}
std::cout << " [" << logEntry.id << "]: ";
std::cout << "\033[0m";
switch (logEntry.logLevel) {
case LogLevel::ERROR: {
// Errors in red
std::cout << "\033[31m";
std::cout << "[ERROR] ";
break;
}
case LogLevel::WARNING: {
// Warnings in yellow
std::cout << "\033[33m";
std::cout << "[WARNING] ";
break;
}
case LogLevel::INFO: {
std::cout << "[INFO] ";
break;
}
case LogLevel::DEBUG: {
std::cout << "[DEBUG] ";
break;
}
}
std::cout << logEntry.message << "\033[0m" << std::endl;
void Logger::configure(const ProjectConfig& projectConfig) {
if (projectConfig.debugLoggingEnabled) {
Logger::debugPrintingEnabled = true;
Logger::debug("Debug log printing has been enabled");
}
}
void Logger::silence() {
Logger::debugPrintingEnabled = false;
Logger::infoPrintingEnabled = false;
Logger::errorPrintingEnabled = false;
Logger::warningPrintingEnabled = false;
}
void Logger::log(const LogEntry& logEntry) {
static auto timezoneAbbreviation = Services::DateTimeService::getTimeZoneAbbreviation(
logEntry.timestamp
).toStdString();
const auto lock = std::unique_lock(Logger::printMutex);
// Print the timestamp and id in a green font color:
std::cout << "\033[32m";
std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString()
+ timezoneAbbreviation;
if (!logEntry.threadName.empty()) {
std::cout << " [" << logEntry.threadName << "]";
}
std::cout << " [" << logEntry.id << "]: ";
std::cout << "\033[0m";
switch (logEntry.logLevel) {
case LogLevel::ERROR: {
// Errors in red
std::cout << "\033[31m";
std::cout << "[ERROR] ";
break;
}
case LogLevel::WARNING: {
// Warnings in yellow
std::cout << "\033[33m";
std::cout << "[WARNING] ";
break;
}
case LogLevel::INFO: {
std::cout << "[INFO] ";
break;
}
case LogLevel::DEBUG: {
std::cout << "[DEBUG] ";
break;
}
}
std::cout << logEntry.message << "\033[0m" << std::endl;
}

View File

@@ -8,93 +8,90 @@
#include "src/ProjectConfig.hpp"
#include "src/Services/DateTimeService.hpp"
namespace Bloom
static_assert(std::atomic<std::uint32_t>::is_always_lock_free);
enum class LogLevel: std::uint8_t
{
static_assert(std::atomic<std::uint32_t>::is_always_lock_free);
INFO,
WARNING,
ERROR,
DEBUG,
};
enum class LogLevel: std::uint8_t
class LogEntry
{
public:
std::uint32_t id = ++(LogEntry::lastLogId);
std::string message;
LogLevel logLevel;
QDateTime timestamp = Services::DateTimeService::currentDateTime();
std::string threadName;
LogEntry(std::string message, LogLevel logLevel)
: message(std::move(message))
, logLevel(logLevel)
{
INFO,
WARNING,
ERROR,
DEBUG,
// Get thread name
std::array<char, 16> threadNameBuf = {};
if (::pthread_getname_np(::pthread_self(), threadNameBuf.data(), threadNameBuf.size()) == 0) {
/*
* The name of the main thread is also the name of the process, so we have to name the
* main thread "Bloom" (to prevent confusion).
*
* We override the main thread name when printing logs, to keep the format of the thread name in the
* logs consistent.
*/
this->threadName = std::string(threadNameBuf.data());
this->threadName = this->threadName == "Bloom" ? "MT" : this->threadName;
}
};
class LogEntry
{
public:
std::uint32_t id = ++(LogEntry::lastLogId);
std::string message;
LogLevel logLevel;
QDateTime timestamp = Services::DateTimeService::currentDateTime();
std::string threadName;
private:
static inline std::atomic<std::uint32_t> lastLogId = 0;
};
LogEntry(std::string message, LogLevel logLevel)
: message(std::move(message))
, logLevel(logLevel)
{
// Get thread name
std::array<char, 16> threadNameBuf = {};
/**
* Super simple thread safe static Logger class for basic logging.
*/
class Logger
{
public:
static void configure(const ProjectConfig& projectConfig);
if (::pthread_getname_np(::pthread_self(), threadNameBuf.data(), threadNameBuf.size()) == 0) {
/*
* The name of the main thread is also the name of the process, so we have to name the
* main thread "Bloom" (to prevent confusion).
*
* We override the main thread name when printing logs, to keep the format of the thread name in the
* logs consistent.
*/
this->threadName = std::string(threadNameBuf.data());
this->threadName = this->threadName == "Bloom" ? "MT" : this->threadName;
}
};
static void silence();
private:
static inline std::atomic<std::uint32_t> lastLogId = 0;
};
/**
* Super simple thread safe static Logger class for basic logging.
*/
class Logger
{
public:
static void configure(const ProjectConfig& projectConfig);
static void silence();
static void info(const std::string& message) {
if (Logger::infoPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::INFO));
}
static void info(const std::string& message) {
if (Logger::infoPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::INFO));
}
}
static void warning(const std::string& message) {
if (Logger::warningPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::WARNING));
}
static void warning(const std::string& message) {
if (Logger::warningPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::WARNING));
}
}
static void error(const std::string& message) {
if (Logger::errorPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::ERROR));
}
static void error(const std::string& message) {
if (Logger::errorPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::ERROR));
}
}
static void debug(const std::string& message) {
if (Logger::debugPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::DEBUG));
}
static void debug(const std::string& message) {
if (Logger::debugPrintingEnabled) {
Logger::log(LogEntry(message, LogLevel::DEBUG));
}
}
private:
static inline bool errorPrintingEnabled = true;
static inline bool warningPrintingEnabled = true;
static inline bool infoPrintingEnabled = true;
static inline bool debugPrintingEnabled = false;
private:
static inline bool errorPrintingEnabled = true;
static inline bool warningPrintingEnabled = true;
static inline bool infoPrintingEnabled = true;
static inline bool debugPrintingEnabled = false;
static inline std::mutex printMutex;
static inline std::mutex printMutex;
static void log(const LogEntry& logEntry);
};
}
static void log(const LogEntry& logEntry);
};