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.
- class aidge_core.Log#
Static logging utility class for managing application logs.
- static debug(msg: str) None#
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.
- Parameters:
msg (str) – Debug message.
Example:
from aidge_core import Log Log.debug("Variable x has value: 42")
- static info(msg: str) None#
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.
- Parameters:
msg (str) – Info message.
Example:
from aidge_core import Log Log.info("Model loaded successfully")
- static notice(msg: str) None#
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.
- Parameters:
msg (str) – Notice message.
Example:
from aidge_core import Log Log.notice("Using fallback configuration")
- static warn(msg: str) None#
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.
- Parameters:
msg (str) – Warning message.
Example:
from aidge_core import Log Log.warn("Configuration file not found, using defaults")
- static error(msg: str) None#
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.
- Parameters:
msg (str) – Error message.
Example:
from aidge_core import Log Log.error("Failed to load input data")
- static fatal(msg: str) None#
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.
- Parameters:
msg (str) – Fatal message.
Example:
from aidge_core import Log Log.fatal("Critical system failure, terminating")
- static set_console_level(level: Level) None#
Set the minimum log level displayed in the console.
Available
Levelvalues in ascending order:Level.DebugLevel.InfoLevel.NoticeLevel.WarnLevel.ErrorLevel.Fatal
- Parameters:
level (Level) – Log level.
Example:
from aidge_core import Log, Level Log.set_console_level(Level.Warn)
- static get_console_level() Level#
Get the current log level. Log level is set to
Noticeby default.Log level is shared across modules.
Available
Levelvalues in ascending order:Level.DebugLevel.InfoLevel.NoticeLevel.WarnLevel.ErrorLevel.Fatal
- Returns:
Current log level.
- Return type:
Example:
from aidge_core import Log current_level = Log.get_console_level()
- static set_console_color(enabled: bool) None#
Enables or disable color output on console.
Initial value should be assumed
True.- Parameters:
enabled (bool) – Activate or deactivate colors on console.
Example:
from aidge_core import Log Log.set_console_color(False) # Disable colors
- static set_file_level(level: Level) None#
Set the minimum log level saved in the log file.
Available
Levelvalues in ascending order:Level.DebugLevel.InfoLevel.NoticeLevel.WarnLevel.ErrorLevel.Fatal
- Parameters:
level (Level) – Log level.
Example:
from aidge_core import Log, Level Log.set_file_level(Level.Debug)
- static set_file_name(fileName: str) None#
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.
- Parameters:
fileName (str) – Log file name.
Example:
from aidge_core import Log Log.set_file_name("application.log")
- static set_precision(precision: int) None#
Set the precision format for floating point numbers.
- Parameters:
precision (int) – Number of digits displayed on the right-hand of the decimal point.
Example:
from aidge_core import Log Log.set_precision(6) # Display 6 decimal places
- class aidge_core.Level#
Enumeration of logging severity levels.
-
class Log#
Logging utility class for development and debugging.
The Log class provides a static interface for logging messages at different severity levels. It supports both console output (with optional colors) and file output. The logging behavior can be configured through environment variables or programmatically.
Environment variables:
AIDGE_LOGLEVEL_CONSOLE: Set console output level (Debug,Info,Notice,Warn,Error,Fatal)
AIDGE_LOGLEVEL_FILE: Set file output level
AIDGE_LOG_COLOR: Enable/disable colored output (“off”/”OFF”/”0” to disable)
AIDGE_LOG_FILE: Set log file path
Note
Console colors are enabled by default
Public Types
-
enum Level#
Log severity levels in ascending order.
Values:
-
enumerator Debug#
Detailed information for debugging.
-
enumerator Info#
General information about program execution.
-
enumerator Notice#
Normal but significant conditions.
-
enumerator Warn#
Warning messages for potentially problematic situations.
-
enumerator Error#
Error messages for serious problems.
-
enumerator Fatal#
Critical errors that lead to program termination.
-
enumerator Debug#
Public Static Functions
-
template<typename ...T>
static inline void print(FILE *f, fmt::format_string<T...> fmt, T&&... args)#
-
template<typename ...T>
static inline void println(FILE *f, fmt::format_string<T...> fmt, T&&... args)#
-
template<typename ...Args>
static inline void debug(Args&&... args)# Log a debug message.
Note
Debug messages are only compiled in debug builds
- Parameters:
args – Format string and arguments for the message
-
template<typename ...Args>
static inline void info(Args&&... args)# Log an info message.
- Parameters:
args – Format string and arguments for the message
-
template<typename ...Args>
static inline void notice(Args&&... args)# Log a notice message.
- Parameters:
args – Format string and arguments for the message
-
template<typename ...Args>
static inline void warn(Args&&... args)# Log a warning message.
- Parameters:
args – Format string and arguments for the message
-
template<typename ...Args>
static inline void error(Args&&... args)# Log an error message.
- Parameters:
args – Format string and arguments for the message
-
template<typename ...Args>
static inline void fatal(Args&&... args)# Log a fatal error message.
- Parameters:
args – Format string and arguments for the message
-
static inline void setConsoleLevel(Level level)#
Set the minimum level for console output.
- Parameters:
level – Minimum level to display
-
static inline void setConsoleColor(bool enabled) noexcept#
Enable or disable colored console output.
- Parameters:
enabled – True to enable colors, false to disable
-
static inline void setFileLevel(Level level) noexcept#
Set the minimum level for file output.
- Parameters:
level – Minimum level to write to file
-
static void setFileName(const std::string &fileName)#
Set the log file path.
- Parameters:
fileName – Path to log file (empty to disable file logging)
- Throws:
std::runtime_error – if file cannot be opened
-
static inline void setPrecision(int precision) noexcept#
Set the precision format for floating point numbers.
- Parameters:
precision – number of digits displayed on the right-hand of the decimal point.
-
static inline int getPrecision() noexcept#
-
class Context#
RAII class for managing logging contexts.
This class allows adding temporary context information to logs. When an instance is created, it adds a context message that will be displayed with all logs until the instance is destroyed.
Example:
{ Log::Context ctx("Processing file: {}", filename); Log::info("Starting process"); // Will show context // Context automatically removed when ctx is destroyed }
Example Usage (C++):
#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#
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)
#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#
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("")
#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.