File indexing completed on 2025-01-18 09:39:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_ATTRIBUTES_SCOPED_ATTRIBUTE_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_SCOPED_ATTRIBUTE_HPP_INCLUDED_
0017
0018 #include <cstddef>
0019 #include <utility>
0020 #include <boost/move/core.hpp>
0021 #include <boost/move/utility_core.hpp>
0022 #include <boost/core/addressof.hpp>
0023 #include <boost/log/detail/config.hpp>
0024 #include <boost/log/core/core.hpp>
0025 #include <boost/log/sources/basic_logger.hpp>
0026 #include <boost/log/attributes/attribute.hpp>
0027 #include <boost/log/attributes/attribute_set.hpp>
0028 #include <boost/log/attributes/attribute_name.hpp>
0029 #include <boost/log/attributes/constant.hpp>
0030 #include <boost/log/utility/unused_variable.hpp>
0031 #include <boost/log/utility/unique_identifier_name.hpp>
0032 #include <boost/log/detail/header.hpp>
0033
0034 #ifdef BOOST_HAS_PRAGMA_ONCE
0035 #pragma once
0036 #endif
0037
0038 namespace boost {
0039
0040 BOOST_LOG_OPEN_NAMESPACE
0041
0042 namespace aux {
0043
0044
0045 class attribute_scope_guard
0046 {
0047 };
0048
0049 }
0050
0051
0052 typedef aux::attribute_scope_guard const& scoped_attribute;
0053
0054 namespace aux {
0055
0056
0057 template< typename LoggerT >
0058 class scoped_logger_attribute :
0059 public attribute_scope_guard
0060 {
0061 BOOST_COPYABLE_AND_MOVABLE_ALT(scoped_logger_attribute)
0062
0063 private:
0064
0065 typedef LoggerT logger_type;
0066
0067 private:
0068
0069 logger_type* m_pLogger;
0070
0071 attribute_set::iterator m_itAttribute;
0072
0073 public:
0074
0075 scoped_logger_attribute(logger_type& l, attribute_name const& name, attribute const& attr) :
0076 m_pLogger(boost::addressof(l))
0077 {
0078 std::pair<
0079 attribute_set::iterator,
0080 bool
0081 > res = l.add_attribute(name, attr);
0082 if (res.second)
0083 m_itAttribute = res.first;
0084 else
0085 m_pLogger = NULL;
0086 }
0087
0088 scoped_logger_attribute(BOOST_RV_REF(scoped_logger_attribute) that) BOOST_NOEXCEPT :
0089 m_pLogger(that.m_pLogger),
0090 m_itAttribute(that.m_itAttribute)
0091 {
0092 that.m_pLogger = NULL;
0093 }
0094
0095
0096 ~scoped_logger_attribute()
0097 {
0098 if (m_pLogger)
0099 m_pLogger->remove_attribute(m_itAttribute);
0100 }
0101
0102 #ifndef BOOST_LOG_BROKEN_REFERENCE_FROM_RVALUE_INIT
0103 BOOST_DELETED_FUNCTION(scoped_logger_attribute(scoped_logger_attribute const&))
0104 #else
0105 scoped_logger_attribute(scoped_logger_attribute const& that) BOOST_NOEXCEPT : m_pLogger(that.m_pLogger), m_itAttribute(that.m_itAttribute)
0106 {
0107 const_cast< scoped_logger_attribute& >(that).m_pLogger = NULL;
0108 }
0109 #endif
0110
0111 BOOST_DELETED_FUNCTION(scoped_logger_attribute& operator= (scoped_logger_attribute const&))
0112 };
0113
0114 }
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 template< typename LoggerT >
0126 BOOST_FORCEINLINE aux::scoped_logger_attribute< LoggerT > add_scoped_logger_attribute(LoggerT& l, attribute_name const& name, attribute const& attr)
0127 {
0128 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0129 return aux::scoped_logger_attribute< LoggerT >(l, name, attr);
0130 #else
0131 aux::scoped_logger_attribute< LoggerT > guard(l, name, attr);
0132 return boost::move(guard);
0133 #endif
0134 }
0135
0136 #ifndef BOOST_LOG_DOXYGEN_PASS
0137
0138 #define BOOST_LOG_SCOPED_LOGGER_ATTR_INTERNAL(logger, attr_name, attr, sentry_var_name)\
0139 BOOST_LOG_UNUSED_VARIABLE(::boost::log::scoped_attribute, sentry_var_name,\
0140 = ::boost::log::add_scoped_logger_attribute(logger, attr_name, (attr)));
0141
0142 #endif
0143
0144
0145 #define BOOST_LOG_SCOPED_LOGGER_ATTR(logger, attr_name, attr)\
0146 BOOST_LOG_SCOPED_LOGGER_ATTR_INTERNAL(\
0147 logger,\
0148 attr_name,\
0149 attr,\
0150 BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_scoped_logger_attr_sentry_))
0151
0152
0153 #define BOOST_LOG_SCOPED_LOGGER_TAG(logger, attr_name, attr_value)\
0154 BOOST_LOG_SCOPED_LOGGER_ATTR(logger, attr_name, ::boost::log::attributes::make_constant(attr_value))
0155
0156 namespace aux {
0157
0158
0159 class scoped_thread_attribute :
0160 public attribute_scope_guard
0161 {
0162 BOOST_COPYABLE_AND_MOVABLE_ALT(scoped_thread_attribute)
0163
0164 private:
0165
0166 core_ptr m_pCore;
0167
0168 attribute_set::iterator m_itAttribute;
0169
0170 public:
0171
0172 scoped_thread_attribute(attribute_name const& name, attribute const& attr) :
0173 m_pCore(core::get())
0174 {
0175 std::pair<
0176 attribute_set::iterator,
0177 bool
0178 > res = m_pCore->add_thread_attribute(name, attr);
0179 if (res.second)
0180 m_itAttribute = res.first;
0181 else
0182 m_pCore.reset();
0183 }
0184
0185 scoped_thread_attribute(BOOST_RV_REF(scoped_thread_attribute) that) : m_itAttribute(that.m_itAttribute)
0186 {
0187 m_pCore.swap(that.m_pCore);
0188 }
0189
0190
0191 ~scoped_thread_attribute()
0192 {
0193 if (!!m_pCore)
0194 m_pCore->remove_thread_attribute(m_itAttribute);
0195 }
0196
0197 #ifndef BOOST_LOG_BROKEN_REFERENCE_FROM_RVALUE_INIT
0198 BOOST_DELETED_FUNCTION(scoped_thread_attribute(scoped_thread_attribute const&))
0199 #else
0200 scoped_thread_attribute(scoped_thread_attribute const& that) : m_itAttribute(that.m_itAttribute)
0201 {
0202 m_pCore.swap(const_cast< scoped_thread_attribute& >(that).m_pCore);
0203 }
0204 #endif
0205
0206 BOOST_DELETED_FUNCTION(scoped_thread_attribute& operator= (scoped_thread_attribute const&))
0207 };
0208
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 BOOST_FORCEINLINE aux::scoped_thread_attribute add_scoped_thread_attribute(attribute_name const& name, attribute const& attr)
0220 {
0221 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0222 return aux::scoped_thread_attribute(name, attr);
0223 #else
0224 aux::scoped_thread_attribute guard(name, attr);
0225 return boost::move(guard);
0226 #endif
0227 }
0228
0229 #ifndef BOOST_LOG_DOXYGEN_PASS
0230
0231 #define BOOST_LOG_SCOPED_THREAD_ATTR_INTERNAL(attr_name, attr, sentry_var_name)\
0232 BOOST_LOG_UNUSED_VARIABLE(::boost::log::scoped_attribute, sentry_var_name,\
0233 = ::boost::log::add_scoped_thread_attribute(attr_name, (attr)));
0234
0235 #endif
0236
0237
0238 #define BOOST_LOG_SCOPED_THREAD_ATTR(attr_name, attr)\
0239 BOOST_LOG_SCOPED_THREAD_ATTR_INTERNAL(\
0240 attr_name,\
0241 attr,\
0242 BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_scoped_thread_attr_sentry_))
0243
0244
0245 #define BOOST_LOG_SCOPED_THREAD_TAG(attr_name, attr_value)\
0246 BOOST_LOG_SCOPED_THREAD_ATTR(attr_name, ::boost::log::attributes::make_constant(attr_value))
0247
0248 BOOST_LOG_CLOSE_NAMESPACE
0249
0250 }
0251
0252 #include <boost/log/detail/footer.hpp>
0253
0254 #endif