-
Notifications
You must be signed in to change notification settings - Fork 537
AIESW-28663 : Add syslog equivalent message dispatcher for Windows #9837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rbramand-xilinx
wants to merge
5
commits into
Xilinx:master
Choose a base branch
from
rbramand-xilinx:event_log
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+271
−91
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6177e7f
Add changes to dump xrt messages to windows event log
rbramand-xilinx 4c5523c
Address comments
rbramand-xilinx fde1b6f
Add separate headers for platform specific code
rbramand-xilinx 3aaa705
Fix clang-tidy warnings
rbramand-xilinx f51a641
simiplify windows library linking
rbramand-xilinx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| // POSIX syslog implementation of syslog_dispatch. | ||
|
|
||
| #include "core/common/message.h" | ||
|
|
||
| #include <map> | ||
| #include <syslog.h> | ||
|
|
||
| namespace xrt_core::message { | ||
|
|
||
| class syslog_dispatch : public message_dispatch | ||
|
rbramand-xilinx marked this conversation as resolved.
|
||
| { | ||
| public: | ||
| syslog_dispatch() | ||
| { openlog("sdaccel", LOG_PID|LOG_CONS, LOG_USER); } | ||
|
|
||
| syslog_dispatch(const syslog_dispatch&) = delete; | ||
| syslog_dispatch& operator=(const syslog_dispatch&) = delete; | ||
| syslog_dispatch(syslog_dispatch&&) = delete; | ||
| syslog_dispatch& operator=(syslog_dispatch&&) = delete; | ||
|
|
||
| ~syslog_dispatch() override | ||
| { closelog(); } | ||
|
|
||
| void | ||
| send(severity_level l, const char* tag, const char* msg) override | ||
| { syslog(m_severity_map[l], "%s", msg); } | ||
|
|
||
| private: | ||
| std::map<severity_level, int> m_severity_map = { | ||
| { severity_level::emergency, LOG_EMERG }, | ||
| { severity_level::alert, LOG_ALERT }, | ||
| { severity_level::critical, LOG_CRIT }, | ||
| { severity_level::error, LOG_ERR }, | ||
| { severity_level::warning, LOG_WARNING }, | ||
| { severity_level::notice, LOG_NOTICE }, | ||
| { severity_level::info, LOG_INFO }, | ||
| { severity_level::debug, LOG_DEBUG } | ||
| }; | ||
| }; | ||
|
|
||
| } // xrt_core::message | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| #ifndef core_common_detail_syslog_h | ||
| #define core_common_detail_syslog_h | ||
|
|
||
| #ifdef _WIN32 | ||
| # include "core/common/detail/windows/syslog.h" | ||
| #else | ||
| # include "core/common/detail/linux/syslog.h" | ||
| #endif | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| // Windows Event Log implementation of syslog_dispatch. | ||
| // Routes XRT messages to the Application event log under source "AMD_XRT". | ||
| // | ||
| // Filter in Event Viewer: | ||
| // Windows Logs -> Application -> Source: AMD_XRT | ||
| // Filter via PowerShell: | ||
| // Get-EventLog -LogName Application -Source "AMD_XRT" | ||
| // Get-EventLog -LogName Application -Source "AMD_XRT" -EntryType Error | ||
| // Get-EventLog -LogName Application -Source "AMD_XRT" -EntryType Error,Warning | ||
| // Filter via cmd (Level: 2=Error, 3=Warning, 4=Information): | ||
| // wevtutil qe Application /q:"*[System[Provider[@Name='AMD_XRT']]]" /f:text | ||
| // wevtutil qe Application /q:"*[System[Provider[@Name='AMD_XRT'] and Level=2]]" /f:text | ||
| // wevtutil qe Application /q:"*[System[Provider[@Name='AMD_XRT'] and (Level=2 or Level=3)]]" /f:text | ||
|
|
||
| #include "core/common/message.h" | ||
|
|
||
| #include <array> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <windows.h> | ||
|
rbramand-xilinx marked this conversation as resolved.
|
||
|
|
||
| #pragma comment(lib, "Advapi32.lib") // for Windows Event Log APIs | ||
|
|
||
| namespace xrt_core::message { | ||
|
|
||
| class syslog_dispatch : public message_dispatch | ||
|
rbramand-xilinx marked this conversation as resolved.
|
||
| { | ||
| public: | ||
| syslog_dispatch() | ||
| { | ||
| // RegisterEventSourceA opens a handle to the Application event log and | ||
| // associates it with the source name "AMD_XRT". Registry registration of | ||
| // "AMD_XRT" as a known source is done at driver install time via the INF | ||
| // AddReg directive. This call does not require admin rights. | ||
| m_handle = RegisterEventSourceA(nullptr, "AMD_XRT"); | ||
| // Do not throw on failure: this is constructed lazily on first | ||
| // xrt_core::message::send(), so a throw here would crash the application | ||
| // if the Windows Event Log service is unavailable. | ||
| if (!m_handle) | ||
| std::cerr << "XRT: Failed to open Windows Event Log source 'AMD_XRT' " | ||
| << "(error " << GetLastError() << "). Logging disabled.\n"; | ||
| } | ||
|
|
||
| syslog_dispatch(const syslog_dispatch&) = delete; | ||
| syslog_dispatch& operator=(const syslog_dispatch&) = delete; | ||
| syslog_dispatch(syslog_dispatch&&) = delete; | ||
| syslog_dispatch& operator=(syslog_dispatch&&) = delete; | ||
|
|
||
| ~syslog_dispatch() override | ||
|
rbramand-xilinx marked this conversation as resolved.
|
||
| { | ||
| if (m_handle) | ||
| DeregisterEventSource(m_handle); | ||
| } | ||
|
|
||
| void | ||
| send(severity_level l, const char* tag, const char* msg) override | ||
| { | ||
| if (!m_handle) | ||
| return; | ||
|
|
||
| std::string full_msg = std::string("[") + tag + "] : " + msg; | ||
| std::array<LPCSTR, 1> strings = {full_msg.c_str()}; | ||
| // Event ID 1 matches the pass-through entry in EventCreate.exe's message | ||
| // table (%1), so Event Viewer displays our text directly without a warning. | ||
| // Severity filtering uses wType (Level column), not event ID. | ||
| static constexpr DWORD event_id = 1; | ||
| ReportEventA(m_handle, to_event_type(l), 0, event_id, | ||
| nullptr, 1, 0, strings.data(), nullptr); | ||
| } | ||
|
|
||
| private: | ||
| HANDLE m_handle = nullptr; | ||
|
|
||
| // Maps XRT severity to Windows event type (controls icon in Event Viewer): | ||
| // EVENTLOG_ERROR_TYPE -> red X (emergency/alert/critical/error) | ||
| // EVENTLOG_WARNING_TYPE -> yellow triangle | ||
| // EVENTLOG_INFORMATION_TYPE -> blue i (notice/info/debug) | ||
| static WORD | ||
| to_event_type(severity_level l) | ||
| { | ||
| if (l == severity_level::warning) | ||
| return EVENTLOG_WARNING_TYPE; | ||
| if (l == severity_level::emergency || l == severity_level::alert || | ||
| l == severity_level::critical || l == severity_level::error) | ||
| return EVENTLOG_ERROR_TYPE; | ||
| return EVENTLOG_INFORMATION_TYPE; | ||
| } | ||
| }; | ||
|
|
||
| } // xrt_core::message | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.