microsoft / SPTAG

A distributed approximate nearest neighborhood search (ANN) library which provides a high quality vector index build, search and distributed online serving toolkits for large scale vector search scenario.
MIT License
4.77k stars 581 forks source link

Allow setting a different Logger at runtime #370

Closed PhilipBAdams closed 1 year ago

PhilipBAdams commented 1 year ago

Atomicicty is needed here because Logger::Logging is not const, so we can mangle things if shared_ptr is not updated atomically. We can use std::atomic in C++20 and above, and atomic_store/atomic_load otherwise.

Previous code GetLogger().reset() would not work correctly, because it would overwrite the copy of the static ptr, not the magic static s_pLogger inside of GetLogger(). We add an indirection to make it possible to override the static