Log === The Log class provides a comprehensive logging system with multiple severity levels and flexible output options. It supports both console and file logging with configurable levels, colors, and precision formatting. .. tab-set:: .. tab-item:: Python .. py:class:: aidge_core.Log Static logging utility class for managing application logs. .. py:method:: debug(msg: str) -> None :staticmethod: Detailed messages for debugging purposes, providing information helpful for developers to trace and identify issues. Detailed insights of what is happening in an operation, not useful for the end-user. The operation is performed nominally. .. note:: This level is disabled at compile time for Release builds, therefore inducing no runtime overhead for Release. :param msg: Debug message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.debug("Variable x has value: 42") .. py:method:: info(msg: str) -> None :staticmethod: Messages that provide a record of the normal operation, about the application's state, progress, or important events. Reports normal start, end and key steps in an operation. The operation is performed nominally. :param msg: Info message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.info("Model loaded successfully") .. py:method:: notice(msg: str) -> None :staticmethod: Applies to normal but significant conditions that may require monitoring, like unusual or normal fallback events. Reports specific paths in an operation. The operation can still be performed normally. :param msg: Notice message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.notice("Using fallback configuration") .. py:method:: warn(msg: str) -> None :staticmethod: Indicates potential issues or situations that may lead to errors but do not necessarily cause immediate problems. Some specific steps of the operation could not be performed, but it can still provide an exploitable result. :param msg: Warning message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.warn("Configuration file not found, using defaults") .. py:method:: error(msg: str) -> None :staticmethod: Signifies a problem or unexpected condition that the application can recover from, but attention is needed to prevent further issues. The operation could not be performed, but it does not prevent potential further operations. :param msg: Error message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.error("Failed to load input data") .. py:method:: fatal(msg: str) -> None :staticmethod: Represents a critical error or condition that leads to the termination of the application, indicating a severe and unrecoverable problem. The operation could not be performed and any further operation is impossible. :param msg: Fatal message. :type msg: str **Example:** .. code-block:: python from aidge_core import Log Log.fatal("Critical system failure, terminating") .. py:method:: set_console_level(level: Level) -> None :staticmethod: Set the minimum log level displayed in the console. Available ``Level`` values in ascending order: - ``Level.Debug`` - ``Level.Info`` - ``Level.Notice`` - ``Level.Warn`` - ``Level.Error`` - ``Level.Fatal`` :param level: Log level. :type level: Level **Example:** .. code-block:: python from aidge_core import Log, Level Log.set_console_level(Level.Warn) .. py:method:: get_console_level() -> Level :staticmethod: Get the current log level. Log level is set to ``Notice`` by default. Log level is shared across modules. Available ``Level`` values in ascending order: - ``Level.Debug`` - ``Level.Info`` - ``Level.Notice`` - ``Level.Warn`` - ``Level.Error`` - ``Level.Fatal`` :return: Current log level. :rtype: Level **Example:** .. code-block:: python from aidge_core import Log current_level = Log.get_console_level() .. py:method:: set_console_color(enabled: bool) -> None :staticmethod: Enables or disable color output on console. Initial value should be assumed ``True``. :param enabled: Activate or deactivate colors on console. :type enabled: bool **Example:** .. code-block:: python from aidge_core import Log Log.set_console_color(False) # Disable colors .. py:method:: set_file_level(level: Level) -> None :staticmethod: Set the minimum log level saved in the log file. Available ``Level`` values in ascending order: - ``Level.Debug`` - ``Level.Info`` - ``Level.Notice`` - ``Level.Warn`` - ``Level.Error`` - ``Level.Fatal`` :param level: Log level. :type level: Level **Example:** .. code-block:: python from aidge_core import Log, Level Log.set_file_level(Level.Debug) .. py:method:: set_file_name(fileName: str) -> None :staticmethod: Set the log file name. Close the current log file and open the one with the new file name. If empty, stop logging into a file. :param fileName: Log file name. :type fileName: str **Example:** .. code-block:: python from aidge_core import Log Log.set_file_name("application.log") .. py:method:: set_precision(precision: int) -> None :staticmethod: Set the precision format for floating point numbers. :param precision: Number of digits displayed on the right-hand of the decimal point. :type precision: int **Example:** .. code-block:: python from aidge_core import Log Log.set_precision(6) # Display 6 decimal places .. py:class:: aidge_core.Level Enumeration of logging severity levels. .. py:attribute:: Debug :type: Level Debug level - detailed diagnostic information. .. py:attribute:: Info :type: Level Info level - informational messages about normal operations. .. py:attribute:: Notice :type: Level Notice level - normal but significant conditions. .. py:attribute:: Warn :type: Level Warning level - potential issues that may require attention. .. py:attribute:: Error :type: Level Error level - recoverable errors that need attention. .. py:attribute:: Fatal :type: Level Fatal level - critical unrecoverable errors. .. tab-item:: C++ .. doxygenclass:: Aidge::Log :members: :undoc-members: **Example Usage (C++):** .. code-block:: cpp #include "aidge/utils/Log.hpp" using namespace Aidge; // Set console log level Log::setConsoleLevel(Log::Level::Info); // Basic logging Log::info("Application started"); Log::debug("Variable value: {}", myVariable); Log::warn("Potential issue detected"); // Configure file logging Log::setFileName("app.log"); Log::setFileLevel(Log::Level::Debug); // Set floating point precision Log::setPrecision(4); // Error handling if (error_condition) { Log::error("Operation failed: {}", error_msg); } Usage Examples -------------- Basic Logging ~~~~~~~~~~~~~ .. tab-set:: .. tab-item:: Python .. code-block:: python from aidge_core import Log, Level # Simple logging Log.info("Starting processing") Log.debug("Processing step 1") Log.warn("Unusual condition detected") # Configure console output Log.set_console_level(Level.Info) Log.set_console_color(True) .. tab-item:: C++ .. code-block:: cpp #include "aidge/utils/Log.hpp" using namespace Aidge; // Simple logging Log::info("Starting processing"); Log::debug("Processing step 1"); Log::warn("Unusual condition detected"); // Configure console output Log::setConsoleLevel(Log::Level::Info); Log::setConsoleColor(true); File Logging ~~~~~~~~~~~~ .. tab-set:: .. tab-item:: Python .. code-block:: python from aidge_core import Log, Level # Enable file logging Log.set_file_name("application.log") Log.set_file_level(Level.Debug) # All messages at Debug level and above will be written to file Log.debug("This goes to the file") Log.info("This also goes to the file") # Stop file logging Log.set_file_name("") .. tab-item:: C++ .. code-block:: cpp #include "aidge/utils/Log.hpp" using namespace Aidge; // Enable file logging Log::setFileName("application.log"); Log::setFileLevel(Log::Level::Debug); // All messages at Debug level and above will be written to file Log::debug("This goes to the file"); Log::info("This also goes to the file"); // Stop file logging Log::setFileName(""); Notes ----- - The default console log level is ``Notice``. - Debug level is disabled at compile time for Release builds (C++ only). - Log levels are shared across all modules. - Color output is enabled by default on console. - When setting a log level, only messages at that level or higher severity will be displayed/saved. - An empty filename stops file logging.