2
0
mirror of https://github.com/boostorg/log.git synced 2026-02-09 11:12:38 +00:00
Commit Graph

45 Commits

Author SHA1 Message Date
Andrey Semashev
69ec057e7c Added support for appending to files with file counter placeholders in names.
Previously, text_file_backend would generate a new file name when the file
name pattern contained a file counter placeholder, which prevented appending
to the file. Appending was only possible when the active file name was
stable across process restarts (effectively, this prohibited the file counter
to be used in the active file name).

This commit adds support for appending in such configuration. The file
collector has been updated to return the last found file counter during
filesystem scanning, and the sink backend doesn't increment it when the initial
file is opened, when appending is enabled, and when the file to be opened
exists and, if file collector is used, is in the target storage of the file
collector. In all other cases the file counter is incremented, which leaves
the behavior unchanged.

Closes https://github.com/boostorg/log/issues/179.
2022-02-27 00:03:37 +03:00
Andrey Semashev
656fd1b0c1 Avoid updating file counter in scan_for_files if no new files are found.
This prevents the file counter from being reset to zero if scan_for_files
is called multiple times, and subsequent calls don't find any new files.

Reported in https://github.com/boostorg/log/issues/179.
2022-02-26 16:01:21 +03:00
Andrey Semashev
9fe832c344 Add ios_base::ate when ios_base::app is specified for text_file_backend.
This ensures that the writing position is actual immediately after the
log file is opened for appending. This fixes incorrect accounting for
the initial file size with MSVC and possibly other compilers.

Closes https://github.com/boostorg/log/issues/151.
2021-07-20 01:03:53 +03:00
Andrey Semashev
dd5a8f1b41 Fixed file counter in the target filename generated by text file backend.
The file counter gets incremented when a new file is opened. Since the
target filename was generated later, on file rotation, the target filename
got the next value of the counter. This caused some values of the counter
being skipped when the application restarts and scans for the previous
log files.

Fixes https://github.com/boostorg/log/issues/125.
2020-08-20 19:57:21 +03:00
Andrey Semashev
706fed3bf4 Avoid unnecessary copy of the filename string. 2020-05-07 17:48:38 +03:00
Eugene Zelenko
4019d171a3 Use BOOST_OVERRIDE to fix GCC -Wsuggest-override and Clang-tidy modernize-use-override warnings. 2020-05-03 20:29:19 -07:00
Marian Klymov
e6c6479d91 Add missing filesystem includes.
Fix compilation with BOOST_FILESYSTEM_NO_DEPRECATED
2020-04-03 18:55:34 +03:00
Andrey Semashev
5f48284bf9 Nonessential cleanup. 2020-03-04 13:38:45 +03:00
Andrey Semashev
68d38321b3 Updated deprecated uses of boost::bind to silence warnings. 2020-03-04 00:44:23 +03:00
Andrey Semashev
34d9e64815 Reordered day and day kind initializers to match declaration order.
Silences compiler warnings.
2020-02-17 15:54:45 +03:00
Andrey Semashev
8a7cc8efd6 Move log file status check before renaming to the target file name.
If the log file has not been created (e.g. when there are no log records
written yet), rotate_file could throw as it attempted to rename the file
to the target file name before rotation. The check for file presence that
was intended to protect from this was made later on, before the file collector
is invoked. This commit moves the check before renaming.
2020-02-17 15:12:36 +03:00
Andrey Semashev
42b4463ad2 Fixed day kind representation in rotation_at_time_point.
Since day_kind is enum, it may be represented by a signed integer type.
Some compilers (e.g. MSVC) use sign extension when loading the day kind
field from the bit field, which corrupts the monthday value (which is 2)
and makes the rotation never happen. Fix this by using an unsigned type
to store the day kind and then cast the value to the enum.

Also, rearranged the bitfields for slightly better codegen.

