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 Enable log with application handle.
Q/q Terminate the application.

Sample Path

/Samples/CPP/Generic/Log

Code

Copied!

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


#include "SDK/ADLXHelper/Windows/Cpp/ADLXHelper.h"
#include "SDK/Include/IDisplays.h"
#include "SDK/Include/ILog.h"
#include <iostream>

// Use ADLX namespace
using namespace adlx;

// ADLXHelper instance
// No outstanding interfaces from ADLX must exist when ADLX is destoryed.
// Use global variables to ensure validity of the interface.
static ADLXHelper g_ADLXHelp;

// Demonstrates how applications capture ADLX log
// The log class may get used throughout the liftime of ADLX.
// Global variables are used as they hold their value throughout the lifetime of ADLX.
class AppHandlLog : public IADLXLog
{
  public:
    ADLX_RESULT  ADLX_STD_CALL WriteLog(const wchar_t* msg)
    {
        wprintf(L"%s", msg);
        return ADLX_OK ;
    }
};

// Application creates object to handle ADLX log
static AppHandlLog g_appHandlLog;

// Wait for exit with error message
int WaitAndExit(const char* msg, const int retCode);

// Local file
void UseLocalFile();

// Output window of the application debugger
void UseWindowDebugger();

// Application handle log
void UseAppHandlLog();

// Main menu
void MainMenu();

// Menu action control
void MenuControl();

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

    // Initialize ADLX
    res = g_ADLXHelp.Initialize();
    if (ADLX_SUCCEEDED (res))
    {
        // Menu
        MainMenu();
        MenuControl();

        // Call ADLX methods to generate log entries
        // Get display service and the number of displays
        IADLXDisplayServicesPtr displayService;
        res = g_ADLXHelp.GetSystemServices()->GetDisplaysServices(&displayService);
        if (ADLX_SUCCEEDED (res))
        {
            adlx_uint displayNum;
            displayService->GetNumberOfDisplays(&displayNum);
        }
    }
    else
    {
        return WaitAndExit("ADLX initialization failed", 0);
    }

    // Destroy ADLX
    res = g_ADLXHelp.Terminate();
    std::cout << "Destroy ADLX res: " << res << std::endl;

    // Pause to see the print out
    system("pause");
    return 0;
}

// Wait for exit with error message
int WaitAndExit(const char* msg, const int retCode)
{
    // Printout the message and pause to see before returning the desired code
    if (nullptr != msg)
        std::cout << msg << std::endl;

    system("pause");
    return retCode;
}

// Local file, ADLX log data will be saved to file
void UseLocalFile()
{
    // 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 = g_ADLXHelp.GetSystemServices()->EnableLog(mode, severity, nullptr, logfile);
    std::cout << "Enabled log res: " << res << "(0 means success)" << std::endl;
}

// Configure ADLX log to send errors, warnings and debug information messages to the DebugView.
void UseDebugView()
{
    // Log destination, severity
    ADLX_LOG_DESTINATION  mode = DBGVIEW ;
    ADLX_LOG_SEVERITY  severity = LDEBUG ;

    // Enable log
    ADLX_RESULT  res = g_ADLXHelp.GetSystemServices()->EnableLog(mode, severity, nullptr, nullptr);
    std::cout << "Enabled log result : " << res << "(0 means success)" << std::endl;
}

// Application handle log, app's callback will handle the ADLX log
void UseAppHandlLog()
{
    // Log destination, severity
    ADLX_LOG_DESTINATION  mode = APPLICATION ;
    ADLX_LOG_SEVERITY  severity = LDEBUG ;

    // Enable log
    ADLX_RESULT  res = g_ADLXHelp.GetSystemServices()->EnableLog(mode, severity, &g_appHandlLog, nullptr);
    std::cout << "Enabled log result: " << res << "(0 means success)" << std::endl;
}

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

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

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

    // Application handle
    case '3':
        UseAppHandlLog();
        break;

    default:
        std::cout << "Invalid input" << std::endl;
        break;
    }
}

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!