File logging.hpp

File List > astutedds > rtps > logging.hpp

Go to the documentation of this file

//
// Copyright (c) 2026, Astute Systems PTY LTD
//
// This file is part of the Astute DDS developed by Astute Systems.
//
// See the commercial LICENSE file in the project root for full license details.
//
// @file logging.hpp
// @brief AstuteDDS runtime logging infrastructure
//
// Provides log-level–filtered, timestamped diagnostic output for all
// AstuteDDS layers (RTPS, DCPS, XTypes, Security).
//
// Environment variables (checked once at startup):
//   ASTUTEDDS_LOG=<path>          Write log to <path>; enables logging.
//                                  Use "" or omit to write to stderr when
//                                  logging is enabled programmatically.
//   ASTUTEDDS_LOG_LEVEL=<level>   Filter messages.  <level> is one of
//                                  ERROR | WARN | INFO | DEBUG | TRACE
//                                  (case-insensitive).  Default: DEBUG.
//
// Usage:
//   #include <astutedds/rtps/logging.hpp>
//   using astutedds::rtps::LogLevel;
//   astutedds::rtps::log_message(LogLevel::INFO, "[DCPS] Topic '%s' created", name);
//

#ifndef ASTUTEDDS_RTPS_LOGGING_HPP
#define ASTUTEDDS_RTPS_LOGGING_HPP

namespace astutedds::rtps
{

enum class LogLevel
{
    ERROR = 0, 
    WARN  = 1, 
    INFO  = 2, 
    DEBUG = 3, 
    TRACE = 4, 
};

void enableLogging(const char *path);

void setLogLevel(LogLevel level);

void log_message(LogLevel level, const char *format, ...)
#if defined(__GNUC__) || defined(__clang__)
    __attribute__((format(printf, 2, 3)))
#endif
    ;

} // namespace astutedds::rtps

#endif // ASTUTEDDS_RTPS_LOGGING_HPP