This commit is contained in:
CupWater
2026-08-17 10:02:18 +08:00
parent d54d2fcff5
commit c196ffb6d8
8 changed files with 29 additions and 30 deletions
-15
View File
@@ -1,15 +0,0 @@
#ifndef FEATHERLOG_LOG_FORMATTER_HPP
#define FEATHERLOG_LOG_FORMATTER_HPP
#include <string>
namespace flog
{
class LogFormatter
{
public:
virtual ~LogFormatter() = default;
virtual std::string format() = 0;
};
}
#endif
-21
View File
@@ -1,21 +0,0 @@
#ifndef FEATHERLOG_LOG_LEVEL_HPP
#define FEATHERLOG_LOG_LEVEL_HPP
#include <cstdint>
namespace flog
{
enum class LogLevel : uint8_t
{
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
FATAL = 5,
OFF = 0xff,
};
}
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#include "log_manager.hpp"
#include "../../include/log_manager.hpp"
namespace flog
{
-59
View File
@@ -1,59 +0,0 @@
#ifndef FEATHERLOG_LOG_MANAGER_HPP
#define FEATHERLOG_LOG_MANAGER_HPP
#include <atomic>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <unordered_map>
#include <vector>
#include "logger.hpp"
#include "log_formatter.hpp"
#include "log_level.hpp"
#include "log_message.hpp"
#include "log_outputter.hpp"
namespace flog
{
class LogManager;
class LogManager : public std::enable_shared_from_this<LogManager>
{
friend class LoggerCallback;
public:
LogManager(const LogManager&) = delete;
LogManager& operator=(const LogManager&) = delete;
LogManager(LogManager&&) = delete;
LogManager& operator=(LogManager&&) = delete;
static std::shared_ptr<LogManager> create();
~LogManager();
LogLevel get_min_log_level() const noexcept;
void set_min_log_level(LogLevel level) noexcept;
void add_outputter(std::unique_ptr<LogOutputter> outputter);
std::shared_ptr<Logger> get_logger(const std::string& name);
size_t clean_unused_loggers();
private:
LogManager() noexcept = default;
void print_log(const LogMessage& message) const;
std::atomic<LogLevel> m_minLogLevel{LogLevel::DEBUG};
mutable std::shared_mutex m_logOutputtersMutex;
std::vector<std::unique_ptr<LogOutputter>> m_logOutputters;
mutable std::mutex m_loggersMutex;
std::unordered_map<std::string, std::shared_ptr<Logger>> m_loggers;
};
}
#endif
-20
View File
@@ -1,20 +0,0 @@
#ifndef FEATHERLOG_LOG_MESSAGE_HPP
#define FEATHERLOG_LOG_MESSAGE_HPP
#include <chrono>
#include <string_view>
#include "log_level.hpp"
namespace flog
{
struct LogMessage {
std::chrono::system_clock::time_point timestamp;
LogLevel level;
std::string_view logger_name;
std::string text;
};
}
#endif
-27
View File
@@ -1,27 +0,0 @@
#ifndef FEATHERLOG_LOG_OUTPUTER_HPP
#define FEATHERLOG_LOG_OUTPUTER_HPP
#include <memory>
#include <string>
#include "log_formatter.hpp"
#include "log_message.hpp"
namespace flog
{
class LogOutputter
{
public:
virtual ~LogOutputter() = default;
std::unique_ptr<LogFormatter> set_formatter(const std::unique_ptr<LogFormatter>& formatter);
std::unique_ptr<LogFormatter>& get_formatter();
virtual void write(const LogMessage& message) = 0;
protected:
std::unique_ptr<LogFormatter> m_logFormatter;
};
}
#endif
-33
View File
@@ -1,33 +0,0 @@
#ifndef FEATHERLOG_LOGGER_HPP
#define FEATHERLOG_LOGGER_HPP
#include <format>
#include <source_location>
#include "log_manager.hpp"
namespace flog
{
class LoggerCallback;
class Logger
{
friend class LogManager;
public:
~Logger() = default;
template <typename... Args>
void info(std::format_string<Args...> fmt, Args&&... args,
std::source_location loc = std::source_location::current());
private:
Logger(const std::string& name, std::weak_ptr<LogManager> manager) : m_name(name), m_logManager(manager)
{ }
std::string m_name;
std::weak_ptr<LogManager> m_logManager;
};
}
#endif