feat: introduce LogLevel value object and improve logger API
- Replace LogLevel enum with a dedicated class that encapsulates log level representation. - Add factory methods for creating Debug, Info, and Error levels. - Add string conversion support through LogLevel::toString(). - Add equality comparison operators for LogLevel instances. - Rename Logger::writeLog() to writeMessage(). - Add writeMessage() overload that uses the default log level. - Implement actual file writing with error handling using core::Status. - Improve logger documentation to reflect the updated API. - Update logger tests to use the new LogLevel API. - Move logger tests into the core test directory. - Replace enum-based log level usage with LogLevel factory methods. - Update test cases for the renamed writeMessage() method.
This commit is contained in:
@@ -1,7 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace logger {
|
||||
|
||||
enum class LogLevel { Debug = 0, Info = 1, Error = 2 };
|
||||
/**
|
||||
* @brief Представляет уровень логирования.
|
||||
*
|
||||
* Экземпляры класса создаются только через статические фабричные методы.
|
||||
*/
|
||||
class LogLevel {
|
||||
public:
|
||||
/**
|
||||
* @brief Создает уровень Debug.
|
||||
*/
|
||||
static LogLevel debug() { return LogLevel(Type::Debug); }
|
||||
|
||||
/**
|
||||
* @brief Создает уровень Info.
|
||||
*/
|
||||
static LogLevel info() { return LogLevel(Type::Info); }
|
||||
|
||||
/**
|
||||
* @brief Создает уровень Error.
|
||||
*/
|
||||
static LogLevel error() { return LogLevel(Type::Error); }
|
||||
|
||||
/**
|
||||
* @brief Возвращает строковое представление уровня.
|
||||
*
|
||||
* @return "DEBUG", "INFO" или "ERROR".
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::string_view toString() const {
|
||||
switch (type_) {
|
||||
case Type::Debug:
|
||||
return "DEBUG";
|
||||
|
||||
case Type::Info:
|
||||
return "INFO";
|
||||
|
||||
case Type::Error:
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Сравнивает два уровня логирования.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
bool operator==(const LogLevel &other) const {
|
||||
return type_ == other.type_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Сравнивает два уровня логирования.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
bool operator!=(const LogLevel &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
enum class Type { Debug, Info, Error };
|
||||
|
||||
explicit LogLevel(Type type) : type_(type) {}
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
};
|
||||
|
||||
} // namespace logger
|
||||
|
||||
Reference in New Issue
Block a user