Skip to content

Commit 0cf9d6e

Browse files
martygrantkbenzie
andcommitted
Logger callback function sink (#17095)
Migrated from #1748 This PR implements #1330 through a new logger sink: a user configurable callback. It introduces some spec additions: - `typedef void (*ur_logger_output_callback_t)(ur_logger_level_t level, const char *pLoggerMsg, void *pUserData)` - `urSetLoggerCallback(ur_adapter_handle_t hAdapter, ur_logger_output_callback_t pfnLoggerCallback, void *pUserData, ur_logger_level_t level` )` - `urSetLoggerCallbackLevel(ur_adapter_handle_t hAdapter, ur_logger_level_t level)` - `typedef enum ur_logger_level_t` (moved the logger::level enum into the spec) This new logger sink will only be constructed once a user makes a call to `urSetLoggerCallback` (which is called from the UR `urAdapterSetLoggerCallback` entry point), supplying their own callback function. They can set the minimum logging level through `urSetLoggerCallbackLevel`. Any subsequent logging calls will additionally make a call to the supplied callback where the log level, message and user data will be sent. A callback has been setup in the SYCL RT in `sycl/source/detail/ur.cpp` to print logs to `std::err`: ``` void urLoggerCallback([[maybe_unused]] ur_logger_level_t level, const char *msg, [[maybe_unused]] void *userData) { std::cerr << msg << std::endl; } ``` A new test suite `LoggerWithCallbackSink` has been added to test this new functionality. --------- Co-authored-by: Kenneth Benzie (Benie) <[email protected]>
1 parent 8af4495 commit 0cf9d6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1630
-366
lines changed

include/ur_api.h

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_api_funcs.def

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_ddi.h

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_print.h

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_print.hpp

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/core/INTRO.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ By default, no messages are printed.
202202

203203
By default, there is a guarantee that *error* messages are flushed immediately. One can change this behavior to flush on lower-level messages.
204204

205-
Loggers redirect messages to *stdout*, *stderr*, or a file (default: *stderr*).
205+
Loggers redirect messages to *stdout*, *stderr*, a file, or a user configurable callback function (default: *stderr*).
206206

207-
All of these logging options can be set with **UR_LOG_LOADER** and **UR_LOG_NULL** environment variables described in the **Environment Variables** section below.
207+
All of these logging options (except the callback) can be set with **UR_LOG_LOADER** and **UR_LOG_NULL** environment variables described in the **Environment Variables** section below.
208208
Both of these environment variables have the same syntax for setting logger options:
209209

210210
"[level:debug|info|warning|error];[flush:<debug|info|warning|error>];[output:stdout|stderr|file,<path>]"
@@ -232,6 +232,10 @@ An example of an environment variable for setting up the null adapter library wi
232232

233233
UR_LOG_NULL="level:warning;output:stdout"
234234

235+
Logging callback
236+
^^^^^^^^^^^^^^^^^^^^^
237+
An API is available to configure the logging callback function :ref:`urAdapterSetLoggerCallback`. Additionally, the logging level can be set using :ref:`urAdapterSetLoggerCallbackLevel`.
238+
235239
Adapter Discovery
236240
---------------------
237241
UR is capable of discovering adapter libraries in the following ways in the listed order:

0 commit comments

Comments
 (0)