-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Support custom asynchronous logger and reuse thread pool #3293
Conversation
Off-topic I really think spdlog is a very good project, and I've wrapped some of spdlog's APIs into SourceMod's extensions to ease the burden of logging and debugging for SourceMod plugin developers. The wrapped spdlog extension is much better than SourceMod's native logging API in terms of functionality and efficiency. Especially in terms of performance, the sdplog extension is many times faster than the SourceMod native logging API in my benchmarks. But SourceMod is a somewhat old project, and there are a lot of problems that need to be solved by extending and wrapping spdlog. So I'm submitting this pull request to enhance spdlog's extensibility and reusability to provide more flexibility for developers. |
Suppose we add an option |
Thanks @F1F88 for the suggestions. I tend not to change anything significant in this branch though. |
The design ideas of async-sink are impressive! I am glad to see that the async-sink branch is exploring new asynchronous function implementations. I understand the emphasis on stability in the current branch and the decision not to make major changes in this branch. For the current needs of my project, I will temporarily modify the source code of spdlog to meet specific use cases. Although this approach may have limitations in long-term maintainability, I will closely follow the progress of async-sink and v2.x branches and re-evaluate and optimize my implementation when appropriate. Thank you for your valuable feedback and guidance. I look forward to the official release of v2.x and hope to have the opportunity to contribute to its development in the future! |
You're welcome . Thanks @F1F88 |
* 抽象后台工作接口,而不是将 thread_pool、async_logger、backend_worker 绑定 * 这能更灵活的自定义 async_logger 并复用 spdlog::thread_pool * 由于 v2.x 还没有发行版,v1.x 拒绝合并破坏 api 的更改 所以我们自己修改 spdlog 源码以满足自定义 async_logger 的需求 后续需要特别注意此处的兼容性 * gabime/spdlog#3293
In the current version of spdlog, customizing async_logger and reusing spdlog::thread_pool becomes difficult due to the following limitations:
The
post_log
andpost_flush
parameters of thespdlog::thread_pool
class are limited to thespdlog::async_logger
type, which lacks flexibility.spdlog::async_logger
is afinal
class and cannot be inherited or customized. This further limits the extensibility and reuse capabilities of the logger.Changes
Abstract backend worker interface
Abstract the
backend_sink_it_
andbackend_flush__
interfaces into a new classbackend_worker
.The
spdlog::async_logger
class inherits and implementsbackend_worker
, and is no longer directly bound to the backend worker interface.Improve the versatility of
spdlog::thread_pool
Modify the parameter types of
post_log
andpost_flush
fromspdlog::async_logger
to the generalbackend_worker
type.Allow collaboration with other
backend_worker
implementations to improve the reusability ofthread_pool
.Advantages
Support custom asynchronous logger
Users can easily create custom asynchronous logger by inheriting the
spdlog::logger
class and thebackend_worker
class, without being restricted by the fixed implementation ofspdlog::async_logger
.Enhance the reusability of spdlog::thread_pool
spdlog::thread_pool
is no longer limited to collaboration withspdlog::async_logger
, but can cooperate with more implementation classes of thebackend_worker
class, significantly enhancing versatility and extensibility.This shouldn't be too disruptive to the original code structure, spdlog::async_logger is still the final class and can still be passed as a backend worker to spdlog::thread_pool .