123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
- #ifndef BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_
- #define BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_
- #include <exception>
- #include <utility>
- #include <ostream>
- #include <boost/assert.hpp>
- #include <boost/move/core.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/core/addressof.hpp>
- #include <boost/type_traits/is_nothrow_swappable.hpp>
- #include <boost/type_traits/is_nothrow_move_constructible.hpp>
- #include <boost/preprocessor/facilities/empty.hpp>
- #include <boost/preprocessor/facilities/identity.hpp>
- #include <boost/preprocessor/seq/enum.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/parameter_tools.hpp>
- #include <boost/log/attributes/attribute_set.hpp>
- #include <boost/log/attributes/attribute_name.hpp>
- #include <boost/log/attributes/attribute.hpp>
- #include <boost/log/core/core.hpp>
- #include <boost/log/core/record.hpp>
- #include <boost/log/sources/features.hpp>
- #include <boost/log/sources/threading_models.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace sources {
- template< typename CharT, typename FinalT, typename ThreadingModelT >
- class basic_logger :
- public ThreadingModelT
- {
- typedef basic_logger this_type;
- BOOST_COPYABLE_AND_MOVABLE_ALT(this_type)
- public:
-
- typedef CharT char_type;
-
- typedef FinalT final_type;
-
- typedef ThreadingModelT threading_model;
- #if !defined(BOOST_LOG_NO_THREADS)
-
- typedef boost::log::aux::multiple_unique_lock2< threading_model, threading_model > swap_lock;
-
- typedef boost::log::aux::exclusive_lock_guard< threading_model > add_attribute_lock;
-
- typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_attribute_lock;
-
- typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_all_attributes_lock;
-
- typedef boost::log::aux::shared_lock_guard< const threading_model > get_attributes_lock;
-
- typedef boost::log::aux::shared_lock_guard< threading_model > open_record_lock;
-
- typedef boost::log::aux::exclusive_lock_guard< threading_model > set_attributes_lock;
- #else
- typedef no_lock< threading_model > swap_lock;
- typedef no_lock< threading_model > add_attribute_lock;
- typedef no_lock< threading_model > remove_attribute_lock;
- typedef no_lock< threading_model > remove_all_attributes_lock;
- typedef no_lock< const threading_model > get_attributes_lock;
- typedef no_lock< threading_model > open_record_lock;
- typedef no_lock< threading_model > set_attributes_lock;
- #endif
-
- typedef no_lock< threading_model > push_record_lock;
- private:
-
- core_ptr m_pCore;
-
- attribute_set m_Attributes;
- public:
-
- basic_logger() :
- threading_model(),
- m_pCore(core::get())
- {
- }
-
- basic_logger(basic_logger const& that) :
- threading_model(static_cast< threading_model const& >(that)),
- m_pCore(that.m_pCore),
- m_Attributes(that.m_Attributes)
- {
- }
-
- basic_logger(BOOST_RV_REF(basic_logger) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< threading_model >::value &&
- boost::is_nothrow_move_constructible< core_ptr >::value &&
- boost::is_nothrow_move_constructible< attribute_set >::value) :
- threading_model(boost::move(static_cast< threading_model& >(that))),
- m_pCore(boost::move(that.m_pCore)),
- m_Attributes(boost::move(that.m_Attributes))
- {
- }
-
- template< typename ArgsT >
- explicit basic_logger(ArgsT const&) :
- threading_model(),
- m_pCore(core::get())
- {
- }
- protected:
-
- core_ptr const& core() const { return m_pCore; }
-
- attribute_set& attributes() { return m_Attributes; }
-
- attribute_set const& attributes() const { return m_Attributes; }
-
- threading_model& get_threading_model() BOOST_NOEXCEPT { return *this; }
-
- threading_model const& get_threading_model() const BOOST_NOEXCEPT { return *this; }
-
- final_type* final_this() BOOST_NOEXCEPT
- {
- BOOST_LOG_ASSUME(this != NULL);
- return static_cast< final_type* >(this);
- }
-
- final_type const* final_this() const BOOST_NOEXCEPT
- {
- BOOST_LOG_ASSUME(this != NULL);
- return static_cast< final_type const* >(this);
- }
-
- void swap_unlocked(basic_logger& that)
- {
- get_threading_model().swap(that.get_threading_model());
- m_Attributes.swap(that.m_Attributes);
- }
-
- std::pair< attribute_set::iterator, bool > add_attribute_unlocked(attribute_name const& name, attribute const& attr)
- {
- return m_Attributes.insert(name, attr);
- }
-
- void remove_attribute_unlocked(attribute_set::iterator it)
- {
- m_Attributes.erase(it);
- }
-
- void remove_all_attributes_unlocked()
- {
- m_Attributes.clear();
- }
-
- record open_record_unlocked()
- {
- return m_pCore->open_record(m_Attributes);
- }
-
- template< typename ArgsT >
- record open_record_unlocked(ArgsT const&)
- {
- return m_pCore->open_record(m_Attributes);
- }
-
- void push_record_unlocked(BOOST_RV_REF(record) rec)
- {
- m_pCore->push_record(boost::move(rec));
- }
-
- attribute_set get_attributes_unlocked() const
- {
- return m_Attributes;
- }
-
- void set_attributes_unlocked(attribute_set const& attrs)
- {
- m_Attributes = attrs;
- }
-
- BOOST_DELETED_FUNCTION(basic_logger& operator= (basic_logger const&))
- };
- template< typename CharT, typename FinalT, typename ThreadingModelT >
- inline void swap(
- basic_logger< CharT, FinalT, ThreadingModelT >& left,
- basic_logger< CharT, FinalT, ThreadingModelT >& right) BOOST_NOEXCEPT_IF(boost::is_nothrow_swappable< FinalT >::value)
- {
- static_cast< FinalT& >(left).swap(static_cast< FinalT& >(right));
- }
- template< typename CharT, typename FinalT, typename ThreadingModelT, typename FeaturesT >
- class basic_composite_logger :
- public boost::log::sources::aux::inherit_features<
- basic_logger< CharT, FinalT, ThreadingModelT >,
- FeaturesT
- >::type
- {
- private:
-
- typedef typename boost::log::sources::aux::inherit_features<
- basic_logger< CharT, FinalT, ThreadingModelT >,
- FeaturesT
- >::type base_type;
- protected:
-
- typedef basic_composite_logger logger_base;
- BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base)
- public:
-
- typedef typename base_type::threading_model threading_model;
-
- typedef typename base_type::swap_lock swap_lock;
- #if !defined(BOOST_LOG_NO_THREADS)
- public:
-
- basic_composite_logger() {}
-
- basic_composite_logger(basic_composite_logger const& that) :
- base_type
- ((
- boost::log::aux::shared_lock_guard< const threading_model >(that.get_threading_model()),
- static_cast< base_type const& >(that)
- ))
- {
- }
-
- basic_composite_logger(BOOST_RV_REF(logger_base) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< base_type >::value) :
- base_type(boost::move(static_cast< base_type& >(that)))
- {
- }
-
- template< typename ArgsT >
- explicit basic_composite_logger(ArgsT const& args) : base_type(args)
- {
- }
-
- std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr)
- {
- typename base_type::add_attribute_lock lock(base_type::get_threading_model());
- return base_type::add_attribute_unlocked(name, attr);
- }
-
- void remove_attribute(attribute_set::iterator it)
- {
- typename base_type::remove_attribute_lock lock(base_type::get_threading_model());
- base_type::remove_attribute_unlocked(it);
- }
-
- void remove_all_attributes()
- {
- typename base_type::remove_all_attributes_lock lock(base_type::get_threading_model());
- base_type::remove_all_attributes_unlocked();
- }
-
- attribute_set get_attributes() const
- {
- typename base_type::get_attributes_lock lock(base_type::get_threading_model());
- return base_type::get_attributes_unlocked();
- }
-
- void set_attributes(attribute_set const& attrs)
- {
- typename base_type::set_attributes_lock lock(base_type::get_threading_model());
- base_type::set_attributes_unlocked(attrs);
- }
-
- record open_record()
- {
-
- if (this->core()->get_logging_enabled())
- {
- typename base_type::open_record_lock lock(base_type::get_threading_model());
- return base_type::open_record_unlocked(boost::log::aux::empty_arg_list());
- }
- else
- return record();
- }
-
- template< typename ArgsT >
- record open_record(ArgsT const& args)
- {
-
- if (this->core()->get_logging_enabled())
- {
- typename base_type::open_record_lock lock(base_type::get_threading_model());
- return base_type::open_record_unlocked(args);
- }
- else
- return record();
- }
-
- void push_record(BOOST_RV_REF(record) rec)
- {
- typename base_type::push_record_lock lock(base_type::get_threading_model());
- base_type::push_record_unlocked(boost::move(rec));
- }
-
- void swap(basic_composite_logger& that)
- {
- swap_lock lock(base_type::get_threading_model(), that.get_threading_model());
- base_type::swap_unlocked(static_cast< base_type& >(that));
- }
- protected:
-
- FinalT& assign(FinalT const& that)
- {
- BOOST_LOG_ASSUME(this != NULL);
- if (static_cast< FinalT* >(this) != boost::addressof(that))
- {
-
- FinalT tmp(that);
- boost::log::aux::exclusive_lock_guard< threading_model > lock(base_type::get_threading_model());
- base_type::swap_unlocked(tmp);
- }
- return static_cast< FinalT& >(*this);
- }
- };
- template< typename CharT, typename FinalT, typename FeaturesT >
- class basic_composite_logger< CharT, FinalT, single_thread_model, FeaturesT > :
- public boost::log::sources::aux::inherit_features<
- basic_logger< CharT, FinalT, single_thread_model >,
- FeaturesT
- >::type
- {
- private:
- typedef typename boost::log::sources::aux::inherit_features<
- basic_logger< CharT, FinalT, single_thread_model >,
- FeaturesT
- >::type base_type;
- protected:
- typedef basic_composite_logger logger_base;
- BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base)
- public:
- typedef typename base_type::threading_model threading_model;
- #endif
- public:
- basic_composite_logger() {}
- basic_composite_logger(basic_composite_logger const& that) :
- base_type(static_cast< base_type const& >(that))
- {
- }
- basic_composite_logger(BOOST_RV_REF(logger_base) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< base_type >::value) :
- base_type(boost::move(static_cast< base_type& >(that)))
- {
- }
- template< typename ArgsT >
- explicit basic_composite_logger(ArgsT const& args) : base_type(args)
- {
- }
- std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr)
- {
- return base_type::add_attribute_unlocked(name, attr);
- }
- void remove_attribute(attribute_set::iterator it)
- {
- base_type::remove_attribute_unlocked(it);
- }
- void remove_all_attributes()
- {
- base_type::remove_all_attributes_unlocked();
- }
- attribute_set get_attributes() const
- {
- return base_type::get_attributes_unlocked();
- }
- void set_attributes(attribute_set const& attrs)
- {
- base_type::set_attributes_unlocked(attrs);
- }
- record open_record()
- {
-
- if (this->core()->get_logging_enabled())
- return base_type::open_record_unlocked(boost::log::aux::empty_arg_list());
- else
- return record();
- }
- template< typename ArgsT >
- record open_record(ArgsT const& args)
- {
-
- if (this->core()->get_logging_enabled())
- return base_type::open_record_unlocked(args);
- else
- return record();
- }
- void push_record(BOOST_RV_REF(record) rec)
- {
- base_type::push_record_unlocked(boost::move(rec));
- }
- void swap(basic_composite_logger& that)
- {
- base_type::swap_unlocked(static_cast< base_type& >(that));
- }
- protected:
- FinalT& assign(FinalT that)
- {
- base_type::swap_unlocked(that);
- return static_cast< FinalT& >(*this);
- }
- };
- #ifndef BOOST_LOG_DOXYGEN_PASS
- #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, typename_keyword)\
- public:\
- BOOST_DEFAULTED_FUNCTION(class_type(), {})\
- class_type(class_type const& that) : class_type::logger_base(\
- static_cast< typename_keyword() class_type::logger_base const& >(that)) {}\
- class_type(BOOST_RV_REF(class_type) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< typename_keyword() class_type::logger_base >::value) : class_type::logger_base(\
- ::boost::move(static_cast< typename_keyword() class_type::logger_base& >(that))) {}\
- BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, class_type::logger_base)\
- #endif
- #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\
- BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_EMPTY)
- #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\
- BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_IDENTITY(typename))
- #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type)\
- public:\
- class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\
- {\
- return class_type::logger_base::assign(static_cast< class_type const& >(that));\
- }\
- class_type& operator= (BOOST_RV_REF(class_type) that)\
- {\
- BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< class_type::threading_model > lock(this->get_threading_model());)\
- this->swap_unlocked(that);\
- return *this;\
- }
- #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type)\
- public:\
- class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\
- {\
- return class_type::logger_base::assign(static_cast< class_type const& >(that));\
- }\
- class_type& operator= (BOOST_RV_REF(class_type) that)\
- {\
- BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< typename class_type::threading_model > lock(this->get_threading_model());)\
- this->swap_unlocked(that);\
- return *this;\
- }
- #define BOOST_LOG_FORWARD_LOGGER_MEMBERS(class_type)\
- BOOST_COPYABLE_AND_MOVABLE(class_type)\
- BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\
- BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type)
- #define BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(class_type)\
- BOOST_COPYABLE_AND_MOVABLE(class_type)\
- BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\
- BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type)
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #define BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char_type, base_seq, threading)\
- class type_name :\
- public ::boost::log::sources::basic_composite_logger<\
- char_type,\
- type_name,\
- threading,\
- ::boost::log::sources::features< BOOST_PP_SEQ_ENUM(base_seq) >\
- >\
- {\
- BOOST_LOG_FORWARD_LOGGER_MEMBERS(type_name)\
- }
- #ifdef BOOST_LOG_USE_CHAR
- #define BOOST_LOG_DECLARE_LOGGER(type_name, base_seq)\
- BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, ::boost::log::sources::single_thread_model)
- #if !defined(BOOST_LOG_NO_THREADS)
- #define BOOST_LOG_DECLARE_LOGGER_MT(type_name, base_seq)\
- BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq,\
- ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >)
- #endif
- #endif
- #ifdef BOOST_LOG_USE_WCHAR_T
- #define BOOST_LOG_DECLARE_WLOGGER(type_name, base_seq)\
- BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, ::boost::log::sources::single_thread_model)
- #if !defined(BOOST_LOG_NO_THREADS)
- #define BOOST_LOG_DECLARE_WLOGGER_MT(type_name, base_seq)\
- BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq,\
- ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >)
- #endif
- #endif
- #include <boost/log/detail/footer.hpp>
- #endif
|