mirror of
https://github.com/boostorg/log.git
synced 2026-01-19 04:22:09 +00:00
Added BOOST_LOG_WITHOUT_ASIO config option.
This lets users to disable Boost.ASIO-related functionality and remove the dependency on Boost.ASIO. This may be useful on platforms where Boost.ASIO or its dependencies don't work or disabled. Refs https://github.com/chriskohlhoff/asio/issues/1637.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2021-2024 Andrey Semashev
|
||||
# Copyright 2021-2025 Andrey Semashev
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -19,6 +19,7 @@ if (WIN32)
|
||||
set(BOOST_LOG_WITHOUT_EVENT_LOG OFF CACHE BOOL "Disable support for event log on Windows in Boost.Log")
|
||||
endif()
|
||||
set(BOOST_LOG_WITHOUT_IPC OFF CACHE BOOL "Disable support for inter-process communication in Boost.Log")
|
||||
set(BOOST_LOG_WITHOUT_ASIO OFF CACHE BOOL "Disable support for Boost.ASIO in Boost.Log")
|
||||
set(BOOST_LOG_WITHOUT_SYSLOG OFF CACHE BOOL "Disable support for syslog API in Boost.Log")
|
||||
set(BOOST_LOG_USE_NATIVE_SYSLOG OFF CACHE BOOL "Force-enable using native syslog API in Boost.Log")
|
||||
set(BOOST_LOG_USE_COMPILER_TLS OFF CACHE BOOL "Enable using compiler-specific intrinsics for thread-local storage in Boost.Log")
|
||||
@@ -123,6 +124,10 @@ else()
|
||||
list(APPEND boost_log_common_public_defines BOOST_LOG_STATIC_LINK)
|
||||
endif()
|
||||
|
||||
if (BOOST_LOG_WITHOUT_ASIO)
|
||||
list(APPEND boost_log_common_public_defines BOOST_LOG_WITHOUT_ASIO)
|
||||
endif()
|
||||
|
||||
set(boost_log_sources
|
||||
src/alignment_gap_between.hpp
|
||||
src/attribute_name.cpp
|
||||
@@ -496,7 +501,6 @@ target_link_libraries(boost_log
|
||||
|
||||
PRIVATE
|
||||
Boost::align
|
||||
Boost::asio
|
||||
Boost::bind
|
||||
Boost::exception
|
||||
Boost::interprocess
|
||||
@@ -521,6 +525,13 @@ if (NOT BOOST_LOG_NO_THREADS)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT BOOST_LOG_WITHOUT_ASIO)
|
||||
target_link_libraries(boost_log
|
||||
PRIVATE
|
||||
Boost::asio
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(boost_log
|
||||
PUBLIC
|
||||
${boost_log_common_public_defines}
|
||||
@@ -622,7 +633,6 @@ if (NOT BOOST_LOG_WITHOUT_SETTINGS_PARSERS)
|
||||
${boost_log_setup_public_deps}
|
||||
|
||||
PRIVATE
|
||||
Boost::asio
|
||||
Boost::bind
|
||||
Boost::date_time
|
||||
Boost::exception
|
||||
@@ -642,6 +652,13 @@ if (NOT BOOST_LOG_WITHOUT_SETTINGS_PARSERS)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT BOOST_LOG_WITHOUT_ASIO)
|
||||
target_link_libraries(boost_log_setup
|
||||
PRIVATE
|
||||
Boost::asio
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(boost_log_setup
|
||||
PUBLIC
|
||||
${boost_log_common_public_defines}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright Andrey Semashev 2007 - 2023.
|
||||
# Copyright Andrey Semashev 2007 - 2025.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -68,13 +68,13 @@ constant boost_log_public_deps :
|
||||
|
||||
constant boost_log_private_deps :
|
||||
<library>/boost/align//boost_align
|
||||
<library>/boost/asio//boost_asio
|
||||
<library>/boost/bind//boost_bind
|
||||
<library>/boost/exception//boost_exception
|
||||
<library>/boost/interprocess//boost_interprocess
|
||||
<library>/boost/optional//boost_optional
|
||||
<library>/boost/random//boost_random
|
||||
<library>/boost/spirit//boost_spirit
|
||||
<conditional>@log-build-config.check-asio
|
||||
[ requires
|
||||
cxx11_lambdas
|
||||
]
|
||||
@@ -100,7 +100,6 @@ constant boost_log_setup_public_deps :
|
||||
;
|
||||
|
||||
constant boost_log_setup_private_deps :
|
||||
<library>/boost/asio//boost_asio
|
||||
<library>/boost/bind//boost_bind
|
||||
<library>/boost/date_time//boost_date_time
|
||||
<library>/boost/exception//boost_exception
|
||||
@@ -110,6 +109,7 @@ constant boost_log_setup_private_deps :
|
||||
<library>/boost/spirit//boost_spirit
|
||||
<library>/boost/throw_exception//boost_throw_exception
|
||||
<library>/boost/utility//boost_utility
|
||||
<conditional>@log-build-config.check-asio
|
||||
[ requires
|
||||
cxx11_lambdas
|
||||
]
|
||||
|
||||
@@ -124,3 +124,15 @@ rule select-regex-backend ( properties * )
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
rule check-asio ( properties * )
|
||||
{
|
||||
local result ;
|
||||
|
||||
if ! [ has-config-flag BOOST_LOG_WITHOUT_ASIO : $(properties) ]
|
||||
{
|
||||
result = <library>/boost/asio//boost_asio ;
|
||||
}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
[heading 2.32, Boost 1.89]
|
||||
|
||||
* Added support for `BOOST_LOG_WITHOUT_ASIO` configuration macro, which can be used to remove the dependency on __boost_asio__ and disable the related functionality.
|
||||
* Use locale-independent formatting of the file counter in `text_file_backend` when composing log file names. This fixes failures in the subsequent parsing of the file names in `file_collector::scan_for_files`. ([pull_request 246])
|
||||
|
||||
[heading 2.31, Boost 1.88]
|
||||
|
||||
@@ -50,7 +50,7 @@ MinGW users on Windows XP may be affected by the [@http://sourceforge.net/p/ming
|
||||
|
||||
[heading Additional notes for Cygwin users]
|
||||
|
||||
Cygwin support is very preliminary. The default GCC version available in Cygwin (4.5.3 as of this writing) is unable to compile the library because of compiler errors. You will have to build a newer GCC from sources. Even then some Boost.Log functionality is not available. In particular, the socket-based syslog backend is not supported, as it is based on __boost_asio__, which doesn't compile on this platform. However, the native syslog support is still in place.
|
||||
Cygwin support is very preliminary. The default GCC version available in Cygwin (4.5.3 as of this writing) is unable to compile the library because of compiler errors. You will have to build a newer GCC from sources. Even then some Boost.Log functionality is not available. In particular, the socket-based [link log.detailed.sink_backends.syslog syslog backend] is not supported, as it is based on __boost_asio__, which doesn't compile on this platform. However, the native syslog support is still in place.
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -74,8 +74,9 @@ The library supports a number of configuration macros:
|
||||
[[`BOOST_LOG_WITHOUT_SETTINGS_PARSERS`] [Affects only compilation of the library. If defined, none of the facilities related to the parsers for settings will be built. This can substantially reduce the binary size.] [Disables compilation of the `boost_log_setup` library.]]
|
||||
[[`BOOST_LOG_WITHOUT_DEBUG_OUTPUT`] [Affects only compilation of the library. If defined, the support for debugger output on Windows will not be built.] []]
|
||||
[[`BOOST_LOG_WITHOUT_EVENT_LOG`] [Affects only compilation of the library. If defined, the support for Windows event log will not be built. Defining the macro also makes Message Compiler toolset unnecessary.] []]
|
||||
[[`BOOST_LOG_WITHOUT_SYSLOG`] [Affects only compilation of the library. If defined, the support for syslog backend will not be built.] []]
|
||||
[[`BOOST_LOG_WITHOUT_IPC`] [Affects only compilation of the library. If defined, the support for interprocess queues will not be built.] []]
|
||||
[[`BOOST_LOG_WITHOUT_SYSLOG`] [Affects only compilation of the library. If defined, the support for [link log.detailed.sink_backends.syslog syslog backend] will not be built.] []]
|
||||
[[`BOOST_LOG_WITHOUT_IPC`] [Affects only compilation of the library. If defined, the support for [link log.detailed.utilities.ipc interprocess queues] and the related [link log.detailed.sink_backends.text_ipc_message_queue backend] will not be built.] []]
|
||||
[[`BOOST_LOG_WITHOUT_ASIO`] [Affects compilation of both the library and users' code. If defined, the support for Boost.ASIO-dependent functionality will not be built. In particular, this disables socket-based [link log.detailed.sink_backends.syslog syslog backend] implementation.] []]
|
||||
[[`BOOST_LOG_NO_SHORTHAND_NAMES`] [Affects only compilation of users' code. If defined, some deprecated shorthand macro names will not be available.] [Not a CMake configuration option.]]
|
||||
[[`BOOST_LOG_USE_COMPILER_TLS`] [Affects only compilation of the library. This macro enables support for compiler intrinsics for thread-local storage. Defining it may improve performance of Boost.Log if certain usage limitations are acceptable. See below for more comments.] []]
|
||||
[[`BOOST_LOG_USE_STD_REGEX`, `BOOST_LOG_USE_BOOST_REGEX` or `BOOST_LOG_USE_BOOST_XPRESSIVE`] [Affects only compilation of the library. By defining one of these macros the user can instruct Boost.Log to use `std::regex`, __boost_regex__ or __boost_xpressive__ internally for string matching filters parsed from strings and settings. If none of these macros is defined then Boost.Log uses __boost_regex__ by default. Using `std::regex` or __boost_regex__ typically produces smaller executables, __boost_regex__ usually also being the fastest in run time. Using __boost_xpressive__ allows to eliminate the dependency on __boost_regex__ compiled binary. Note that these macros do not affect [link log.detailed.expressions.predicates.advanced_string_matching filtering expressions] created by users.] [Instead of definitng one of these macros, use `BOOST_LOG_USE_REGEX_BACKEND` string option with one of the following values: "std::regex", "Boost.Regex" or "Boost.Xpressive". The macros will be defined accordingly by CMake.]]
|
||||
|
||||
@@ -54,7 +54,7 @@ void init_native_syslog()
|
||||
//->
|
||||
|
||||
//<-
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
//->
|
||||
void init_builtin_syslog()
|
||||
{
|
||||
@@ -89,7 +89,7 @@ int main(int, char*[])
|
||||
{
|
||||
#if defined(BOOST_LOG_USE_NATIVE_SYSLOG)
|
||||
init_native_syslog();
|
||||
#elif !defined(BOOST_LOG_NO_ASIO)
|
||||
#elif !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
init_builtin_syslog();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
sink->locked_backend()->set_severity_mapper(mapping);
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
// Set the remote address to sent syslog messages to
|
||||
sink->locked_backend()->set_target_address("localhost");
|
||||
#endif
|
||||
|
||||
@@ -103,9 +103,9 @@
|
||||
# define BOOST_LOG_NO_CXX11_CODECVT_FACETS
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
#if defined(__CYGWIN__) && !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
// Boost.ASIO is broken on Cygwin
|
||||
# define BOOST_LOG_NO_ASIO
|
||||
# define BOOST_LOG_WITHOUT_ASIO
|
||||
#endif
|
||||
|
||||
#if defined(__VXWORKS__)
|
||||
@@ -121,7 +121,7 @@
|
||||
# define BOOST_LOG_NO_GETPWUID_R
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_LOG_USE_NATIVE_SYSLOG) && defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_USE_NATIVE_SYSLOG) && defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
# ifndef BOOST_LOG_WITHOUT_SYSLOG
|
||||
# define BOOST_LOG_WITHOUT_SYSLOG
|
||||
# endif
|
||||
|
||||
@@ -57,11 +57,11 @@ namespace syslog {
|
||||
{
|
||||
#ifdef BOOST_LOG_USE_NATIVE_SYSLOG
|
||||
native = 0 //!< Use native syslog API
|
||||
#ifndef BOOST_LOG_NO_ASIO
|
||||
#ifndef BOOST_LOG_WITHOUT_ASIO
|
||||
,
|
||||
#endif
|
||||
#endif
|
||||
#ifndef BOOST_LOG_NO_ASIO
|
||||
#ifndef BOOST_LOG_WITHOUT_ASIO
|
||||
udp_socket_based = 1 //!< Use UDP sockets, according to RFC3164
|
||||
#endif
|
||||
};
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
*/
|
||||
BOOST_LOG_API void set_severity_mapper(severity_mapper_type const& mapper);
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
/*!
|
||||
* The method sets the local host name which log records will be sent from. The host name
|
||||
@@ -247,7 +247,7 @@ public:
|
||||
*/
|
||||
BOOST_LOG_API void set_target_address(boost::asio::ip::address const& addr, unsigned short port = 514);
|
||||
|
||||
#endif // !defined(BOOST_LOG_NO_ASIO)
|
||||
#endif // !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
/*!
|
||||
* The method passes the formatted message to the syslog API or sends to a syslog server
|
||||
@@ -262,7 +262,7 @@ private:
|
||||
{
|
||||
construct(
|
||||
args[keywords::facility | syslog::user],
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
args[keywords::use_impl | syslog::udp_socket_based],
|
||||
#else
|
||||
args[keywords::use_impl | syslog::native],
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
#include <boost/log/utility/setup/from_settings.hpp>
|
||||
#include <boost/log/utility/setup/filter_parser.hpp>
|
||||
#include <boost/log/utility/setup/formatter_parser.hpp>
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
#include <boost/asio/ip/address.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_LOG_NO_THREADS)
|
||||
@@ -171,14 +171,14 @@ inline sinks::auto_newline_mode param_cast_to_auto_newline_mode(const char* para
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
//! Extracts a network address from parameter value
|
||||
template< typename CharT >
|
||||
inline std::string param_cast_to_address(const char* param_name, std::basic_string< CharT > const& value)
|
||||
{
|
||||
return log::aux::to_narrow(value);
|
||||
}
|
||||
#endif // !defined(BOOST_LOG_NO_ASIO)
|
||||
#endif // !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
template< typename CharT >
|
||||
inline bool is_weekday(const CharT* str, std::size_t len, boost::log::basic_string_literal< CharT > const& weekday, boost::log::basic_string_literal< CharT > const& short_weekday)
|
||||
@@ -589,14 +589,14 @@ public:
|
||||
// For now we use only the default level mapping. Will add support for configuration later.
|
||||
backend->set_severity_mapper(sinks::syslog::direct_severity_mapping< >(log::aux::default_attribute_names::severity()));
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
// Setup local and remote addresses
|
||||
if (optional< string_type > local_address_param = params["LocalAddress"])
|
||||
backend->set_local_address(param_cast_to_address("LocalAddress", local_address_param.get()));
|
||||
|
||||
if (optional< string_type > target_address_param = params["TargetAddress"])
|
||||
backend->set_target_address(param_cast_to_address("TargetAddress", target_address_param.get()));
|
||||
#endif // !defined(BOOST_LOG_NO_ASIO)
|
||||
#endif // !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
return base_type::init_sink(backend, params);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/make_shared_object.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/socket_base.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
@@ -90,7 +90,7 @@ struct syslog_backend::implementation
|
||||
#ifdef BOOST_LOG_USE_NATIVE_SYSLOG
|
||||
struct native;
|
||||
#endif // BOOST_LOG_USE_NATIVE_SYSLOG
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
struct udp_socket_based;
|
||||
#endif
|
||||
|
||||
@@ -303,7 +303,7 @@ private:
|
||||
// Socket-based implementation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
BOOST_LOG_ANONYMOUS_NAMESPACE {
|
||||
|
||||
@@ -463,7 +463,7 @@ struct syslog_backend::implementation::udp_socket_based :
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(BOOST_LOG_NO_ASIO)
|
||||
#endif // !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sink backend implementation
|
||||
@@ -506,7 +506,7 @@ BOOST_LOG_API void syslog_backend::construct(syslog::facility fac, syslog::impl_
|
||||
}
|
||||
#endif // BOOST_LOG_USE_NATIVE_SYSLOG
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
typedef implementation::udp_socket_based udp_socket_based_impl;
|
||||
asio::ip::udp protocol = asio::ip::udp::v4();
|
||||
switch (ip_version)
|
||||
@@ -524,7 +524,7 @@ BOOST_LOG_API void syslog_backend::construct(syslog::facility fac, syslog::impl_
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(BOOST_LOG_NO_ASIO)
|
||||
#if !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
//! The method sets the local address which log records will be sent from.
|
||||
BOOST_LOG_API void syslog_backend::set_local_address(std::string const& addr, unsigned short port)
|
||||
@@ -617,7 +617,7 @@ BOOST_LOG_API void syslog_backend::set_target_address(boost::asio::ip::address c
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !defined(BOOST_LOG_NO_ASIO)
|
||||
#endif // !defined(BOOST_LOG_WITHOUT_ASIO)
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user