File logging_spi.hpp

File List > astutedds > security > logging_spi.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.
//

#pragma once

#include "security_types.hpp"

#include <chrono>
#include <memory>
#include <string>

namespace astutedds::security
{

enum class SecurityLogLevel : uint32_t
{
    EMERGENCY = 0,      // System is unusable
    ALERT = 1,          // Action must be taken immediately
    CRITICAL = 2,       // Critical conditions
    ERROR = 3,          // Error conditions
    WARNING = 4,        // Warning conditions
    NOTICE = 5,         // Normal but significant condition
    INFORMATIONAL = 6,  // Informational messages
    DEBUG = 7           // Debug-level messages
};

enum class SecurityEventCategory : uint32_t
{
    AUTHENTICATION = 0,
    ACCESS_CONTROL = 1,
    CRYPTO = 2,
    DISCOVERY = 3,
    DATA_PROTECTION = 4,
    PARTICIPANT_LIFECYCLE = 5,
    ENDPOINT_LIFECYCLE = 6,
    CONFIGURATION = 7,
    GENERAL = 8
};

struct SecurityEvent
{
    std::chrono::system_clock::time_point timestamp;
    SecurityLogLevel level{SecurityLogLevel::INFORMATIONAL};
    SecurityEventCategory category{SecurityEventCategory::GENERAL};
    std::string message;
    PropertySeq context_properties;

    SecurityEvent() : timestamp(std::chrono::system_clock::now()) {}
};

class LoggingPlugin
{
public:
    virtual ~LoggingPlugin() = default;

    virtual bool set_log_level(SecurityLogLevel level, SecurityException& ex) = 0;

    virtual bool log(const SecurityEvent& event, SecurityException& ex) = 0;

    virtual bool log_authentication_event(SecurityLogLevel level, IdentityHandle local_identity,
                                          IdentityHandle remote_identity, const std::string& message,
                                          SecurityException& ex) = 0;

    virtual bool log_access_control_event(SecurityLogLevel level, PermissionsHandle permissions,
                                          const std::string& topic_name, const std::string& message,
                                          SecurityException& ex) = 0;

    virtual bool log_crypto_event(SecurityLogLevel level, CryptoHandle crypto_handle, const std::string& message,
                                  SecurityException& ex) = 0;

    virtual bool flush(SecurityException& ex) = 0;
};

using LoggingPluginPtr = std::shared_ptr<LoggingPlugin>;

}  // namespace astutedds::security