18.6.3. Logger Module Usage - 5.2 English - 57404

AOCL User Guide (57404)

Document ID
57404
Release Date
2025-12-29
Version
5.2 English

The Logger module provides thread-safe logging utilities for applications.

Features:

  • Thread-safe logging

  • Multiple log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, PANIC, NOTICE

  • Supports both API calls and macros

  • Can log to console, files, or custom destinations

C API Logging

#include "Capi/au/logger/logger.h"

logger_ctx_t* logger = au_logger_create();
au_logger_log(logger, "Hello From Logger", AUD_LOG_LEVEL_INFO);
au_logger_log(logger, "Error occurred", AUD_LOG_LEVEL_ERROR);
au_logger_flush(logger);
au_logger_destroy(logger);

C Logging Macros

#include "Capi/au/logger/macros.h"

AUD_LOG_INFO("This is info message");
AUD_LOG_ERROR("This is error message");
AUD_LOG_WARN("This is warn message");

C++ API Logging

#include "Au/Logger/LogManager.hh"
#include "Au/Logger/Macros.hh"

auto consoleLogger = LoggerFactory::createLogger("ConsoleLogger", "Main");
LogWriter::setLogger(std::move(consoleLogger));
auto logWriter = LogWriter::getLogWriter();
LogManager logger(logWriter);

Message msg("This is a message");
logger.log(msg);
logger << "Using operator<<";
logger.flush();

C++ Logging Macros

AU_LOGGER_LOG_INFO("Info message");
AU_LOGGER_LOG_WARN("Warning message");
AU_LOGGER_LOG_ERROR("Error message");
AU_LOGGER_LOG_DEBUG("Debug message");

Log Levels (in order of severity):

  1. TRACE: Detailed execution traces

  2. DEBUG: Debug information

  3. INFO: Informational messages

  4. NOTICE: Normal but significant events

  5. WARN: Warning messages

  6. ERROR: Error conditions

  7. FATAL: Fatal errors

  8. PANIC: System panic (highest severity)

Using Logger for Diagnostics:

  • Enable DEBUG or TRACE level for troubleshooting

  • Use INFO level for production

  • ERROR/FATAL for critical issues

  • Thread-safe: can be used from multiple threads

Performance Considerations:

  • Asynchronous logging minimizes overhead

  • Flush periodically (not on every message)

  • Disable verbose logging in production for best performance

Best Practices:

  • Create logger once at startup

  • Use appropriate log levels (don’t spam INFO with DEBUG messages)

  • Flush before application exit

  • Clean up logger resources (au_logger_destroy in C)