SHA256
finish log_manager.cpp
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <featherlog/log_message.hpp>
|
||||
#include <featherlog/log_outputter.hpp>
|
||||
#include <featherlog/flog_definitions.h>
|
||||
#include <featherlog/push_result.hpp>
|
||||
|
||||
namespace flog {
|
||||
class FLOG_API LogManager : public std::enable_shared_from_this<LogManager> {
|
||||
@@ -25,13 +26,14 @@ namespace flog {
|
||||
|
||||
_NODISCARD static std::shared_ptr<LogManager> FLOG_CALL create();
|
||||
|
||||
~LogManager() = default;
|
||||
~LogManager();
|
||||
|
||||
LogLevel FLOG_CALL get_min_log_level() const noexcept;
|
||||
void FLOG_CALL set_min_log_level(LogLevel level) noexcept;
|
||||
|
||||
PushResult FLOG_CALL add_outputter(const std::string& name, std::unique_ptr<LogOutputter> outputter);
|
||||
std::optional<LogOutputter> FLOG_CALL get_outputter() noexcept;
|
||||
PushResult<std::unique_ptr<LogOutputter>> FLOG_CALL add_outputter(std::unique_ptr<LogOutputter> outputter);
|
||||
bool FLOG_CALL contains_outputter(std::string_view name) const noexcept;
|
||||
std::optional<std::unique_ptr<LogOutputter>> try_delete_outputter(std::string_view name) noexcept;
|
||||
|
||||
std::shared_ptr<Logger> FLOG_CALL get_logger(const std::string &name);
|
||||
|
||||
|
||||
@@ -10,14 +10,20 @@
|
||||
namespace flog {
|
||||
class FLOG_API LogOutputter {
|
||||
public:
|
||||
explicit LogOutputter(std::string name) noexcept : name(std::move(name)) {}
|
||||
|
||||
virtual ~LogOutputter() = default;
|
||||
|
||||
std::string& getName() const noexcept;
|
||||
|
||||
std::unique_ptr<LogFormatter> FLOG_CALL set_formatter(const std::unique_ptr<LogFormatter> &formatter);
|
||||
[[nodiscard]] const std::unique_ptr<LogFormatter> & FLOG_CALL get_formatter() const;
|
||||
|
||||
virtual void FLOG_CALL write(const LogMessage &message) = 0;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
std::unique_ptr<LogFormatter> m_logFormatter;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,22 +2,39 @@
|
||||
#define FEATHERLOG_PUSH_RESULT_HPP
|
||||
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
|
||||
namespace flog {
|
||||
template <typename T>
|
||||
class PushResult {
|
||||
public:
|
||||
static PushResult getVoid() {
|
||||
return PushResult(3);
|
||||
_NODISCARD static PushResult success() noexcept { return PushResult(); }
|
||||
_NODISCARD static PushResult failWithValue(T value) noexcept {
|
||||
return PushResult(std::move(std::optional<T>(std::move(value))));
|
||||
}
|
||||
|
||||
_NODISCARD bool isSuccessful() const noexcept { return !m_value.has_value(); }
|
||||
_NODISCARD bool isFail() const noexcept { return m_value.has_value(); }
|
||||
|
||||
void getValueIfFail(const std::function<void(const T& value)> func) const {
|
||||
if (isFail()) {
|
||||
func(m_value.value());
|
||||
}
|
||||
}
|
||||
|
||||
_NODISCARD T getValue() const {
|
||||
return m_value.value();
|
||||
}
|
||||
|
||||
PushResult(const PushResult &other) noexcept {
|
||||
m_value = other.m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit PushResult(std::optional<T> value) : m_value(value) {
|
||||
std::optional<T> bad;
|
||||
std::map<int, std::optional<T>> mp;
|
||||
}
|
||||
PushResult() noexcept = default;
|
||||
explicit PushResult(std::optional<T> value) noexcept : m_value(std::move(value)) {}
|
||||
|
||||
std::optional<T> m_value;
|
||||
std::optional<T> m_value = std::nullopt;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user