SHA256
modify something
This commit is contained in:
@@ -27,8 +27,12 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _NODISCARD
|
#ifndef NODISCARD
|
||||||
#define _NODISCARD [[nodiscard]]
|
# ifdef _NODISCARD
|
||||||
|
# define NODISCARD _NODISCARD
|
||||||
|
# else
|
||||||
|
# define NODISCARD [[nodiscard]]
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ namespace flog
|
|||||||
public:
|
public:
|
||||||
virtual ~LogFormatter() = default;
|
virtual ~LogFormatter() = default;
|
||||||
|
|
||||||
_NODISCARD virtual std::string FLOG_CALL format(const LogMessage& message) = 0;
|
NODISCARD virtual std::string FLOG_CALL format(const LogMessage& message) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <featherlog/log_outputter.hpp>
|
#include <featherlog/log_outputter.hpp>
|
||||||
#include <featherlog/flog_definitions.h>
|
#include <featherlog/flog_definitions.h>
|
||||||
#include <featherlog/push_result.hpp>
|
#include <featherlog/push_result.hpp>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace flog
|
namespace flog
|
||||||
{
|
{
|
||||||
@@ -23,26 +24,30 @@ namespace flog
|
|||||||
LogManager(LogManager &&) = delete;
|
LogManager(LogManager &&) = delete;
|
||||||
LogManager &operator=(LogManager &&) = delete;
|
LogManager &operator=(LogManager &&) = delete;
|
||||||
|
|
||||||
_NODISCARD static std::shared_ptr<LogManager> FLOG_CALL create();
|
NODISCARD static std::shared_ptr<LogManager> FLOG_CALL create() noexcept { return {}; }
|
||||||
|
NODISCARD static std::shared_ptr<LogManager> FLOG_CALL create(LogMessageFlagManager flagManager);
|
||||||
|
|
||||||
~LogManager();
|
~LogManager();
|
||||||
|
|
||||||
_NODISCARD LogLevel FLOG_CALL get_min_log_level() const noexcept;
|
NODISCARD LogLevel FLOG_CALL get_min_log_level() const noexcept;
|
||||||
void FLOG_CALL set_min_log_level(LogLevel level) noexcept;
|
void FLOG_CALL set_min_log_level(LogLevel level) noexcept;
|
||||||
|
|
||||||
_NODISCARD PushResult<std::unique_ptr<LogOutputter>> FLOG_CALL add_outputter(
|
NODISCARD PushResult<std::unique_ptr<LogOutputter>> FLOG_CALL
|
||||||
std::unique_ptr<LogOutputter> outputter);
|
add_outputter(std::unique_ptr<LogOutputter> outputter);
|
||||||
|
NODISCARD bool FLOG_CALL contains_outputter(std::string_view name) const;
|
||||||
_NODISCARD bool FLOG_CALL contains_outputter(std::string_view name) const;
|
|
||||||
std::optional<std::unique_ptr<LogOutputter>> FLOG_CALL try_delete_outputter(std::string_view name);
|
std::optional<std::unique_ptr<LogOutputter>> FLOG_CALL try_delete_outputter(std::string_view name);
|
||||||
|
|
||||||
_NODISCARD std::shared_ptr<Logger> FLOG_CALL get_logger(const std::string &name);
|
NODISCARD std::shared_ptr<Logger> FLOG_CALL get_logger(const std::string &name);
|
||||||
|
|
||||||
size_t FLOG_CALL clean_unused_loggers();
|
size_t FLOG_CALL clean_unused_loggers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogManager() noexcept = default;
|
LogManager() noexcept = default;
|
||||||
|
|
||||||
|
explicit LogManager(LogMessageFlagManager flagManager) noexcept :
|
||||||
|
m_logMessageFlagManager(std::move(flagManager))
|
||||||
|
{ }
|
||||||
|
|
||||||
void FLOG_CALL write_log(const LogMessage &message) const;
|
void FLOG_CALL write_log(const LogMessage &message) const;
|
||||||
|
|
||||||
std::atomic<LogLevel> m_minLogLevel{LogLevel::DEBUG};
|
std::atomic<LogLevel> m_minLogLevel{LogLevel::DEBUG};
|
||||||
@@ -52,5 +57,8 @@ namespace flog
|
|||||||
|
|
||||||
mutable std::mutex m_loggersMutex;
|
mutable std::mutex m_loggersMutex;
|
||||||
std::unordered_map<std::string, std::shared_ptr<Logger>> m_loggers;
|
std::unordered_map<std::string, std::shared_ptr<Logger>> m_loggers;
|
||||||
|
|
||||||
|
mutable std::shared_mutex m_logMessageFlagManagerMutex;
|
||||||
|
LogMessageFlagManager m_logMessageFlagManager;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,36 @@
|
|||||||
|
|
||||||
namespace flog
|
namespace flog
|
||||||
{
|
{
|
||||||
typedef uint32_t MessageFlag;
|
typedef uint32_t LogMessageFlag;
|
||||||
|
typedef LogMessageFlag MessageFlag;
|
||||||
|
|
||||||
class MessageFlagManager
|
typedef class LogMessageFlagManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageFlagManager() noexcept = default;
|
static constexpr MessageFlag ADD_FAILED = 0;
|
||||||
~MessageFlagManager() = default;
|
|
||||||
|
|
||||||
MessageFlagManager(const MessageFlagManager&) noexcept = default;
|
static constexpr size_t FLAG_ARRAY_SIZE = std::numeric_limits<MessageFlag>::digits;
|
||||||
MessageFlagManager& operator=(const MessageFlagManager&) noexcept = default;
|
|
||||||
MessageFlagManager(MessageFlagManager&&) noexcept = default;
|
|
||||||
MessageFlagManager& operator=(MessageFlagManager&&) noexcept = default;
|
|
||||||
|
|
||||||
_NODISCARD bool isFull() const noexcept { return flagCount >= std::numeric_limits<MessageFlag>::digits; }
|
LogMessageFlagManager() noexcept = default;
|
||||||
_NODISCARD bool pushable() const noexcept { return !isFull(); }
|
~LogMessageFlagManager() = default;
|
||||||
_NODISCARD bool isEmpty() const noexcept { return flagCount == 0; }
|
|
||||||
|
|
||||||
_NODISCARD bool contains(std::string_view name) const noexcept;
|
LogMessageFlagManager(const LogMessageFlagManager&) noexcept = default;
|
||||||
|
LogMessageFlagManager& operator=(const LogMessageFlagManager&) noexcept = default;
|
||||||
|
LogMessageFlagManager(LogMessageFlagManager&&) noexcept = default;
|
||||||
|
LogMessageFlagManager& operator=(LogMessageFlagManager&&) noexcept = default;
|
||||||
|
|
||||||
|
NODISCARD bool isFull() const noexcept { return flagCount >= FLAG_ARRAY_SIZE; }
|
||||||
|
NODISCARD bool pushable() const noexcept { return !isFull(); }
|
||||||
|
NODISCARD bool isEmpty() const noexcept { return flagCount == 0; }
|
||||||
|
NODISCARD bool empty() const noexcept { return isEmpty(); }
|
||||||
|
|
||||||
|
NODISCARD bool contains(std::string_view name) const noexcept;
|
||||||
|
|
||||||
|
NODISCARD MessageFlag addFlag (std::string_view name);
|
||||||
|
NODISCARD MessageFlag findFlag(std::string_view name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<std::string, std::numeric_limits<MessageFlag>::digits> m_flagMap{};
|
std::array<std::string, FLAG_ARRAY_SIZE> m_flagMap{};
|
||||||
size_t flagCount { 0 };
|
size_t flagCount { 0 };
|
||||||
};
|
} MessageFlagManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,21 @@
|
|||||||
#include <featherlog/log_message.hpp>
|
#include <featherlog/log_message.hpp>
|
||||||
#include <featherlog/flog_definitions.h>
|
#include <featherlog/flog_definitions.h>
|
||||||
|
|
||||||
namespace flog {
|
namespace flog
|
||||||
class FLOG_API LogOutputter {
|
{
|
||||||
|
class FLOG_API LogOutputter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
explicit LogOutputter(std::string name, std::unique_ptr<LogFormatter> formatter) noexcept
|
LogOutputter(std::string name, std::unique_ptr<LogFormatter> formatter) noexcept
|
||||||
: m_name(std::move(name)), m_logFormatter(std::move(formatter))
|
: m_name(std::move(name)), m_logFormatter(std::move(formatter))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~LogOutputter() = default;
|
virtual ~LogOutputter() = default;
|
||||||
|
|
||||||
_NODISCARD std::string FLOG_CALL getName() const noexcept { return m_name; }
|
NODISCARD std::string FLOG_CALL getName() const noexcept { return m_name; }
|
||||||
|
|
||||||
std::unique_ptr<LogFormatter> FLOG_CALL set_formatter(const std::unique_ptr<LogFormatter> &formatter);
|
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;
|
NODISCARD const std::unique_ptr<LogFormatter> & FLOG_CALL get_formatter() const;
|
||||||
|
|
||||||
virtual void FLOG_CALL write_log(const LogMessage &message) = 0;
|
virtual void FLOG_CALL write_log(const LogMessage &message) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ namespace flog
|
|||||||
friend class LogManager;
|
friend class LogManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Logger(const Logger&) = delete;
|
||||||
|
Logger operator=(const Logger&) = delete;
|
||||||
|
Logger(const Logger&&) = delete;
|
||||||
|
Logger operator=(const Logger&&) = delete;
|
||||||
|
|
||||||
~Logger() = default;
|
~Logger() = default;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace flog
|
|||||||
class PushResult
|
class PushResult
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD static PushResult success() noexcept { return PushResult(); }
|
NODISCARD static PushResult success() noexcept { return PushResult(); }
|
||||||
_NODISCARD static PushResult failWithValue(T value) noexcept
|
NODISCARD static PushResult failWithValue(T value) noexcept
|
||||||
{
|
{
|
||||||
return PushResult(std::move(std::optional<T>(std::move(value))));
|
return PushResult(std::move(std::optional<T>(std::move(value))));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD bool isSuccessful() const noexcept { return !m_value.has_value(); }
|
NODISCARD bool isSuccessful() const noexcept { return !m_value.has_value(); }
|
||||||
_NODISCARD bool isFail() 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
|
void getValueIfFail(const std::function<void(const T& value)> func) const
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace flog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD T getValue() const { return m_value.value(); }
|
NODISCARD T getValue() const { return m_value.value(); }
|
||||||
|
|
||||||
PushResult(const PushResult &other) noexcept { m_value = other.m_value; }
|
PushResult(const PushResult &other) noexcept { m_value = other.m_value; }
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -1,13 +1,10 @@
|
|||||||
#include <ranges>
|
|
||||||
#include <featherlog/log_manager.hpp>
|
#include <featherlog/log_manager.hpp>
|
||||||
#include <featherlog/push_result.hpp>
|
#include <featherlog/push_result.hpp>
|
||||||
|
|
||||||
namespace flog
|
namespace flog
|
||||||
{
|
{
|
||||||
std::shared_ptr<LogManager> LogManager::create()
|
std::shared_ptr<LogManager> LogManager::create(MessageFlagManager flagManager) {
|
||||||
{
|
return std::shared_ptr<LogManager>(new LogManager(std::move(flagManager)));
|
||||||
// ReSharper disable once CppDFAMemoryLeak
|
|
||||||
return std::shared_ptr<LogManager>(new LogManager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager::~LogManager()
|
LogManager::~LogManager()
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#include <featherlog/log_message_flag.hpp>
|
||||||
Reference in New Issue
Block a user