OpenVPN 3 Core Library
Loading...
Searching...
No Matches
logthread_macros.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// This is a general-purpose logging framework that allows for OPENVPN_LOG and
13// OPENVPN_LOG_NTNL macros to dispatch logging data to a thread-local handler.
14
15#pragma once
16
17// Define this parameter before including this header:
18// OPENVPN_LOG_INFO -- converts a log string to the form that should be passed to log()
19
20#ifndef OPENVPN_LOG_INFO
21#error OPENVPN_LOG_INFO must be defined
22#endif
23
24#define OPENVPN_LOG(args) \
25 do \
26 { \
27 if (openvpn::Log::Context::defined()) \
28 { \
29 std::ostringstream _ovpn_log; \
30 _ovpn_log << args << '\n'; \
31 (openvpn::Log::Context::obj()->log(OPENVPN_LOG_INFO(_ovpn_log.str()))); \
32 } \
33 } while (0)
34
35// like OPENVPN_LOG but no trailing newline
36#define OPENVPN_LOG_NTNL(args) \
37 do \
38 { \
39 if (openvpn::Log::Context::defined()) \
40 { \
41 std::ostringstream _ovpn_log; \
42 _ovpn_log << args; \
43 (openvpn::Log::Context::obj()->log(OPENVPN_LOG_INFO(_ovpn_log.str()))); \
44 } \
45 } while (0)
46
47#define OPENVPN_LOG_STRING(str) \
48 do \
49 { \
50 if (openvpn::Log::Context::defined()) \
51 { \
52 (openvpn::Log::Context::obj()->log(OPENVPN_LOG_INFO(str))); \
53 } \
54 } while (0)