Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Enhanced Configuration #19

Open
F1F88 opened this issue Jan 5, 2025 · 2 comments
Open

[Feature Request] Enhanced Configuration #19

F1F88 opened this issue Jan 5, 2025 · 2 comments
Labels
Type: Feature Request New feature or request

Comments

@F1F88
Copy link
Owner

F1F88 commented Jan 5, 2025

最初由 @blueblur0730modified-plugins 中提出

现状:
目前唯一可配置的功能只有全局线程池,并且只能将配置项写在 core.cfg 里。

期望:
从专用的 log4sp.cfg 中读取配置,并支持配置更多功能。(例如:创建 logger)

@F1F88
Copy link
Owner Author

F1F88 commented Jan 5, 2025

拟定配置文件结构

"log4sp"
{
    /**
     * 全局线程池相关配置
     * 兼容性:先读取配置文件,不存在则读取 core.cfg,还不存在使用默认值
     */
    "GlobalThreadPool"
    {
        "QueueSize"     "8192"      // unsigned int (1 - 1024 * 1024 * 10)
        "ThreadCount"   "1"         // unsigned int (1 - 1000)
    }

    /**
     * 初始化 logger 列表
     * 兼容性:如果不存在全局 logger "log4sp" 的配置项,则使用默认值创建
     */
    "InitializeLoggers"
    {
        // 待定:已存在时,是直接跳过还是修改属性?
        // Name: string
        "log4sp"
        {
            // string (忽略大小写) | unsigned int (0 - 6)
            "LogLevel"      "Info"

            // string (忽略大小写) | unsigned int (0 - 6)
            "FlushLevel"    "Off"

            // string
            "Pattern"       "[%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v"

            // unsigned long long (0 = 关闭 | 其他 = 启用)
            "Backtrace"     "0"

            "Sinks"
            {
                // string (忽略大小写) | BaseFile | DailyFile | RotatingFile | ServerConsole
                "type"          "..."

                // string (忽略大小写) | unsigned int (0 - 6)
                "LogLevel"      "Trace"

                // string | logger Pattern 执行在后会覆盖
                "Pattern"       "[%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v"
            }

            // bool | true = Handle 可释放 | false = Handle 不可释放
            "Closeable"     "false"

            // "ErrorHandler"   // 待定
        }

        "logger-2"
        { ... }

        "logger-3"
        { ... }

        [...]
    }
}

@F1F88
Copy link
Owner Author

F1F88 commented Jan 5, 2025

拟定实现方案

  1. 通过额外的 SourceMod 插件实现

    • 可以分模块处理,基本不需要改动拓展源码

    • 无法配置全局线程池

    • 无法配置全局 logger

  2. 通过修改拓展内部源码,新增一个 configs/configuration.cpp 组件实现

    class configuration {
    public:
        [[nodiscard]] static configuration &instance();
    
        void load(const std::string& filePath);
        std::string get(const std::string &key, const std::string &defaultValue = "");
        spdlog::level::level_enum get_level(const std::string& key, spdlog::level::level_enum defaultValue = spdlog::level::off);
    
        configuration(const configuration &) = delete;
        configuration &operator=(const configuration &) = delete;
    
    private:
        configuration() = default;
        std::unordered_map<std::string, std::string> configs_;
    };

@F1F88 F1F88 added the Type: Feature Request New feature or request label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant