carb/logging/ILogging.h

File members: carb/logging/ILogging.h

// Copyright (c) 2018-2024, 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 "../Interface.h"
#include "../IObject.h"

#define carb_logging_ILogging_latest CARB_HEXVERSION(1, 2)
#ifndef carb_logging_ILogging
#    define carb_logging_ILogging CARB_HEXVERSION(1, 1)
#endif

#include "StandardLogger2.h"

namespace carb
{
namespace logging
{

struct StandardLogger;
class StandardLogger2;
struct Logger;

typedef void(CARB_ABI* SetLogLevelFn)(int32_t logLevel);

enum class LogSettingBehavior
{
    eInherit,
    eOverride
};

typedef void (*LogFn)(const char* source,
                      int32_t level,
                      const char* fileName,
                      const char* functionName,
                      int lineNumber,
                      const char* fmt,
                      ...);

struct ILogging
{
    CARB_PLUGIN_INTERFACE_EX("carb::logging::ILogging", carb_logging_ILogging_latest, carb_logging_ILogging)

    void(CARB_ABI* log)(const char* source,
                        int32_t level,
                        const char* fileName,
                        const char* functionName,
                        int lineNumber,
                        const char* fmt,
                        ...) CARB_PRINTF_FUNCTION(6, 7);

    void(CARB_ABI* setLevelThreshold)(int32_t level);

    int32_t(CARB_ABI* getLevelThreshold)();

    void(CARB_ABI* setLogEnabled)(bool enabled);

    bool(CARB_ABI* isLogEnabled)();

    void(CARB_ABI* setLevelThresholdForSource)(const char* source, LogSettingBehavior behavior, int32_t level);

    void(CARB_ABI* setLogEnabledForSource)(const char* source, LogSettingBehavior behavior, bool enabled);

    void(CARB_ABI* reset)();

    void(CARB_ABI* addLogger)(Logger* logger);

    void(CARB_ABI* removeLogger)(Logger* logger);

#if CARB_VERSION_ATLEAST(carb_logging_ILogging, 1, 1)
    CARB_DEPRECATED("Use getDefaultLogger() instead") StandardLogger*(CARB_ABI* getDefaultLoggerOld)();

    CARB_DEPRECATED("Use createStandardLogger() instead") StandardLogger*(CARB_ABI* createStandardLoggerOld)();

    CARB_DEPRECATED("Use StandardLogger2::release() instead")
    void(CARB_ABI* destroyStandardLoggerOld)(StandardLogger* logger);
#else
    StandardLogger*(CARB_ABI* getDefaultLogger)();

    StandardLogger*(CARB_ABI* createStandardLogger)();

    void(CARB_ABI* destroyStandardLogger)(StandardLogger* logger);
#endif

    void(CARB_ABI* registerSource)(const char* source, SetLogLevelFn setLevelThreshold);

    void(CARB_ABI* unregisterSource)(const char* source);

    bool(CARB_ABI* setLogAsync)(bool logAsync);

    bool(CARB_ABI* getLogAsync)();

    void(CARB_ABI* flushLogs)();

#if CARB_VERSION_ATLEAST(carb_logging_ILogging, 1, 1)
    StandardLogger2*(CARB_ABI* getStandardLogger2)(StandardLogger* logger);

    StandardLogger2*(CARB_ABI* getDefaultLogger)();

    StandardLogger2*(CARB_ABI* createStandardLoggerInternal)();

    ObjectPtr<StandardLogger2> createStandardLogger()
    {
        using Ptr = ObjectPtr<StandardLogger2>;
        return Ptr(createStandardLoggerInternal(), Ptr::InitPolicy::eSteal);
    }
#endif
};

} // namespace logging
} // namespace carb