SHA256
.
This commit is contained in:
+3
-2
@@ -16,6 +16,8 @@ set(${PROJECT_NAME}_SOURCES
|
||||
include/featherlog/log_formatter.hpp
|
||||
include/featherlog/log_level.hpp
|
||||
include/featherlog/log_message.hpp
|
||||
include/featherlog/flog_definitions.h
|
||||
include/featherlog/push_result.hpp
|
||||
src/log_manager.cpp)
|
||||
|
||||
# 生成静态库
|
||||
@@ -29,8 +31,7 @@ add_compile_definitions(FLOG_DLL_MODE)
|
||||
add_compile_definitions(FLOG_BUILDING_DLL)
|
||||
|
||||
# 生成动态库
|
||||
add_library(${PROJECT_NAME}_shared SHARED ${${PROJECT_NAME}_SOURCES}
|
||||
include/featherlog/flog_definitions.h)
|
||||
add_library(${PROJECT_NAME}_shared SHARED ${${PROJECT_NAME}_SOURCES})
|
||||
target_include_directories(${PROJECT_NAME}_shared PUBLIC include)
|
||||
set_target_properties(${PROJECT_NAME}_shared PROPERTIES
|
||||
OUTPUT_NAME ${PROJECT_NAME}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <featherlog/logger.hpp>
|
||||
#include <featherlog/log_level.hpp>
|
||||
@@ -24,14 +23,15 @@ namespace flog {
|
||||
LogManager(LogManager &&) = delete;
|
||||
LogManager &operator=(LogManager &&) = delete;
|
||||
|
||||
static std::shared_ptr<LogManager> FLOG_CALL create();
|
||||
_NODISCARD static std::shared_ptr<LogManager> FLOG_CALL create();
|
||||
|
||||
~LogManager();
|
||||
~LogManager() = default;
|
||||
|
||||
LogLevel FLOG_CALL get_min_log_level() const noexcept;
|
||||
void FLOG_CALL set_min_log_level(LogLevel level) noexcept;
|
||||
|
||||
void FLOG_CALL add_outputter(std::unique_ptr<LogOutputter> outputter);
|
||||
PushResult FLOG_CALL add_outputter(const std::string& name, std::unique_ptr<LogOutputter> outputter);
|
||||
std::optional<LogOutputter> FLOG_CALL get_outputter() noexcept;
|
||||
|
||||
std::shared_ptr<Logger> FLOG_CALL get_logger(const std::string &name);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace flog {
|
||||
std::atomic<LogLevel> m_minLogLevel{LogLevel::DEBUG};
|
||||
|
||||
mutable std::shared_mutex m_logOutputtersMutex;
|
||||
std::vector<std::unique_ptr<LogOutputter>> m_logOutputters;
|
||||
std::unordered_map<std::string, std::unique_ptr<LogOutputter>> m_logOutputters;
|
||||
|
||||
mutable std::mutex m_loggersMutex;
|
||||
std::unordered_map<std::string, std::shared_ptr<Logger>> m_loggers;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef FEATHERLOG_PUSH_RESULT_HPP
|
||||
#define FEATHERLOG_PUSH_RESULT_HPP
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace flog {
|
||||
template <typename T>
|
||||
class PushResult {
|
||||
public:
|
||||
static PushResult getVoid() {
|
||||
return PushResult(3);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit PushResult(std::optional<T> value) : m_value(value) {
|
||||
std::optional<T> bad;
|
||||
std::map<int, std::optional<T>> mp;
|
||||
}
|
||||
|
||||
std::optional<T> m_value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+6
-13
@@ -6,17 +6,6 @@ namespace flog {
|
||||
return std::shared_ptr<LogManager>(new LogManager());
|
||||
}
|
||||
|
||||
LogManager::~LogManager() {
|
||||
{
|
||||
std::lock_guard lock(m_loggersMutex);
|
||||
m_loggers.clear();
|
||||
}
|
||||
{
|
||||
std::lock_guard lock(m_logOutputtersMutex);
|
||||
m_logOutputters.clear();
|
||||
}
|
||||
}
|
||||
|
||||
LogLevel LogManager::get_min_log_level() const noexcept {
|
||||
return m_minLogLevel.load(std::memory_order_relaxed);
|
||||
}
|
||||
@@ -25,9 +14,13 @@ namespace flog {
|
||||
m_minLogLevel.store(level, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void LogManager::add_outputter(std::unique_ptr<LogOutputter> outputter) {
|
||||
bool LogManager::add_outputter(const std::string& name, std::unique_ptr<LogOutputter> outputter) {
|
||||
std::lock_guard lock(m_logOutputtersMutex);
|
||||
m_logOutputters.push_back(std::move(outputter));
|
||||
if (m_logOutputters.contains(name)) {
|
||||
return false;
|
||||
}
|
||||
m_logOutputters[name] = std::move(outputter);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Logger> LogManager::get_logger(const std::string &name) {
|
||||
|
||||
Reference in New Issue
Block a user