Log

Demonstrates how to enable log and get log data when programming with ADLX.

Command Prompts

Command Prompt Description
1 Enable log with local file, file [./ADLX.log] is created.
2 Enable log with DebugView.
3 Eenable log with app handle.
Q/q Terminate the application.

Sample Path

/Samples/C/Generic/Log

Code

Copied!

//
// Copyright (c) 2021 - 2025 Advanced Micro Devices, Inc. All rights reserved.
//
//-------------------------------------------------------------------------------------------------

#include "SDK/ADLXHelper/Windows/C/ADLXHelper.h"
#include "SDK/Include/IDisplays.h"

// CallBack to handle ADLX log
ADLX_RESULT  ADLX_STD_CALL WriteLog(IADLXLog* pThis, const wchar_t* msg)
{
    wprintf(L"%s", msg);
    return ADLX_OK ;
}

// Application's log struct demostration, application can capture ADLX log here
typedef struct AppHandlLog
{
    ADLX_RESULT (ADLX_STD_CALL* WriteLog)
    (IADLXLog* pThis, const wchar_t* msg);
} AppHandlLog;

// Local file, ADLX log data is saved to file
void UseLocalFile()
{
    // Get system services
    IADLXSystem* sys = ADLXHelper_GetSystemServices();

    // Log destination, severity, logfile
    ADLX_LOG_DESTINATION  mode = LOCALFILE ;
    ADLX_LOG_SEVERITY  severity = LDEBUG ;
    wchar_t logfile[] = L"./ADLX.log";

    // Enable log
    ADLX_RESULT  res = sys->pVtbl->EnableLog(sys, mode, severity, NULL, logfile);
    printf("Enabled log result: %d (0 means success)\\n", res);
}

// Configure ADLX log to send errors, warnings and debug information messages to the DebugView
void UseDebugView()
{
    // Get system services
    IADLXSystem* sys = ADLXHelper_GetSystemServices();

    // Log destination, severity
    ADLX_LOG_DESTINATION  mode = DBGVIEW ;
    ADLX_LOG_SEVERITY  severity = LDEBUG ;

    // Enable log
    ADLX_RESULT  res = sys->pVtbl->EnableLog(sys, mode, severity, NULL, NULL);
    printf("Enabled log result : %d (0 means Success)\\n", res);
}

// Application handle log, application's callback will handle the ADLX log
void UseAppHandlLog(AppHandlLog** appHandlLog)
{
    // Get system services
    IADLXSystem* sys = ADLXHelper_GetSystemServices();

    // Log destination, severity
    ADLX_LOG_DESTINATION  mode = APPLICATION ;
    ADLX_LOG_SEVERITY  severity = LDEBUG ;

    // Enable log
    ADLX_RESULT  res = sys->pVtbl->EnableLog(sys, mode, severity, (IADLXLog*)appHandlLog, NULL);
    printf("Enabled log result : %d (0 means Success)\\n", res);
}

// Main menu
void MainMenu()
{
    printf("\\tChoose from the following options:\\n");
    printf("\\t->Press 1 to enable log with local file, file [./ADLX.log] will be created.\\n");
    printf("\\t->Press 2 to enable log with DebugView\\n");
    printf("\\t->Press 3 to enable log with app handle\\n");
}

// Menu action control
void MenuControl(AppHandlLog** appHandlLog)
{
    int num = 0;
    num = getchar();
    switch (num)
    {
    // Local file
    case '1':
        UseLocalFile();
        break;

    // DebugView
    case '2':
        UseDebugView();
        break;

    // App handle
    case '3':
        UseAppHandlLog(appHandlLog);
        break;

    default:
        printf("Invalid input\\n");
        break;
    }
}

// Wait for exit with error message
int WaitAndExit(const char* msg, const int retCode)
{
    // Printout the message and pause to see it before returning the desired code
    if (NULL != msg)
        printf("%s\\n", msg);

    system("pause");
    return retCode;
}

int main()
{
    // Define return code
    ADLX_RESULT  res = ADLX_FAIL ;

    // Initialize ADLX
    res = ADLXHelper_Initialize();
    if (ADLX_SUCCEEDED (res))
    {
        // Get system services
        IADLXSystem* sys = ADLXHelper_GetSystemServices();

        // App create object to handle ADLX log
        AppHandlLog* appHandlLog = (AppHandlLog*)malloc(sizeof(AppHandlLog));
        appHandlLog->WriteLog = &WriteLog;

        // Menu
        MainMenu();
        MenuControl(&appHandlLog);

        // Try get log by using some interfaces
        // Get display service and display numbers
        IADLXDisplayServices* displayService = NULL;
        res = sys->pVtbl->GetDisplaysServices(sys, &displayService);
        if (ADLX_SUCCEEDED (res))
        {
            adlx_uint displayNum;
            displayService->pVtbl->GetNumberOfDisplays(displayService, &displayNum);
        }
        if (NULL != displayService)
        {
            displayService->pVtbl->Release(displayService);
            displayService = NULL;
        }

        // Destroy ADLX
        res = ADLXHelper_Terminate();
        printf("Destroy ADLX res: %d\\n", res);

        // appHandlLog may be used throughout the life cycle of ADLX,
        // So destroy appHandlLog after destroying ADLX
        free(appHandlLog);
        appHandlLog = NULL;
    }
    else
    {
        return WaitAndExit("ADLX initialization failed", 0);
    }

    // Pause for user see the print out
    system("pause");

    return 0;
}

Related pages

  • Visit the Adlx product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNA™ 2 GPUs, AMD Ryzen™ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!