DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
log_state_saver.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: GPL-2.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_LOG_STATE_SAVER_H
13 #define DOCWIRE_LOG_STATE_SAVER_H
14 
15 #include "log_core.h"
16 
17 namespace docwire::log
18 {
19 
24 {
25 public:
26  state_saver()
27  : m_old_sink(get_sink()), m_old_filter(get_filter())
28  {}
29 
30  // Prevent copying and moving to ensure single ownership of restoration responsibility
31  state_saver(const state_saver&) = delete;
32  state_saver& operator=(const state_saver&) = delete;
33  state_saver(state_saver&&) = delete;
34  state_saver& operator=(state_saver&&) = delete;
35 
36  ~state_saver()
37  {
38  set_sink(m_old_sink);
39  set_filter(m_old_filter);
40  }
41 
42 private:
43  std::function<void(const record&)> m_old_sink;
44  std::string m_old_filter;
45 };
46 
47 } // namespace docwire::log
48 
49 #endif // DOCWIRE_LOG_STATE_SAVER_H
RAII class to save and restore logging state (sink and filter).
Provides a modern, high-performance, and structured logging framework.
DOCWIRE_CORE_EXPORT void set_sink(std::function< void(const log::record &)> callback)
Sets the global callback function that will receive all enabled log records.
DOCWIRE_CORE_EXPORT std::function< void(const record &)> get_sink()
Gets the current log sink function.
DOCWIRE_CORE_EXPORT std::string get_filter()
Gets the current log filter specification string.