Simplified logger configuration, it no longer depends on Wt

This commit is contained in:
emeric
2023-11-24 16:23:31 +01:00
parent 6f47c32ac2
commit 9060c0d925
104 changed files with 2603 additions and 2598 deletions
@@ -22,6 +22,7 @@
#include <string>
#include <sstream>
#include "utils/String.hpp"
#include "Service.hpp"
enum class Severity
@@ -59,11 +60,11 @@ enum class Module
const char* getModuleName(Module mod);
const char* getSeverityName(Severity sev);
class Logger;
class ILogger;
class Log
{
public:
Log(Logger* logger, Module module, Severity severity);
Log(ILogger& logger, Module module, Severity severity);
~Log();
Module getModule() const { return _module; }
@@ -76,18 +77,24 @@ private:
Log(const Log&) = delete;
Log& operator=(const Log&) = delete;
ILogger& _logger;
Module _module;
Severity _severity;
std::ostringstream _oss;
Logger* _logger{};
};
class Logger
class ILogger
{
public:
virtual ~Logger() = default;
virtual ~ILogger() = default;
virtual bool isSeverityActive(Severity severity) const = 0;
virtual void processLog(const Log& log) = 0;
};
#define LMS_LOG(module, severity) Log{Service<Logger>::get(), Module::module, Severity::severity}.getOstream()
#define LMS_LOG_EX(module, severity) Log{Service<Logger>::get(), module, severity}.getOstream()
#define LMS_LOG(module, severity, message) \
do \
{ \
if (auto* logger {::Service<::ILogger>::get()}; logger && logger->isSeverityActive(::Severity::severity)) \
::Log{ *logger, ::Module::module, ::Severity::severity }.getOstream() << message; \
} while(0)
+10 -9
View File
@@ -20,19 +20,20 @@
#pragma once
#include "utils/EnumSet.hpp"
#include "utils/Logger.hpp"
#include "utils/ILogger.hpp"
class StreamLogger final : public Logger
class StreamLogger final : public ILogger
{
public:
static constexpr EnumSet<Severity> defaultSeverities {Severity::FATAL, Severity::ERROR, Severity::WARNING, Severity::INFO};
public:
static constexpr EnumSet<Severity> defaultSeverities{ Severity::FATAL, Severity::ERROR, Severity::WARNING, Severity::INFO };
StreamLogger(std::ostream& oss, EnumSet<Severity> severities = defaultSeverities);
StreamLogger(std::ostream& oss, EnumSet<Severity> severities = defaultSeverities);
void processLog(const Log& log);
bool isSeverityActive(Severity) const override { return true; }
void processLog(const Log& log) override;
private:
std::ostream& _os;
const EnumSet<Severity> _severities;
private:
std::ostream& _os;
const EnumSet<Severity> _severities;
};
+1 -4
View File
@@ -38,19 +38,16 @@ namespace Wt
namespace StringUtils {
[[nodiscard]] std::vector<std::string> splitStringCopy(std::string_view string, std::string_view separators);
[[nodiscard]] std::vector<std::string_view> splitString(std::string_view string, std::string_view separators);
[[nodiscard]] std::string joinStrings(const std::vector<std::string_view>& strings, std::string_view delimiter);
[[nodiscard]] std::string joinStrings(const std::vector<std::string>& strings, const std::string& delimiter);
[[nodiscard]] std::string_view stringTrim(std::string_view str, std::string_view whitespaces = " \t");
[[nodiscard]] std::string_view stringTrimEnd(std::string_view str, std::string_view whitespaces = " \t");
[[nodiscard]] std::string stringToLower(std::string_view str);
void stringToLower(std::string& str);
[[nodiscard]] std::string stringToUpper(const std::string& str);
[[nodiscard]] std::string bufferToString(const std::vector<unsigned char>& data);
+13 -5
View File
@@ -19,11 +19,19 @@
#pragma once
#include "Logger.hpp"
#include <string>
class WtLogger final : public Logger
#include "utils/ILogger.hpp"
class WtLogger final : public ILogger
{
public:
void processLog(const Log& log) override;
};
public:
WtLogger(Severity minSeverity);
static std::string computeLogConfig(Severity minSeverity);
private:
bool isSeverityActive(Severity severity) const override;
void processLog(const Log& log) override;
const Severity _minSeverity;
};