Hide menu
Loading...
Searching...
No Matches
Logging Support

Overview

Manufacturing toolkit provides built-in logging functionality that can be used to trace execution, analyze behavior, and debug issues. Logging is handled through a global singleton instance: Utilities::Logger::Instance() .

The logger filters messages based on severity levels (Utilities::LoggerLevel ) and dispatches accepted messages to registered handlers.

Message delivery is synchronous, meaning execution continues only after all handlers have processed the message.

Message severity level

Message level is defined by an enumeration Utilities::LoggerLevel . The following levels are supported (given in the order of decreasing severity):

  • Fatal
  • Error
  • Warning
  • Info
  • Debug
  • Trace

Utilities::Logger::SetLevel() sets a threshold level for the messages which should be accepted by the logger. The messages sent with the same or greater level are accepted, the ones with a lower level are ignored.

The Debug and Trace levels are reserved for internal purposes and should not be used by the MTK users.

Quick Start

#include <cadex/Utilities/Logger.hxx>
#include <cadex/Utilities/LoggerFileHandler.hxx>
auto& aLogger = Utilities::Logger::Instance();
aLogger.SetLevel (LoggerLevel::Info);
auto aHandler = std::make_shared<LoggerFileHandler> ("c:/temp/1.log");
aLogger.Register (aHandler, LoggerLevel::Info, LoggerLevel::Fatal);
static Logger & Instance()
Returns a global logger.
Definition Logger.cxx:174

Environment Variables

Variable Effect
MTK_LOG_FILE Enables logging to the specified file (absolute path required).

Handlers

Handlers are responsible for processing log messages. They implement the Utilities::LoggerHandler interface. The MTK provides the following built-in handlers:

Handlers are executed in the order they are registered. They must be unregistered before destruction.

Asynchronous Logging

Utilities::LoggerAsyncHandler is a proxy that forwards accepted messages to other handlers using a background thread.

auto anAsyncHandler = std::make_shared<LoggerAsyncHandler>();
anAsyncHandler->Register(aFileHandler); // aFileHandler is another LoggerHandler
aLogger.Register(anAsyncHandler);

Thread Safety

Logging operations and handler registration are thread-safe. Internally, the logger ensures that only one message is processed at a time. Utilities::LoggerAsyncHandler also manages its internal handlers in a thread-safe way.

Note
If multiple handlers write to the same shared resource (e.g. std::cout), the user is responsible for synchronization.