62 static inline void create_logfile(
const std::filesystem::path& path, log_manager* instance =
nullptr);
71 static inline void log_append(
const std::wstring& str);
80 static inline void log_append(
const std::string& str);
83 log_manager() =
default;
84 static inline log_manager* Instance();
91 static inline bool is_operational_for_logging();
93 std::shared_ptr<log> _log;
94 std::recursive_mutex _log_mutex;
95 static inline std::atomic<bool> _shutting_down{
false};
96 static inline std::recursive_mutex _shutting_down_mutex;
110#ifndef CBEAM_DEBUG_LOGGING
112 #define CBEAM_DEBUG_LOGGING 1
114 #define CBEAM_DEBUG_LOGGING 0
124#define CBEAM_LOG(s) ::cbeam::logging::log_manager::log_append(s);
135#if CBEAM_DEBUG_LOGGING
136 #define CBEAM_LOG_DEBUG(s) ::cbeam::logging::log_manager::log_append(s);
138 #define CBEAM_LOG_DEBUG(s)
152 std::lock_guard<std::recursive_mutex> lock(_shutting_down_mutex);
153 _shutting_down =
true;
155 catch (
const std::system_error& ex)
157 std::cerr <<
"cbeam::logging::log_manager::~log_manager: Could not lock the mutex. This indicates a serious (unexpected) bug that must be fixed during development phase." << std::endl;
164 if (!_shutting_down_mutex.try_lock() && instance)
172 instance = Instance();
175 if (is_operational_for_logging())
177 std::lock_guard<std::recursive_mutex> lock(instance->_log_mutex);
180 instance->_log = std::make_shared<log>(path);
184 _shutting_down_mutex.unlock();
189 std::lock_guard<std::recursive_mutex> lockShuttingDown(_shutting_down_mutex);
190 auto instance = Instance();
192 if (is_operational_for_logging())
194 std::lock_guard<std::recursive_mutex> lockLog(instance->_log_mutex);
197 create_logfile(std::filesystem::temp_directory_path() /
"Cbeam.log", instance);
199 instance->_log->append(str);
205 std::lock_guard<std::recursive_mutex> lockShuttingDown(_shutting_down_mutex);
206 if (is_operational_for_logging())
218 inline bool log_manager::is_operational_for_logging()
222 std::cerr <<
"Error: The main function returned or the shared library is being unloaded, but a logging attempt has been made." << std::endl
224 <<
"This condition indicates a serious issue that must be resolved during the development phase." << std::endl
225 <<
"The static cbeam::logging::log_manager instance has been correctly destroyed by the C++ runtime" << std::endl
226 <<
"due to the termination of the main application or the unloading of a shared library. However," << std::endl
227 <<
"another thread is still attempting to perform logging operations. It is crucial to ensure that" << std::endl
228 <<
"all threads are joined before the main application exits or before the shared library is unloaded." << std::endl;
232 return !_shutting_down;
The log_manager class provides a global logging facility that can be used throughout the application.
Definition log_manager.hpp:49
virtual ~log_manager() noexcept
Definition log_manager.hpp:148
static void log_append(const std::wstring &str)
Appends a wide-string message to the current global log.
Definition log_manager.hpp:187
static void create_logfile(const std::filesystem::path &path, log_manager *instance=nullptr)
Creates or re-initializes the global log file at the specified path.
Definition log_manager.hpp:162
The log class provides basic file-based logging functionality.
Definition logging_impl.hpp:61
Contains conversion utilities to transform data between different formats and types....
Definition buffer.hpp:35
T from_string(const std::string &str)
Converts a given std::string to a specified type.
Definition string.hpp:171
Offers flexible logging mechanisms to record messages with timestamps and thread information....
Definition logging_impl.hpp:53