Fixes https://github.com/boostorg/log/issues/98.
2020-02-05 17:30:55 +03:00
Andrey Semashev
e903d3aef7 Fixed compilation in C++03. 2019-06-24 04:34:44 +03:00
Andrey Semashev
894acde57e Added support for controling trailing newline insertion in the text sinks.
Text ostream, file and multifile sink backends now support controlling trailing
newline insertion after every log records. The supported modes are described by
the auto_newline_mode enum. The behavior can be controlled via the same-named
named parameter, a set_auto_newline_mode call or the AutoNewline parameter
in the settings.

The default behavior has changed from the previous releases. From now on the
trailing newline will only be added if there isn't one in the formatted log
message already.
2019-06-23 21:02:51 +03:00
Andrey Semashev
2154cafa46 Optimized file status requesting while scanning for files. 2019-04-14 20:34:44 +03:00
Andrey Semashev
d7a87119e6 Fixed incorrect matching of digits in a file name against a placeholder.
If a file name pattern ended with a placeholder, e.g. a file counter, file names
fitting that pattern would not be matched by scan_for_files, leaving such files
unmanaged.

Fixes https://github.com/boostorg/log/issues/78.
2019-04-14 20:14:58 +03:00
Andrey Semashev
958ced0edd Work around MSVC name lookup bugs.
The compiler fails to find a symbol defined in an anonymous namespace, if
the name is qualified up to the namespace enclosing the anonymous namespace.
2019-01-06 02:00:44 +03:00
Andrey Semashev
e823f88467 Added support for a separate target file name pattern in text file sink.
This allows to have different file names when actively writing the log file
and when rotating. In particular, this solves the problem with appending
to the previous file, when the log files are also collected and are supposed
to have distincs names.
2019-01-05 21:15:33 +03:00
Andrey Semashev
f8954f6662 Work around incorrect total file size estimate in file_collector.
If the text file sink backend used the file that was previously scanned
by file_collector as an old log file, on rotation the collector would
store a duplicate of the file info. If the file was removed due to
storage limits, the file info would still be stored despite the file
being deleted.

Also, in case if a file that is about to be rotated is deleted, don't
hard fail with an exception. This may happen if another process have deleted
the file or Boost.Log itself has. The latter can happen if multiple sinks
write directly into the common target storage and one of them invokes
file rotation, which due to the storage limits delete the file that
is currently being written by the other sink.
2018-10-30 04:29:49 +03:00
Andrey Semashev
7f75487d0b Fixed bad file counter returned from scan_for_files in case of counter overflow.
If the target directory contained a file with counter value of UINT_MAX in its
name, scan_for_files would always return the counter value of 0, even if such
file also existed in the directory. This caused incorrectly named log files to
appear in the target directory on user's application restart.

Also made sure that the returned counter value is zero if the scanning method
is not scan_matching or the file name pattern does not include the counter
placeholder. The returned counter should not have been used by the caller
in these cases anyway, but the returned value used to be bogus.
2017-08-15 16:09:50 +03:00
Andrey Semashev
68701167a1 Updated comments, renamed auto_flush parameter for clarity. 2016-11-27 23:10:34 +03:00
Andrey Semashev
38fd663541 Added a way to disable log file rotation on sink destruction.
This can be useful when the final rotation cannot be performed while global destructors are run (e.g. when a close handler depends on a global state).

It can also be useful to implement file appending with collector set up to a different target directory than the directory the backend writes to.
2016-11-27 22:53:32 +03:00
Andrey Semashev
a74e9d4a74 Added the get_current_file_name method to obtain the current log file
name from the text file sink backend.

Also make sure the close handler is not called when the file is not
open.
2016-10-16 17:37:14 +03:00
Andrey Semashev
b284e68200 Moved queue overflow policy handling to the IPC queue. Compilation fixes. 2016-04-14 19:32:03 +03:00
Erich Keane
5234253333 Added max_files option to text_file_backend's file_collector
As requested here: https://svn.boost.org/trac/boost/ticket/8746
this commit introduces the boost::log::keywords::max_files keyword
and implements this functionality in the file collector.

Additionally, the non-keyword make_collector call has max_files added as
a uintmax_t parameter, which has a default value as to not break
existing code.

