omni/log/LogChannel.h
File members: omni/log/LogChannel.h
// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <cstdint>
#include <vector>
#define OMNI_LOG_DECLARE_CHANNEL(varName_) extern omni::log::LogChannelData varName_;
#define OMNI_LOG_ADD_CHANNEL(varName_, channelName_, description_)                                                     \
    OMNI_LOG_DEFINE_CHANNEL_(varName_, channelName_, description_, true)
#define OMNI_LOG_DEFINE_CHANNEL(varName_, channelName_, description_)                                                  \
    OMNI_LOG_DEFINE_CHANNEL_(varName_, channelName_, description_, false)
#define OMNI_LOG_DEFINE_CHANNEL_(varName_, channelName_, description_, add_)                                           \
    omni::log::LogChannelData varName_{ channelName_, 0, description_, nullptr };                                      \
    omni::log::LogChannelRegistrar varName_##Registrar{ &varName_, add_ };
#ifndef OMNI_LOG_DEFAULT_CHANNEL
#    define OMNI_LOG_DEFAULT_CHANNEL kDefaultChannel
#endif
namespace omni
{
namespace log
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
struct LogChannelData
{
    const char* const name;
    int32_t level;
    const char* const description;
    LogChannelData* next;
};
#endif
inline LogChannelData*& getModuleLogChannels() noexcept
{
    static LogChannelData* sHead = nullptr;
    return sHead;
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class LogChannelRegistrar
{
public:
    LogChannelRegistrar(LogChannelData* data, bool add) noexcept
    {
        if (add)
        {
            data->next = getModuleLogChannels();
            getModuleLogChannels() = data;
        }
    }
};
#endif
} // namespace log
} // namespace omni
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#    define OMNI_LOG_DECLARE_DEFAULT_CHANNEL_1(chan_) OMNI_LOG_DECLARE_CHANNEL(chan_)
#    define OMNI_LOG_DECLARE_DEFAULT_CHANNEL() OMNI_LOG_DECLARE_DEFAULT_CHANNEL_1(OMNI_LOG_DEFAULT_CHANNEL)
// forward declare the default channel
OMNI_LOG_DECLARE_DEFAULT_CHANNEL()
#endif