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 text_file_backend.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 09.06.2009
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a text file sink backend.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_SINKS_TEXT_FILE_BACKEND_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_SINKS_TEXT_FILE_BACKEND_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <ios>
|
Chris@16
|
19 #include <string>
|
Chris@16
|
20 #include <ostream>
|
Chris@16
|
21 #include <boost/limits.hpp>
|
Chris@16
|
22 #include <boost/cstdint.hpp>
|
Chris@16
|
23 #include <boost/smart_ptr/shared_ptr.hpp>
|
Chris@16
|
24 #include <boost/date_time/date_defs.hpp>
|
Chris@16
|
25 #include <boost/date_time/special_defs.hpp>
|
Chris@16
|
26 #include <boost/date_time/gregorian/greg_day.hpp>
|
Chris@16
|
27 #include <boost/date_time/posix_time/posix_time_types.hpp>
|
Chris@16
|
28 #include <boost/filesystem/path.hpp>
|
Chris@16
|
29 #include <boost/log/keywords/max_size.hpp>
|
Chris@16
|
30 #include <boost/log/keywords/min_free_space.hpp>
|
Chris@16
|
31 #include <boost/log/keywords/target.hpp>
|
Chris@16
|
32 #include <boost/log/keywords/file_name.hpp>
|
Chris@16
|
33 #include <boost/log/keywords/open_mode.hpp>
|
Chris@16
|
34 #include <boost/log/keywords/auto_flush.hpp>
|
Chris@16
|
35 #include <boost/log/keywords/rotation_size.hpp>
|
Chris@16
|
36 #include <boost/log/keywords/time_based_rotation.hpp>
|
Chris@16
|
37 #include <boost/log/detail/config.hpp>
|
Chris@16
|
38 #include <boost/log/detail/light_function.hpp>
|
Chris@16
|
39 #include <boost/log/detail/parameter_tools.hpp>
|
Chris@16
|
40 #include <boost/log/sinks/basic_sink_backend.hpp>
|
Chris@16
|
41 #include <boost/log/sinks/frontend_requirements.hpp>
|
Chris@16
|
42 #include <boost/log/detail/header.hpp>
|
Chris@16
|
43
|
Chris@16
|
44 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
45 #pragma once
|
Chris@16
|
46 #endif
|
Chris@16
|
47
|
Chris@16
|
48 namespace boost {
|
Chris@16
|
49
|
Chris@16
|
50 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
51
|
Chris@16
|
52 namespace sinks {
|
Chris@16
|
53
|
Chris@16
|
54 namespace file {
|
Chris@16
|
55
|
Chris@16
|
56 //! The enumeration of the stored files scan methods
|
Chris@16
|
57 enum scan_method
|
Chris@16
|
58 {
|
Chris@16
|
59 no_scan, //!< Don't scan for stored files
|
Chris@16
|
60 scan_matching, //!< Scan for files with names matching the specified mask
|
Chris@16
|
61 scan_all //!< Scan for all files in the directory
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 /*!
|
Chris@16
|
65 * \brief Base class for file collectors
|
Chris@16
|
66 *
|
Chris@16
|
67 * All file collectors, supported by file sink backends, should inherit this class.
|
Chris@16
|
68 */
|
Chris@16
|
69 struct BOOST_LOG_NO_VTABLE collector
|
Chris@16
|
70 {
|
Chris@16
|
71 /*!
|
Chris@16
|
72 * Default constructor
|
Chris@16
|
73 */
|
Chris@16
|
74 BOOST_DEFAULTED_FUNCTION(collector(), {})
|
Chris@16
|
75
|
Chris@16
|
76 /*!
|
Chris@16
|
77 * Virtual destructor
|
Chris@16
|
78 */
|
Chris@16
|
79 virtual ~collector() {}
|
Chris@16
|
80
|
Chris@16
|
81 /*!
|
Chris@16
|
82 * The function stores the specified file in the storage. May lead to an older file
|
Chris@16
|
83 * deletion and a long file moving.
|
Chris@16
|
84 *
|
Chris@16
|
85 * \param src_path The name of the file to be stored
|
Chris@16
|
86 */
|
Chris@16
|
87 virtual void store_file(filesystem::path const& src_path) = 0;
|
Chris@16
|
88
|
Chris@16
|
89 /*!
|
Chris@16
|
90 * Scans the target directory for the files that have already been stored. The found
|
Chris@16
|
91 * files are added to the collector in order to be tracked and erased, if needed.
|
Chris@16
|
92 *
|
Chris@16
|
93 * The function may scan the directory in two ways: it will either consider every
|
Chris@16
|
94 * file in the directory a log file, or will only consider files with names that
|
Chris@16
|
95 * match the specified pattern. The pattern may contain the following placeholders:
|
Chris@16
|
96 *
|
Chris@16
|
97 * \li %y, %Y, %m, %d - date components, in Boost.DateTime meaning.
|
Chris@16
|
98 * \li %H, %M, %S, %f - time components, in Boost.DateTime meaning.
|
Chris@16
|
99 * \li %N - numeric file counter. May also contain width specification
|
Chris@16
|
100 * in printf-compatible form (e.g. %5N). The resulting number will always be zero-filled.
|
Chris@16
|
101 * \li %% - a percent sign
|
Chris@16
|
102 *
|
Chris@16
|
103 * All other placeholders are not supported.
|
Chris@16
|
104 *
|
Chris@16
|
105 * \param method The method of scanning. If \c no_scan is specified, the call has no effect.
|
Chris@16
|
106 * \param pattern The file name pattern if \a method is \c scan_matching. Otherwise the parameter
|
Chris@16
|
107 * is not used.
|
Chris@16
|
108 * \param counter If not \c NULL and \a method is \c scan_matching, the method suggests initial value
|
Chris@16
|
109 * of a file counter that may be used in the file name pattern. The parameter
|
Chris@16
|
110 * is not used otherwise.
|
Chris@16
|
111 * \return The number of found files.
|
Chris@16
|
112 *
|
Chris@16
|
113 * \note In case if \a method is \c scan_matching the effect of this function is highly dependent
|
Chris@16
|
114 * on the \a pattern definition. It is recommended to choose patterns with easily
|
Chris@16
|
115 * distinguished placeholders (i.e. having delimiters between them). Otherwise
|
Chris@16
|
116 * either some files can be mistakenly found or not found, which in turn may lead
|
Chris@16
|
117 * to an incorrect file deletion.
|
Chris@16
|
118 */
|
Chris@16
|
119 virtual uintmax_t scan_for_files(
|
Chris@16
|
120 scan_method method, filesystem::path const& pattern = filesystem::path(), unsigned int* counter = 0) = 0;
|
Chris@16
|
121
|
Chris@16
|
122 BOOST_DELETED_FUNCTION(collector(collector const&))
|
Chris@16
|
123 BOOST_DELETED_FUNCTION(collector& operator= (collector const&))
|
Chris@16
|
124 };
|
Chris@16
|
125
|
Chris@16
|
126 namespace aux {
|
Chris@16
|
127
|
Chris@16
|
128 //! Creates and returns a file collector with the specified parameters
|
Chris@16
|
129 BOOST_LOG_API shared_ptr< collector > make_collector(
|
Chris@16
|
130 filesystem::path const& target_dir,
|
Chris@16
|
131 uintmax_t max_size,
|
Chris@16
|
132 uintmax_t min_free_space
|
Chris@16
|
133 );
|
Chris@16
|
134 template< typename ArgsT >
|
Chris@16
|
135 inline shared_ptr< collector > make_collector(ArgsT const& args)
|
Chris@16
|
136 {
|
Chris@16
|
137 return aux::make_collector(
|
Chris@16
|
138 filesystem::path(args[keywords::target]),
|
Chris@16
|
139 args[keywords::max_size | (std::numeric_limits< uintmax_t >::max)()],
|
Chris@16
|
140 args[keywords::min_free_space | static_cast< uintmax_t >(0)]);
|
Chris@16
|
141 }
|
Chris@16
|
142
|
Chris@16
|
143 } // namespace aux
|
Chris@16
|
144
|
Chris@16
|
145 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
146
|
Chris@16
|
147 template< typename T1 >
|
Chris@16
|
148 inline shared_ptr< collector > make_collector(T1 const& a1)
|
Chris@16
|
149 {
|
Chris@16
|
150 return aux::make_collector(a1);
|
Chris@16
|
151 }
|
Chris@16
|
152 template< typename T1, typename T2 >
|
Chris@16
|
153 inline shared_ptr< collector > make_collector(T1 const& a1, T2 const& a2)
|
Chris@16
|
154 {
|
Chris@16
|
155 return aux::make_collector((a1, a2));
|
Chris@16
|
156 }
|
Chris@16
|
157 template< typename T1, typename T2, typename T3 >
|
Chris@16
|
158 inline shared_ptr< collector > make_collector(T1 const& a1, T2 const& a2, T3 const& a3)
|
Chris@16
|
159 {
|
Chris@16
|
160 return aux::make_collector((a1, a2, a3));
|
Chris@16
|
161 }
|
Chris@16
|
162
|
Chris@16
|
163 #else
|
Chris@16
|
164
|
Chris@16
|
165 /*!
|
Chris@16
|
166 * The function creates a file collector for the specified target directory.
|
Chris@16
|
167 * Each target directory is managed by a single file collector, so if
|
Chris@16
|
168 * this function is called several times for the same directory,
|
Chris@16
|
169 * it will return a reference to the same file collector. It is safe
|
Chris@16
|
170 * to use the same collector in different sinks, even in a multithreaded
|
Chris@16
|
171 * application.
|
Chris@16
|
172 *
|
Chris@16
|
173 * One can specify certain restrictions for the stored files, such as
|
Chris@16
|
174 * maximum total size or minimum free space left in the target directory.
|
Chris@16
|
175 * If any of the specified restrictions is not met, the oldest stored file
|
Chris@16
|
176 * is deleted. If the same collector is requested more than once with
|
Chris@16
|
177 * different restrictions, the collector will act according to the most strict
|
Chris@16
|
178 * combination of all specified restrictions.
|
Chris@16
|
179 *
|
Chris@16
|
180 * The following named parameters are supported:
|
Chris@16
|
181 *
|
Chris@16
|
182 * \li \c target - Specifies the target directory for the files being stored in. This parameter
|
Chris@16
|
183 * is mandatory.
|
Chris@16
|
184 * \li \c max_size - Specifies the maximum total size, in bytes, of stored files that the collector
|
Chris@16
|
185 * will try not to exceed. If the size exceeds this threshold the oldest file(s) is
|
Chris@16
|
186 * deleted to free space. Note that the threshold may be exceeded if the size of
|
Chris@16
|
187 * individual files exceed the \c max_size value. The threshold is not maintained,
|
Chris@16
|
188 * if not specified.
|
Chris@16
|
189 * \li \c min_free_space - Specifies the minimum free space, in bytes, in the target directory that
|
Chris@16
|
190 * the collector tries to maintain. If the threshold is exceeded, the oldest
|
Chris@16
|
191 * file(s) is deleted to free space. The threshold is not maintained, if not
|
Chris@16
|
192 * specified.
|
Chris@16
|
193 *
|
Chris@16
|
194 * \return The file collector.
|
Chris@16
|
195 */
|
Chris@16
|
196 template< typename... ArgsT >
|
Chris@16
|
197 shared_ptr< collector > make_collector(ArgsT... const& args);
|
Chris@16
|
198
|
Chris@16
|
199 #endif // BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
200
|
Chris@16
|
201 /*!
|
Chris@16
|
202 * The class represents the time point of log file rotation. One can specify one of three
|
Chris@16
|
203 * types of time point based rotation:
|
Chris@16
|
204 *
|
Chris@16
|
205 * \li rotation takes place every day, at the specified time
|
Chris@16
|
206 * \li rotation takes place on the specified day of every week, at the specified time
|
Chris@16
|
207 * \li rotation takes place on the specified day of every month, at the specified time
|
Chris@16
|
208 *
|
Chris@16
|
209 * The time points are considered to be local time.
|
Chris@16
|
210 */
|
Chris@16
|
211 class rotation_at_time_point
|
Chris@16
|
212 {
|
Chris@16
|
213 public:
|
Chris@16
|
214 typedef bool result_type;
|
Chris@16
|
215
|
Chris@16
|
216 private:
|
Chris@16
|
217 enum day_kind
|
Chris@16
|
218 {
|
Chris@16
|
219 not_specified,
|
Chris@16
|
220 weekday,
|
Chris@16
|
221 monthday
|
Chris@16
|
222 };
|
Chris@16
|
223
|
Chris@16
|
224 day_kind m_DayKind : 2;
|
Chris@16
|
225 unsigned char m_Day : 6;
|
Chris@16
|
226 unsigned char m_Hour, m_Minute, m_Second;
|
Chris@16
|
227
|
Chris@16
|
228 mutable posix_time::ptime m_Previous;
|
Chris@16
|
229
|
Chris@16
|
230 public:
|
Chris@16
|
231 /*!
|
Chris@16
|
232 * Creates a rotation time point of every day at the specified time
|
Chris@16
|
233 *
|
Chris@16
|
234 * \param hour The rotation hour, should be within 0 and 23
|
Chris@16
|
235 * \param minute The rotation minute, should be within 0 and 59
|
Chris@16
|
236 * \param second The rotation second, should be within 0 and 59
|
Chris@16
|
237 */
|
Chris@16
|
238 BOOST_LOG_API explicit rotation_at_time_point(unsigned char hour, unsigned char minute, unsigned char second);
|
Chris@16
|
239
|
Chris@16
|
240 /*!
|
Chris@16
|
241 * Creates a rotation time point of each specified weekday at the specified time
|
Chris@16
|
242 *
|
Chris@16
|
243 * \param wday The weekday of the rotation
|
Chris@16
|
244 * \param hour The rotation hour, should be within 0 and 23
|
Chris@16
|
245 * \param minute The rotation minute, should be within 0 and 59
|
Chris@16
|
246 * \param second The rotation second, should be within 0 and 59
|
Chris@16
|
247 */
|
Chris@16
|
248 BOOST_LOG_API explicit rotation_at_time_point(
|
Chris@16
|
249 date_time::weekdays wday,
|
Chris@16
|
250 unsigned char hour = 0,
|
Chris@16
|
251 unsigned char minute = 0,
|
Chris@16
|
252 unsigned char second = 0);
|
Chris@16
|
253
|
Chris@16
|
254 /*!
|
Chris@16
|
255 * Creates a rotation time point of each specified day of month at the specified time
|
Chris@16
|
256 *
|
Chris@16
|
257 * \param mday The monthday of the rotation, should be within 1 and 31
|
Chris@16
|
258 * \param hour The rotation hour, should be within 0 and 23
|
Chris@16
|
259 * \param minute The rotation minute, should be within 0 and 59
|
Chris@16
|
260 * \param second The rotation second, should be within 0 and 59
|
Chris@16
|
261 */
|
Chris@16
|
262 BOOST_LOG_API explicit rotation_at_time_point(
|
Chris@16
|
263 gregorian::greg_day mday,
|
Chris@16
|
264 unsigned char hour = 0,
|
Chris@16
|
265 unsigned char minute = 0,
|
Chris@16
|
266 unsigned char second = 0);
|
Chris@16
|
267
|
Chris@16
|
268 /*!
|
Chris@16
|
269 * Checks if it's time to rotate the file
|
Chris@16
|
270 */
|
Chris@16
|
271 BOOST_LOG_API bool operator() () const;
|
Chris@16
|
272 };
|
Chris@16
|
273
|
Chris@16
|
274 /*!
|
Chris@16
|
275 * The class represents the time interval of log file rotation. The log file will be rotated
|
Chris@16
|
276 * after the specified time interval has passed.
|
Chris@16
|
277 */
|
Chris@16
|
278 class rotation_at_time_interval
|
Chris@16
|
279 {
|
Chris@16
|
280 public:
|
Chris@16
|
281 typedef bool result_type;
|
Chris@16
|
282
|
Chris@16
|
283 private:
|
Chris@16
|
284 posix_time::time_duration m_Interval;
|
Chris@16
|
285 mutable posix_time::ptime m_Previous;
|
Chris@16
|
286
|
Chris@16
|
287 public:
|
Chris@16
|
288 /*!
|
Chris@16
|
289 * Creates a rotation time interval of the specified duration
|
Chris@16
|
290 *
|
Chris@16
|
291 * \param interval The interval of the rotation, should be no less than 1 second
|
Chris@16
|
292 */
|
Chris@16
|
293 explicit rotation_at_time_interval(posix_time::time_duration const& interval) :
|
Chris@16
|
294 m_Interval(interval)
|
Chris@16
|
295 {
|
Chris@16
|
296 BOOST_ASSERT(!interval.is_special());
|
Chris@16
|
297 BOOST_ASSERT(interval.total_seconds() > 0);
|
Chris@16
|
298 }
|
Chris@16
|
299
|
Chris@16
|
300 /*!
|
Chris@16
|
301 * Checks if it's time to rotate the file
|
Chris@16
|
302 */
|
Chris@16
|
303 BOOST_LOG_API bool operator() () const;
|
Chris@16
|
304 };
|
Chris@16
|
305
|
Chris@16
|
306 } // namespace file
|
Chris@16
|
307
|
Chris@16
|
308
|
Chris@16
|
309 /*!
|
Chris@16
|
310 * \brief An implementation of a text file logging sink backend
|
Chris@16
|
311 *
|
Chris@16
|
312 * The sink backend puts formatted log records to a text file.
|
Chris@16
|
313 * The sink supports file rotation and advanced file control, such as
|
Chris@16
|
314 * size and file count restriction.
|
Chris@16
|
315 */
|
Chris@16
|
316 class text_file_backend :
|
Chris@16
|
317 public basic_formatted_sink_backend<
|
Chris@16
|
318 char,
|
Chris@16
|
319 combine_requirements< synchronized_feeding, flushing >::type
|
Chris@16
|
320 >
|
Chris@16
|
321 {
|
Chris@16
|
322 //! Base type
|
Chris@16
|
323 typedef basic_formatted_sink_backend<
|
Chris@16
|
324 char,
|
Chris@16
|
325 combine_requirements< synchronized_feeding, flushing >::type
|
Chris@16
|
326 > base_type;
|
Chris@16
|
327
|
Chris@16
|
328 public:
|
Chris@16
|
329 //! Character type
|
Chris@16
|
330 typedef base_type::char_type char_type;
|
Chris@16
|
331 //! String type to be used as a message text holder
|
Chris@16
|
332 typedef base_type::string_type string_type;
|
Chris@16
|
333 //! Stream type
|
Chris@16
|
334 typedef std::basic_ostream< char_type > stream_type;
|
Chris@16
|
335
|
Chris@16
|
336 //! File open handler
|
Chris@16
|
337 typedef boost::log::aux::light_function< void (stream_type&) > open_handler_type;
|
Chris@16
|
338 //! File close handler
|
Chris@16
|
339 typedef boost::log::aux::light_function< void (stream_type&) > close_handler_type;
|
Chris@16
|
340
|
Chris@16
|
341 //! Predicate that defines the time-based condition for file rotation
|
Chris@16
|
342 typedef boost::log::aux::light_function< bool () > time_based_rotation_predicate;
|
Chris@16
|
343
|
Chris@16
|
344 private:
|
Chris@16
|
345 //! \cond
|
Chris@16
|
346
|
Chris@16
|
347 struct implementation;
|
Chris@16
|
348 implementation* m_pImpl;
|
Chris@16
|
349
|
Chris@16
|
350 //! \endcond
|
Chris@16
|
351
|
Chris@16
|
352 public:
|
Chris@16
|
353 /*!
|
Chris@16
|
354 * Default constructor. The constructed sink backend uses default values of all the parameters.
|
Chris@16
|
355 */
|
Chris@16
|
356 BOOST_LOG_API text_file_backend();
|
Chris@16
|
357
|
Chris@16
|
358 /*!
|
Chris@16
|
359 * Constructor. Creates a sink backend with the specified named parameters.
|
Chris@16
|
360 * The following named parameters are supported:
|
Chris@16
|
361 *
|
Chris@16
|
362 * \li \c file_name - Specifies the file name pattern where logs are actually written to. The pattern may
|
Chris@16
|
363 * contain directory and file name portions, but only the file name may contain
|
Chris@16
|
364 * placeholders. The backend supports Boost.DateTime placeholders for injecting
|
Chris@16
|
365 * current time and date into the file name. Also, an additional %N placeholder is
|
Chris@16
|
366 * supported, it will be replaced with an integral increasing file counter. The placeholder
|
Chris@16
|
367 * may also contain width specification in the printf-compatible form (e.g. %5N). The
|
Chris@16
|
368 * printed file counter will always be zero-filled. If \c file_name is not specified,
|
Chris@16
|
369 * pattern "%5N.log" will be used.
|
Chris@16
|
370 * \li \c open_mode - File open mode. The mode should be presented in form of mask compatible to
|
Chris@16
|
371 * <tt>std::ios_base::openmode</tt>. If not specified, <tt>trunc | out</tt> will be used.
|
Chris@16
|
372 * \li \c rotation_size - Specifies the approximate size, in characters written, of the temporary file
|
Chris@16
|
373 * upon which the file is passed to the file collector. Note the size does
|
Chris@16
|
374 * not count any possible character conversions that may take place during
|
Chris@16
|
375 * writing to the file. If not specified, the file won't be rotated upon reaching
|
Chris@16
|
376 * any size.
|
Chris@16
|
377 * \li \c time_based_rotation - Specifies the predicate for time-based file rotation.
|
Chris@16
|
378 * No time-based file rotations will be performed, if not specified.
|
Chris@16
|
379 * \li \c auto_flush - Specifies a flag, whether or not to automatically flush the file after each
|
Chris@16
|
380 * written log record. By default, is \c false.
|
Chris@16
|
381 *
|
Chris@16
|
382 * \note Read the caution note regarding file name pattern in the <tt>sinks::file::collector::scan_for_files</tt>
|
Chris@16
|
383 * documentation.
|
Chris@16
|
384 */
|
Chris@16
|
385 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
386 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(text_file_backend, construct)
|
Chris@16
|
387 #else
|
Chris@16
|
388 template< typename... ArgsT >
|
Chris@16
|
389 explicit text_file_backend(ArgsT... const& args);
|
Chris@16
|
390 #endif
|
Chris@16
|
391
|
Chris@16
|
392 /*!
|
Chris@16
|
393 * Destructor
|
Chris@16
|
394 */
|
Chris@16
|
395 BOOST_LOG_API ~text_file_backend();
|
Chris@16
|
396
|
Chris@16
|
397 /*!
|
Chris@16
|
398 * The method sets file name wildcard for the files being written. The wildcard supports
|
Chris@16
|
399 * date and time injection into the file name.
|
Chris@16
|
400 *
|
Chris@16
|
401 * \param pattern The name pattern for the file being written.
|
Chris@16
|
402 */
|
Chris@16
|
403 template< typename PathT >
|
Chris@16
|
404 void set_file_name_pattern(PathT const& pattern)
|
Chris@16
|
405 {
|
Chris@16
|
406 set_file_name_pattern_internal(filesystem::path(pattern));
|
Chris@16
|
407 }
|
Chris@16
|
408
|
Chris@16
|
409 /*!
|
Chris@16
|
410 * The method sets the file open mode
|
Chris@16
|
411 *
|
Chris@16
|
412 * \param mode File open mode
|
Chris@16
|
413 */
|
Chris@16
|
414 BOOST_LOG_API void set_open_mode(std::ios_base::openmode mode);
|
Chris@16
|
415
|
Chris@16
|
416 /*!
|
Chris@16
|
417 * The method sets the log file collector function. The function is called
|
Chris@16
|
418 * on file rotation and is being passed the written file name.
|
Chris@16
|
419 *
|
Chris@16
|
420 * \param collector The file collector function object
|
Chris@16
|
421 */
|
Chris@16
|
422 BOOST_LOG_API void set_file_collector(shared_ptr< file::collector > const& collector);
|
Chris@16
|
423
|
Chris@16
|
424 /*!
|
Chris@16
|
425 * The method sets file opening handler. The handler will be called every time
|
Chris@16
|
426 * the backend opens a new temporary file. The handler may write a header to the
|
Chris@16
|
427 * opened file in order to maintain file validity.
|
Chris@16
|
428 *
|
Chris@16
|
429 * \param handler The file open handler function object
|
Chris@16
|
430 */
|
Chris@16
|
431 BOOST_LOG_API void set_open_handler(open_handler_type const& handler);
|
Chris@16
|
432
|
Chris@16
|
433 /*!
|
Chris@16
|
434 * The method sets file closing handler. The handler will be called every time
|
Chris@16
|
435 * the backend closes a temporary file. The handler may write a footer to the
|
Chris@16
|
436 * opened file in order to maintain file validity.
|
Chris@16
|
437 *
|
Chris@16
|
438 * \param handler The file close handler function object
|
Chris@16
|
439 */
|
Chris@16
|
440 BOOST_LOG_API void set_close_handler(close_handler_type const& handler);
|
Chris@16
|
441
|
Chris@16
|
442 /*!
|
Chris@16
|
443 * The method sets maximum file size. When the size is reached, file rotation is performed.
|
Chris@16
|
444 *
|
Chris@16
|
445 * \note The size does not count any possible character translations that may happen in
|
Chris@16
|
446 * the underlying API. This may result in greater actual sizes of the written files.
|
Chris@16
|
447 *
|
Chris@16
|
448 * \param size The maximum file size, in characters.
|
Chris@16
|
449 */
|
Chris@16
|
450 BOOST_LOG_API void set_rotation_size(uintmax_t size);
|
Chris@16
|
451
|
Chris@16
|
452 /*!
|
Chris@16
|
453 * The method sets the predicate that defines the time-based condition for file rotation.
|
Chris@16
|
454 *
|
Chris@16
|
455 * \note The rotation always occurs on writing a log record, so the rotation is
|
Chris@16
|
456 * not strictly bound to the specified condition.
|
Chris@16
|
457 *
|
Chris@16
|
458 * \param predicate The predicate that defines the time-based condition for file rotation.
|
Chris@16
|
459 * If empty, no time-based rotation will take place.
|
Chris@16
|
460 */
|
Chris@16
|
461 BOOST_LOG_API void set_time_based_rotation(time_based_rotation_predicate const& predicate);
|
Chris@16
|
462
|
Chris@16
|
463 /*!
|
Chris@16
|
464 * Sets the flag to automatically flush buffers of all attached streams after each log record
|
Chris@16
|
465 */
|
Chris@16
|
466 BOOST_LOG_API void auto_flush(bool f = true);
|
Chris@16
|
467
|
Chris@16
|
468 /*!
|
Chris@16
|
469 * Performs scanning of the target directory for log files that may have been left from
|
Chris@16
|
470 * previous runs of the application. The found files are considered by the file collector
|
Chris@16
|
471 * as if they were rotated.
|
Chris@16
|
472 *
|
Chris@16
|
473 * The file scan can be performed in two ways: either all files in the target directory will
|
Chris@16
|
474 * be considered as log files, or only those files that satisfy the file name pattern.
|
Chris@16
|
475 * See documentation on <tt>sinks::file::collector::scan_for_files</tt> for more information.
|
Chris@16
|
476 *
|
Chris@16
|
477 * \pre File collector and the proper file name pattern have already been set.
|
Chris@16
|
478 *
|
Chris@16
|
479 * \param method File scanning method
|
Chris@16
|
480 * \param update_counter If \c true and \a method is \c scan_matching, the method attempts
|
Chris@16
|
481 * to update the internal file counter according to the found files. The counter
|
Chris@16
|
482 * is unaffected otherwise.
|
Chris@16
|
483 * \return The number of files found.
|
Chris@16
|
484 *
|
Chris@16
|
485 * \note The method essentially delegates to the same-named function of the file collector.
|
Chris@16
|
486 */
|
Chris@16
|
487 BOOST_LOG_API uintmax_t scan_for_files(
|
Chris@16
|
488 file::scan_method method = file::scan_matching, bool update_counter = true);
|
Chris@16
|
489
|
Chris@16
|
490 /*!
|
Chris@16
|
491 * The method writes the message to the sink
|
Chris@16
|
492 */
|
Chris@16
|
493 BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
|
Chris@16
|
494
|
Chris@16
|
495 /*!
|
Chris@16
|
496 * The method flushes the currently open log file
|
Chris@16
|
497 */
|
Chris@16
|
498 BOOST_LOG_API void flush();
|
Chris@16
|
499
|
Chris@16
|
500 /*!
|
Chris@16
|
501 * The method rotates the file
|
Chris@16
|
502 */
|
Chris@16
|
503 BOOST_LOG_API void rotate_file();
|
Chris@16
|
504
|
Chris@16
|
505 private:
|
Chris@16
|
506 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
507 //! Constructor implementation
|
Chris@16
|
508 template< typename ArgsT >
|
Chris@16
|
509 void construct(ArgsT const& args)
|
Chris@16
|
510 {
|
Chris@16
|
511 construct(
|
Chris@16
|
512 filesystem::path(args[keywords::file_name | filesystem::path()]),
|
Chris@16
|
513 args[keywords::open_mode | (std::ios_base::trunc | std::ios_base::out)],
|
Chris@16
|
514 args[keywords::rotation_size | (std::numeric_limits< uintmax_t >::max)()],
|
Chris@16
|
515 args[keywords::time_based_rotation | time_based_rotation_predicate()],
|
Chris@16
|
516 args[keywords::auto_flush | false]);
|
Chris@16
|
517 }
|
Chris@16
|
518 //! Constructor implementation
|
Chris@16
|
519 BOOST_LOG_API void construct(
|
Chris@16
|
520 filesystem::path const& pattern,
|
Chris@16
|
521 std::ios_base::openmode mode,
|
Chris@16
|
522 uintmax_t rotation_size,
|
Chris@16
|
523 time_based_rotation_predicate const& time_based_rotation,
|
Chris@16
|
524 bool auto_flush);
|
Chris@16
|
525
|
Chris@16
|
526 //! The method sets file name mask
|
Chris@16
|
527 BOOST_LOG_API void set_file_name_pattern_internal(filesystem::path const& pattern);
|
Chris@101
|
528
|
Chris@101
|
529 //! Closes the currently open file
|
Chris@101
|
530 void close_file();
|
Chris@16
|
531 #endif // BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
532 };
|
Chris@16
|
533
|
Chris@16
|
534 } // namespace sinks
|
Chris@16
|
535
|
Chris@16
|
536 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
537
|
Chris@16
|
538 } // namespace boost
|
Chris@16
|
539
|
Chris@16
|
540 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
541
|
Chris@16
|
542 #endif // BOOST_LOG_SINKS_TEXT_FILE_BACKEND_HPP_INCLUDED_
|