annotate DEPENDENCIES/generic/include/boost/log/utility/setup/file.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*
Chris@101 2 * Copyright Andrey Semashev 2007 - 2015.
Chris@16 3 * Distributed under the Boost Software License, Version 1.0.
Chris@16 4 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 */
Chris@16 7 /*!
Chris@16 8 * \file file.hpp
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 16.05.2008
Chris@16 11 *
Chris@16 12 * The header contains implementation of convenience functions for enabling logging to a file.
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_LOG_UTILITY_SETUP_FILE_HPP_INCLUDED_
Chris@16 16 #define BOOST_LOG_UTILITY_SETUP_FILE_HPP_INCLUDED_
Chris@16 17
Chris@16 18 #include <boost/smart_ptr/shared_ptr.hpp>
Chris@16 19 #include <boost/smart_ptr/make_shared_object.hpp>
Chris@16 20 #include <boost/parameter/parameters.hpp> // for is_named_argument
Chris@16 21 #include <boost/preprocessor/comparison/greater.hpp>
Chris@16 22 #include <boost/preprocessor/punctuation/comma_if.hpp>
Chris@16 23 #include <boost/preprocessor/repetition/enum_params.hpp>
Chris@16 24 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
Chris@16 25 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
Chris@16 26 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
Chris@16 27 #include <boost/log/detail/config.hpp>
Chris@16 28 #include <boost/log/detail/sink_init_helpers.hpp>
Chris@16 29 #include <boost/log/detail/parameter_tools.hpp>
Chris@16 30 #include <boost/log/core/core.hpp>
Chris@16 31 #ifndef BOOST_LOG_NO_THREADS
Chris@16 32 #include <boost/log/sinks/sync_frontend.hpp>
Chris@16 33 #else
Chris@16 34 #include <boost/log/sinks/unlocked_frontend.hpp>
Chris@16 35 #endif
Chris@16 36 #include <boost/log/sinks/text_file_backend.hpp>
Chris@16 37 #include <boost/log/keywords/scan_method.hpp>
Chris@16 38 #include <boost/log/detail/header.hpp>
Chris@16 39
Chris@16 40 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 41 #pragma once
Chris@16 42 #endif
Chris@16 43
Chris@16 44 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 45 #ifndef BOOST_LOG_NO_THREADS
Chris@16 46 #define BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL sinks::synchronous_sink
Chris@16 47 #else
Chris@16 48 #define BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL sinks::unlocked_sink
Chris@16 49 #endif
Chris@16 50 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 51
Chris@16 52 namespace boost {
Chris@16 53
Chris@16 54 BOOST_LOG_OPEN_NAMESPACE
Chris@16 55
Chris@16 56 namespace aux {
Chris@16 57
Chris@16 58 //! The function creates a file collector according to the specified arguments
Chris@16 59 template< typename ArgsT >
Chris@16 60 inline shared_ptr< sinks::file::collector > setup_file_collector(ArgsT const&, mpl::true_ const&)
Chris@16 61 {
Chris@16 62 return shared_ptr< sinks::file::collector >();
Chris@16 63 }
Chris@16 64 template< typename ArgsT >
Chris@16 65 inline shared_ptr< sinks::file::collector > setup_file_collector(ArgsT const& args, mpl::false_ const&)
Chris@16 66 {
Chris@16 67 return sinks::file::make_collector(args);
Chris@16 68 }
Chris@16 69
Chris@16 70 //! The function constructs the sink and adds it to the core
Chris@16 71 template< typename ArgsT >
Chris@16 72 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(ArgsT const& args)
Chris@16 73 {
Chris@16 74 typedef sinks::text_file_backend backend_t;
Chris@16 75 shared_ptr< backend_t > pBackend = boost::make_shared< backend_t >(args);
Chris@16 76
Chris@16 77 shared_ptr< sinks::file::collector > pCollector = aux::setup_file_collector(args,
Chris@16 78 typename is_void< typename parameter::binding< ArgsT, keywords::tag::target, void >::type >::type());
Chris@16 79 if (pCollector)
Chris@16 80 {
Chris@16 81 pBackend->set_file_collector(pCollector);
Chris@16 82 pBackend->scan_for_files(args[keywords::scan_method | sinks::file::scan_matching]);
Chris@16 83 }
Chris@16 84
Chris@16 85 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< backend_t > > pSink =
Chris@16 86 boost::make_shared< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< backend_t > >(pBackend);
Chris@16 87
Chris@16 88 aux::setup_filter(*pSink, args,
Chris@16 89 typename is_void< typename parameter::binding< ArgsT, keywords::tag::filter, void >::type >::type());
Chris@16 90
Chris@16 91 aux::setup_formatter(*pSink, args,
Chris@16 92 typename is_void< typename parameter::binding< ArgsT, keywords::tag::format, void >::type >::type());
Chris@16 93
Chris@16 94 core::get()->add_sink(pSink);
Chris@16 95
Chris@16 96 return pSink;
Chris@16 97 }
Chris@16 98
Chris@16 99 //! The function wraps the argument into a file_name named argument, if needed
Chris@16 100 template< typename T >
Chris@16 101 inline T const& wrap_file_name(T const& arg, mpl::true_)
Chris@16 102 {
Chris@16 103 return arg;
Chris@16 104 }
Chris@16 105 template< typename T >
Chris@16 106 inline typename parameter::aux::tag< keywords::tag::file_name, T const >::type
Chris@16 107 wrap_file_name(T const& arg, mpl::false_)
Chris@16 108 {
Chris@16 109 return keywords::file_name = arg;
Chris@16 110 }
Chris@16 111
Chris@16 112 } // namespace aux
Chris@16 113
Chris@16 114 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 115
Chris@16 116 #define BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL(z, n, data)\
Chris@16 117 template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
Chris@16 118 inline shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg))\
Chris@16 119 {\
Chris@16 120 return aux::add_file_log((\
Chris@16 121 aux::wrap_file_name(arg0, typename parameter::aux::is_named_argument< T0 >::type())\
Chris@16 122 BOOST_PP_COMMA_IF(BOOST_PP_GREATER(n, 1))\
Chris@16 123 BOOST_PP_ENUM_SHIFTED_PARAMS(n, arg)\
Chris@16 124 ));\
Chris@16 125 }
Chris@16 126
Chris@16 127 BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_MAX_PARAMETER_ARGS, BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL, ~)
Chris@16 128
Chris@16 129 #undef BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL
Chris@16 130
Chris@16 131 #else // BOOST_LOG_DOXYGEN_PASS
Chris@16 132
Chris@16 133 /*!
Chris@16 134 * The function initializes the logging library to write logs to a file stream.
Chris@16 135 *
Chris@16 136 * \param args A number of named arguments. The following parameters are supported:
Chris@16 137 * \li \c file_name The file name or its pattern. This parameter is mandatory.
Chris@16 138 * \li \c open_mode The mask that describes the open mode for the file. See <tt>std::ios_base::openmode</tt>.
Chris@16 139 * \li \c rotation_size The size of the file at which rotation should occur. See <tt>basic_text_file_backend</tt>.
Chris@16 140 * \li \c time_based_rotation The predicate for time-based file rotations. See <tt>basic_text_file_backend</tt>.
Chris@16 141 * \li \c auto_flush A boolean flag that shows whether the sink should automatically flush the file
Chris@16 142 * after each written record.
Chris@16 143 * \li \c target The target directory to store rotated files in. See <tt>sinks::file::make_collector</tt>.
Chris@16 144 * \li \c max_size The maximum total size of rotated files in the target directory. See <tt>sinks::file::make_collector</tt>.
Chris@16 145 * \li \c min_free_space Minimum free space in the target directory. See <tt>sinks::file::make_collector</tt>.
Chris@16 146 * \li \c scan_method The method of scanning the target directory for log files. See <tt>sinks::file::scan_method</tt>.
Chris@16 147 * \li \c filter Specifies a filter to install into the sink. May be a string that represents a filter,
Chris@16 148 * or a filter lambda expression.
Chris@16 149 * \li \c format Specifies a formatter to install into the sink. May be a string that represents a formatter,
Chris@16 150 * or a formatter lambda expression (either streaming or Boost.Format-like notation).
Chris@16 151 * \return Pointer to the constructed sink.
Chris@16 152 */
Chris@16 153 template< typename... ArgsT >
Chris@16 154 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(ArgsT... const& args);
Chris@16 155
Chris@16 156 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 157
Chris@16 158 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 159
Chris@16 160 } // namespace boost
Chris@16 161
Chris@16 162 #undef BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL
Chris@16 163
Chris@16 164 #include <boost/log/detail/footer.hpp>
Chris@16 165
Chris@16 166 #endif // BOOST_LOG_UTILITY_SETUP_FILE_HPP_INCLUDED_