129 "Use 'common::interfaces::ILogger' via thread_context instead. "
130 "Will be removed in v2.0.")]]
142 "Use 'thread_context::has_logger()' instead. "
143 "Will be removed in v2.0.")]]
156 "Configure log level on 'common::interfaces::ILogger' instead. "
157 "Will be removed in v2.0.")]]
174 "Use 'thread_context::log()' with 'common::interfaces::ILogger' "
175 "instead. Will be removed in v2.0.")]]
177 std::string_view message, std::string_view context =
"") {
187 std::lock_guard<std::mutex> lock(
mutex_);
189 auto now = std::chrono::system_clock::now();
190 auto time_t_val = std::chrono::system_clock::to_time_t(now);
191 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
192 now.time_since_epoch()) % 1000;
196#if defined(_MSC_VER) || defined(_WIN32)
197 localtime_s(&tm_buf, &time_t_val);
199 localtime_r(&time_t_val, &tm_buf);
203 << std::put_time(&tm_buf,
"%Y-%m-%d %H:%M:%S")
204 <<
"." << std::setfill(
'0') << std::setw(3) << ms.count()
207 <<
"[Thread:" << thread_name <<
"] "
208 <<
"[TID:" << std::this_thread::get_id() <<
"] "
211 if (!context.empty()) {
212 std::cerr <<
" | Context: " << context;
215 std::cerr << std::endl;
225 template<
typename ErrorType>
227 "Use 'thread_context::log()' with 'common::interfaces::ILogger' "
228 "instead. Will be removed in v2.0.")]]
235 std::ostringstream oss;
260 default:
return "UNKNOWN";
289 "Use a null 'common::interfaces::ILogger' in thread_context to "
290 "disable logging. Will be removed in v2.0.")]]
306 "Superseded by 'common::interfaces::ILogger' injection. "
307 "Will be removed in v2.0.")]]
Represents an error in the thread system.
error_code code() const noexcept
Gets the error code.
const std::string & message() const noexcept
Gets the error message.
Structured logger for thread system.
thread_logger & operator=(const thread_logger &)=delete
void log_error(std::string_view thread_name, const ErrorType &error)
Log error with error code.
static const char * level_to_string(log_level level)
static thread_logger & instance()
Get singleton instance.
void set_enabled(bool enabled)
Enable/disable logging.
bool is_enabled() const
Check if logging is enabled.
static void prepare_shutdown()
Prepare for process shutdown.
bool is_lightweight_mode() const
Check if in lightweight mode.
void log(log_level level, std::string_view thread_name, std::string_view message, std::string_view context="")
Log a message with context.
static std::atomic< bool > is_shutting_down_
static bool is_shutting_down()
Check if shutdown is in progress.
void set_level(log_level level)
Set minimum log level.
thread_logger(const thread_logger &)=delete
void set_lightweight_mode(bool enabled)
Enable lightweight mode (disables all logging for maximum performance).
@ critical
At or above max_size, queue is full.
Core threading foundation of the thread system library.
log_level
Logging severity levels (legacy).
@ trace
Finest-grained informational events.
@ debug
Fine-grained informational events for debugging.
@ info
Informational messages highlighting progress.
@ error
Error events that might still allow continuation.