diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f170c0..c5dd55b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,10 @@ project(FeatherLog) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) +add_compile_definitions(FLOG_IMPL_CONSOLE_OUTPUTTER) # build with default console outputter +add_compile_definitions(FLOG_IMPL_FILE_OUTPUTTER) # build with default file outputter +add_compile_definitions(FLOG_IMPL_DEFAULT_FORMATTER) # build with default formatter + # 定义源文件 set(${PROJECT_NAME}_SOURCES include/featherlog/log_manager.hpp @@ -16,7 +20,10 @@ set(${PROJECT_NAME}_SOURCES include/featherlog/push_result.hpp include/featherlog/log_message_flag.hpp include/featherlog/featherlog.hpp - src/log_manager.cpp) + src/log_manager.cpp + src/log_message_flag.cpp + include/featherlog/impl/flog_impl.hpp + include/featherlog/impl/console_outputter.hpp) # 生成静态库 add_library(${PROJECT_NAME}_static STATIC ${${PROJECT_NAME}_SOURCES}) diff --git a/include/featherlog/featherlog.hpp b/include/featherlog/featherlog.hpp index dc0af5c..191b389 100644 --- a/include/featherlog/featherlog.hpp +++ b/include/featherlog/featherlog.hpp @@ -2,13 +2,15 @@ #define FEATHERLOG_FEATHERLOG_HPP #include +#include #include #include #include #include #include #include -#include #include +#include + #endif diff --git a/include/featherlog/flog_definitions.h b/include/featherlog/flog_definitions.h index 6576cdc..f2617ee 100644 --- a/include/featherlog/flog_definitions.h +++ b/include/featherlog/flog_definitions.h @@ -27,4 +27,8 @@ #endif +#ifndef _NODISCARD +#define _NODISCARD [[nodiscard]] +#endif + #endif diff --git a/include/featherlog/impl/console_outputter.hpp b/include/featherlog/impl/console_outputter.hpp new file mode 100644 index 0000000..4c8bd45 --- /dev/null +++ b/include/featherlog/impl/console_outputter.hpp @@ -0,0 +1,5 @@ +#pragma once + +#ifdef FLOG_IMPL_CONSOLE_OUTPUTTER + +#endif diff --git a/include/featherlog/impl/flog_impl.hpp b/include/featherlog/impl/flog_impl.hpp new file mode 100644 index 0000000..b703c41 --- /dev/null +++ b/include/featherlog/impl/flog_impl.hpp @@ -0,0 +1,7 @@ +#ifndef FEATHERLOG_IMPL_FLOG_IMPL_HPP +#define FEATHERLOG_IMPL_FLOG_IMPL_HPP + +#include + +#endif + diff --git a/include/featherlog/log_formatter.hpp b/include/featherlog/log_formatter.hpp index 98cfd89..e2be7b2 100644 --- a/include/featherlog/log_formatter.hpp +++ b/include/featherlog/log_formatter.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_LOG_FORMATTER_HPP -#define FEATHERLOG_LOG_FORMATTER_HPP +#pragma once #include #include @@ -11,8 +10,6 @@ namespace flog public: virtual ~LogFormatter() = default; - virtual std::string FLOG_CALL format() = 0; + _NODISCARD virtual std::string FLOG_CALL format(const LogMessage& message) = 0; }; } - -#endif diff --git a/include/featherlog/log_level.hpp b/include/featherlog/log_level.hpp index 473a900..10b8e4b 100644 --- a/include/featherlog/log_level.hpp +++ b/include/featherlog/log_level.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_LOG_LEVEL_HPP -#define FEATHERLOG_LOG_LEVEL_HPP +#pragma once #include @@ -18,5 +17,3 @@ namespace flog OFF = std::numeric_limits::max() }; } - -#endif diff --git a/include/featherlog/log_manager.hpp b/include/featherlog/log_manager.hpp index f38dd64..31a14a3 100644 --- a/include/featherlog/log_manager.hpp +++ b/include/featherlog/log_manager.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_LOG_MANAGER_HPP -#define FEATHERLOG_LOG_MANAGER_HPP +#pragma once #include #include @@ -28,14 +27,16 @@ namespace flog ~LogManager(); - LogLevel FLOG_CALL get_min_log_level() const noexcept; - void FLOG_CALL set_min_log_level(LogLevel level) noexcept; + _NODISCARD LogLevel FLOG_CALL get_min_log_level() const noexcept; + void FLOG_CALL set_min_log_level(LogLevel level) noexcept; - PushResult> FLOG_CALL add_outputter(std::unique_ptr outputter); - bool FLOG_CALL contains_outputter(std::string_view name) const noexcept; - std::optional> FLOG_CALL try_delete_outputter(std::string_view name) noexcept; + _NODISCARD PushResult> FLOG_CALL add_outputter( + std::unique_ptr outputter); - std::shared_ptr FLOG_CALL get_logger(const std::string &name); + _NODISCARD bool FLOG_CALL contains_outputter(std::string_view name) const; + std::optional> FLOG_CALL try_delete_outputter(std::string_view name); + + _NODISCARD std::shared_ptr FLOG_CALL get_logger(const std::string &name); size_t FLOG_CALL clean_unused_loggers(); @@ -53,5 +54,3 @@ namespace flog std::unordered_map> m_loggers; }; } - -#endif diff --git a/include/featherlog/log_message.hpp b/include/featherlog/log_message.hpp index 7286d9f..5615068 100644 --- a/include/featherlog/log_message.hpp +++ b/include/featherlog/log_message.hpp @@ -1,6 +1,4 @@ -#ifndef FEATHERLOG_LOG_MESSAGE_HPP -#define FEATHERLOG_LOG_MESSAGE_HPP - +#pragma once #include #include @@ -19,5 +17,3 @@ namespace flog MessageFlag flag; }; } - -#endif diff --git a/include/featherlog/log_message_flag.hpp b/include/featherlog/log_message_flag.hpp index 4752c50..66eb1c2 100644 --- a/include/featherlog/log_message_flag.hpp +++ b/include/featherlog/log_message_flag.hpp @@ -1,7 +1,7 @@ -#ifndef FEATHERLOG_LOG_MESSAGE_FLAG_HPP -#define FEATHERLOG_LOG_MESSAGE_FLAG_HPP +#pragma once #include +#include namespace flog { @@ -21,12 +21,11 @@ namespace flog _NODISCARD bool isFull() const noexcept { return flagCount >= std::numeric_limits::digits; } _NODISCARD bool pushable() const noexcept { return !isFull(); } _NODISCARD bool isEmpty() const noexcept { return flagCount == 0; } - // _NODISCARD + + _NODISCARD bool contains(std::string_view name) const noexcept; private: std::array::digits> m_flagMap{}; size_t flagCount { 0 }; }; } - -#endif diff --git a/include/featherlog/log_outputter.hpp b/include/featherlog/log_outputter.hpp index 5e92576..724b10d 100644 --- a/include/featherlog/log_outputter.hpp +++ b/include/featherlog/log_outputter.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_LOG_OUTPUTTER_HPP -#define FEATHERLOG_LOG_OUTPUTTER_HPP +#pragma once #include @@ -11,7 +10,8 @@ namespace flog { class FLOG_API LogOutputter { public: explicit LogOutputter(std::string name, std::unique_ptr 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; @@ -28,5 +28,3 @@ namespace flog { std::unique_ptr m_logFormatter; }; } - -#endif diff --git a/include/featherlog/logger.hpp b/include/featherlog/logger.hpp index d2d9a84..5b4ae31 100644 --- a/include/featherlog/logger.hpp +++ b/include/featherlog/logger.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_LOGGER_HPP -#define FEATHERLOG_LOGGER_HPP +#pragma once #include #include @@ -31,5 +30,3 @@ namespace flog const std::weak_ptr m_logManager; }; } - -#endif diff --git a/include/featherlog/push_result.hpp b/include/featherlog/push_result.hpp index e9cfea7..e77bbb0 100644 --- a/include/featherlog/push_result.hpp +++ b/include/featherlog/push_result.hpp @@ -1,5 +1,4 @@ -#ifndef FEATHERLOG_PUSH_RESULT_HPP -#define FEATHERLOG_PUSH_RESULT_HPP +#pragma once #include #include @@ -37,5 +36,3 @@ namespace flog const std::optional m_value = std::nullopt; }; } - -#endif diff --git a/src/log_manager.cpp b/src/log_manager.cpp index eec6fac..c07af34 100644 --- a/src/log_manager.cpp +++ b/src/log_manager.cpp @@ -43,13 +43,13 @@ namespace flog return PushResult>::success(); } - bool LogManager::contains_outputter(const std::string_view name) const noexcept + bool LogManager::contains_outputter(const std::string_view name) const { std::shared_lock lock(m_logOutputtersMutex); return m_logOutputters.contains(name.data()); } - std::optional> LogManager::try_delete_outputter(const std::string_view name) noexcept + std::optional> LogManager::try_delete_outputter(const std::string_view name) { if (contains_outputter(name)) { diff --git a/src/log_message_flag.cpp b/src/log_message_flag.cpp new file mode 100644 index 0000000..473a0f4