The purpose of this is to limit the total number of files in the
collected logs.  If not specified, the limit will be
std::numeric_limits<uintmax_t>::max(), which is likely greater than the
capacity of the filesystem.
2015-12-29 11:07:41 -08:00
Andrey Semashev
a31ec74e51 Make sure that Windows API version is consistent for all sources.
Include winapi/config.hpp as soon as possible; avoid including even
Boost.Config before it so that it doesn't set Windows API version
accidentally by including some third party header. In all source files,
include detail/config.hpp or detail/setup_config.hpp first thing.

Moved all WinAPI config macros to the Jamfile.v2 and removed
windows_version.hpp as it was no longer needed. Also enabled inclusion of
windows.h while compiling the library.

Removed auto-linking with psapi.lib and advapi32.lib as it was no longer
working after ecf3114. Added linking with advapi32.lib to Jamfile.v2.
2015-12-20 21:05:28 +03:00
Andrey Semashev
d242967b52 Added a link to Boost.DateTime ticket for the facet visibility bug. 2015-10-04 23:05:43 +03:00
Andrey Semashev
284d5e6139 Added a workaround for incorrect file name generation in text file sink backend, when the file name contains date/time placeholders. Fixes #11691. 2015-10-04 18:37:05 +03:00
Andrey Semashev
ac70fa34c1 Removed use of auto_ptr. 2015-07-18 20:32:07 +03:00
Andrey Semashev
7ebfd3b6c4 Fixes #11016. Text file sink no longer creates lots of empty files if there is no free space on the file system. 2015-02-14 19:19:42 +03:00
Andrey Semashev
5bb604ee39 Updated copyright dates. 2015-01-25 17:32:33 +03:00
Andrey Semashev
755b2c27b7 Fixes #10700. Don't use vsnprintf_s on MSVC as it does not behave as the standard vsnprintf. Also corrected error checking for snprintf in different places. 2014-10-30 03:19:00 +03:00
Andrey Semashev
dfb3049a7c Extracted text_multifile_backend implementation to a separate file. 2014-06-22 18:46:17 +04:00
Andrey Semashev
7516f00cde Use low-level Qi extractors instead of qi::parse to reduce compile times and binary sizes. 2014-06-22 18:19:12 +04:00
Andrey Semashev
58cca56915 Added noexcept specifications. Simplified code in some cases. 2014-06-21 20:57:18 +04:00
Andrey Semashev
32b3e71432 Fixed compilation with MSVC for 32-bit x86. Removed use of Boost.Spirit and Boost.Phoenix in some cases to speed up compilation and reduce binary sizes. 2014-03-16 18:10:48 +04:00
Andrey Semashev
a21d096e4a Updated copyright notes to 2014. 2014-01-19 18:46:09 +04:00
Andrey Semashev
d3419b1091 Reapplied changeset [86160].
[SVN r86199]
2013-10-08 14:44:59 +00:00
Andrey Semashev
56bb6f2dca Temporarily reverted the last commit [86164], until 1.55 beta ships.
[SVN r86166]
2013-10-05 19:02:18 +00:00
Andrey Semashev
6e6ad59e52 Merged latest changes from trunk.
[SVN r86164]
2013-10-05 14:02:30 +00:00
Andrey Semashev
f01ecd2e7c Merged latest changes from trunk.
[SVN r85986]
2013-09-28 16:11:45 +00:00
Andrey Semashev
313a5b69cd Merged recent changes from trunk.
[SVN r85657]
2013-09-12 17:17:07 +00:00
Andrey Semashev
5204873fa9 Merged latest changes from trunk.
[SVN r85461]
2013-08-25 14:20:22 +00:00
Andrey Semashev
0be5080954 Corrected exception type when an unsupported placeholder is found in the file name pattern when scanning the filesystem.
[SVN r83862]
2013-04-13 12:43:44 +00:00
Andrey Semashev
a7c4e0e319 Boost.Log merged to trunk.
[SVN r83860]
2013-04-13 12:30:25 +00:00