Monado OpenXR Runtime
ovrd_log.hpp
Go to the documentation of this file.
1// Copyright 2020, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Logger code.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup st_ovrd
8 */
9
10#pragma once
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <stdarg.h>
17
18#include "xrt/xrt_compiler.h"
19
20#ifdef __cplusplus
21}
22#endif
23
24#include "openvr_driver.h"
25
26static vr::IVRDriverLog *s_pLogFile = NULL;
27
28static inline void
29ovrd_log_init(vr::IVRDriverLog *pDriverLog)
30{
31 // Noop
32 s_pLogFile = vr::VRDriverLog();
33}
34
35// Cannot use the XRT_PRINTF_FORMAT macro on a function definition.
36static inline void
37ovrd_log(const char *fmt, ...) XRT_PRINTF_FORMAT(1, 2);
38
39static inline void
40ovrd_log(const char *fmt, ...)
41{
42 va_list args;
43 va_start(args, fmt);
44
45 char buf[1024];
46#if defined(WIN32)
47 vsprintf_s(buf, fmt, args);
48#else
49 vsnprintf(buf, sizeof(buf), fmt, args);
50#endif
51
52 if (s_pLogFile)
53 s_pLogFile->Log(buf);
54
55 va_end(args);
56}
57
58static inline void
59ovrd_log_cleanup()
60{
61 s_pLogFile = nullptr;
62}
Header holding common defines.