123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- #ifndef BOOST_LOG_SINKS_TEXT_FILE_BACKEND_HPP_INCLUDED_
- #define BOOST_LOG_SINKS_TEXT_FILE_BACKEND_HPP_INCLUDED_
- #include <ios>
- #include <string>
- #include <ostream>
- #include <boost/limits.hpp>
- #include <boost/cstdint.hpp>
- #include <boost/optional/optional.hpp>
- #include <boost/smart_ptr/shared_ptr.hpp>
- #include <boost/date_time/date_defs.hpp>
- #include <boost/date_time/special_defs.hpp>
- #include <boost/date_time/gregorian/greg_day.hpp>
- #include <boost/date_time/posix_time/posix_time_types.hpp>
- #include <boost/filesystem/path.hpp>
- #include <boost/log/keywords/max_size.hpp>
- #include <boost/log/keywords/max_files.hpp>
- #include <boost/log/keywords/min_free_space.hpp>
- #include <boost/log/keywords/target.hpp>
- #include <boost/log/keywords/target_file_name.hpp>
- #include <boost/log/keywords/file_name.hpp>
- #include <boost/log/keywords/open_mode.hpp>
- #include <boost/log/keywords/auto_flush.hpp>
- #include <boost/log/keywords/rotation_size.hpp>
- #include <boost/log/keywords/time_based_rotation.hpp>
- #include <boost/log/keywords/enable_final_rotation.hpp>
- #include <boost/log/keywords/auto_newline_mode.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/light_function.hpp>
- #include <boost/log/detail/parameter_tools.hpp>
- #include <boost/log/sinks/auto_newline_mode.hpp>
- #include <boost/log/sinks/basic_sink_backend.hpp>
- #include <boost/log/sinks/frontend_requirements.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace sinks {
- namespace file {
- enum scan_method
- {
- no_scan,
- scan_matching,
- scan_all
- };
- struct scan_result
- {
-
- uintmax_t found_count;
-
- boost::optional< unsigned int > last_file_counter;
- scan_result() BOOST_NOEXCEPT :
- found_count(0u)
- {
- }
- };
- struct BOOST_LOG_NO_VTABLE collector
- {
-
- BOOST_DEFAULTED_FUNCTION(collector(), {})
-
- #if !defined(BOOST_LOG_NO_CXX11_DEFAULTED_VIRTUAL_FUNCTIONS)
- BOOST_DEFAULTED_FUNCTION(virtual ~collector(), {})
- #else
- virtual ~collector() {}
- #endif
-
- virtual void store_file(filesystem::path const& src_path) = 0;
-
- virtual bool is_in_storage(filesystem::path const& src_path) const = 0;
-
- virtual scan_result scan_for_files(scan_method method, filesystem::path const& pattern = filesystem::path()) = 0;
- BOOST_DELETED_FUNCTION(collector(collector const&))
- BOOST_DELETED_FUNCTION(collector& operator= (collector const&))
- };
- namespace aux {
-
- BOOST_LOG_API shared_ptr< collector > make_collector(
- filesystem::path const& target_dir,
- uintmax_t max_size,
- uintmax_t min_free_space,
- uintmax_t max_files = (std::numeric_limits< uintmax_t >::max)()
- );
- template< typename ArgsT >
- inline shared_ptr< collector > make_collector(ArgsT const& args)
- {
- return aux::make_collector(
- filesystem::path(args[keywords::target]),
- args[keywords::max_size | (std::numeric_limits< uintmax_t >::max)()],
- args[keywords::min_free_space | static_cast< uintmax_t >(0)],
- args[keywords::max_files | (std::numeric_limits< uintmax_t >::max)()]);
- }
- }
- #ifndef BOOST_LOG_DOXYGEN_PASS
- template< typename T1 >
- inline shared_ptr< collector > make_collector(T1 const& a1)
- {
- return aux::make_collector(a1);
- }
- template< typename T1, typename T2 >
- inline shared_ptr< collector > make_collector(T1 const& a1, T2 const& a2)
- {
- return aux::make_collector((a1, a2));
- }
- template< typename T1, typename T2, typename T3 >
- inline shared_ptr< collector > make_collector(T1 const& a1, T2 const& a2, T3 const& a3)
- {
- return aux::make_collector((a1, a2, a3));
- }
- template< typename T1, typename T2, typename T3, typename T4 >
- inline shared_ptr< collector > make_collector(T1 const& a1, T2 const& a2, T3 const& a3, T4 const& a4)
- {
- return aux::make_collector((a1, a2, a3, a4));
- }
- #else
- template< typename... ArgsT >
- shared_ptr< collector > make_collector(ArgsT... const& args);
- #endif
- class rotation_at_time_point
- {
- public:
- typedef bool result_type;
- private:
- enum day_kind
- {
- not_specified,
- weekday,
- monthday
- };
- unsigned char m_Day : 6;
- unsigned char m_DayKind : 2;
- unsigned char m_Hour, m_Minute, m_Second;
- mutable posix_time::ptime m_Previous;
- public:
-
- BOOST_LOG_API explicit rotation_at_time_point(unsigned char hour, unsigned char minute, unsigned char second);
-
- BOOST_LOG_API explicit rotation_at_time_point(
- date_time::weekdays wday,
- unsigned char hour = 0,
- unsigned char minute = 0,
- unsigned char second = 0);
-
- BOOST_LOG_API explicit rotation_at_time_point(
- gregorian::greg_day mday,
- unsigned char hour = 0,
- unsigned char minute = 0,
- unsigned char second = 0);
-
- BOOST_LOG_API bool operator() () const;
- };
- class rotation_at_time_interval
- {
- public:
- typedef bool result_type;
- private:
- posix_time::time_duration m_Interval;
- mutable posix_time::ptime m_Previous;
- public:
-
- explicit rotation_at_time_interval(posix_time::time_duration const& interval) :
- m_Interval(interval)
- {
- BOOST_ASSERT(!interval.is_special());
- BOOST_ASSERT(interval.total_seconds() > 0);
- }
-
- BOOST_LOG_API bool operator() () const;
- };
- }
- class text_file_backend :
- public basic_formatted_sink_backend<
- char,
- combine_requirements< synchronized_feeding, flushing >::type
- >
- {
-
- typedef basic_formatted_sink_backend<
- char,
- combine_requirements< synchronized_feeding, flushing >::type
- > base_type;
- public:
-
- typedef base_type::char_type char_type;
-
- typedef base_type::string_type string_type;
-
- typedef std::basic_ostream< char_type > stream_type;
-
- typedef boost::log::aux::light_function< void (stream_type&) > open_handler_type;
-
- typedef boost::log::aux::light_function< void (stream_type&) > close_handler_type;
-
- typedef boost::log::aux::light_function< bool () > time_based_rotation_predicate;
- private:
-
- struct implementation;
- implementation* m_pImpl;
-
- public:
-
- BOOST_LOG_API text_file_backend();
-
- #ifndef BOOST_LOG_DOXYGEN_PASS
- BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(text_file_backend, construct)
- #else
- template< typename... ArgsT >
- explicit text_file_backend(ArgsT... const& args);
- #endif
-
- BOOST_LOG_API ~text_file_backend();
-
- template< typename PathT >
- void set_file_name_pattern(PathT const& pattern)
- {
- set_file_name_pattern_internal(filesystem::path(pattern));
- }
-
- template< typename PathT >
- void set_target_file_name_pattern(PathT const& pattern)
- {
- set_target_file_name_pattern_internal(filesystem::path(pattern));
- }
-
- BOOST_LOG_API void set_open_mode(std::ios_base::openmode mode);
-
- BOOST_LOG_API void set_file_collector(shared_ptr< file::collector > const& collector);
-
- BOOST_LOG_API void set_open_handler(open_handler_type const& handler);
-
- BOOST_LOG_API void set_close_handler(close_handler_type const& handler);
-
- BOOST_LOG_API void set_rotation_size(uintmax_t size);
-
- BOOST_LOG_API void set_time_based_rotation(time_based_rotation_predicate const& predicate);
-
- BOOST_LOG_API void enable_final_rotation(bool enable);
-
- BOOST_LOG_API void auto_flush(bool enable = true);
-
- BOOST_LOG_API void set_auto_newline_mode(auto_newline_mode mode);
-
- BOOST_LOG_API filesystem::path get_current_file_name() const;
-
- BOOST_LOG_API uintmax_t scan_for_files(
- file::scan_method method = file::scan_matching, bool update_counter = true);
-
- BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
-
- BOOST_LOG_API void flush();
-
- BOOST_LOG_API void rotate_file();
- private:
- #ifndef BOOST_LOG_DOXYGEN_PASS
-
- template< typename ArgsT >
- void construct(ArgsT const& args)
- {
- construct(
- filesystem::path(args[keywords::file_name | filesystem::path()]),
- filesystem::path(args[keywords::target_file_name | filesystem::path()]),
- args[keywords::open_mode | (std::ios_base::trunc | std::ios_base::out)],
- args[keywords::rotation_size | (std::numeric_limits< uintmax_t >::max)()],
- args[keywords::time_based_rotation | time_based_rotation_predicate()],
- args[keywords::auto_newline_mode | insert_if_missing],
- args[keywords::auto_flush | false],
- args[keywords::enable_final_rotation | true]);
- }
-
- BOOST_LOG_API void construct(
- filesystem::path const& pattern,
- filesystem::path const& target_file_name,
- std::ios_base::openmode mode,
- uintmax_t rotation_size,
- time_based_rotation_predicate const& time_based_rotation,
- auto_newline_mode auto_newline,
- bool auto_flush,
- bool enable_final_rotation);
-
- BOOST_LOG_API void set_file_name_pattern_internal(filesystem::path const& pattern);
-
- BOOST_LOG_API void set_target_file_name_pattern_internal(filesystem::path const& pattern);
-
- void close_file();
- #endif
- };
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|