SergiusTheBest / plog

Portable, simple and extensible C++ logging library
MIT License
2.21k stars 391 forks source link

Remove an appender? #226

Closed aniongithub closed 2 years ago

aniongithub commented 2 years ago

I'm using plog as an internal logging library for my C API that allows users to specify log callbacks from my lib. In this case, I need the ability to remove appenders as well. This would also be true for long running microservice applications that may have clients who connect and disconnect as required and need on-demand logging capabilities.

How can I do this?

Thanks for creating plog!

SergiusTheBest commented 2 years ago

Could you provide more details?

aniongithub commented 2 years ago

Thank you for the quick reply!

I currently add a log appender like so: plog::init((plog::Severity)params.logLevel, _appender.get());

This effectively boils down to a call to addAppender. How would I remove the appender I added using this method?

SergiusTheBest commented 2 years ago

Ok, I think I understand what do you need.

SergiusTheBest commented 2 years ago

I've added a DynamicAppender to keep the old behavior and add ability to add/remove appenders dynamically. Here is how to use it: https://github.com/SergiusTheBest/plog/blob/4c7997b15a3cdc1be9c5b574849b46e32c94a445/samples/DynamicAppender/Main.cpp#L5-L30

aniongithub commented 2 years ago

That's perfect, thanks for this!