2
0
mirror of https://github.com/boostorg/log.git synced 2026-01-31 08:12:30 +00:00
Commit Graph

244 Commits

Author SHA1 Message Date
Andrey Semashev
dda118619a Fixed binding IPv4 local address in syslog_backend when IPv6 target is used.
Fixes https://github.com/boostorg/log/issues/181.
2022-04-22 18:14:11 +03:00
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
1303a7a92c Suppress MSVC warning about possible loss of data. 2021-10-30 00:12:15 +03:00
Andrey Semashev
6c9d326e5b Updated copyright years. 2021-10-25 01:58:04 +03:00
Andrey Semashev
9238377f1f Corrected placement of alignas. 2021-10-25 01:51:17 +03:00
Andrey Semashev
b15d02ab3b Added workarounds of older gcc and clang for AVX2 dump implementation.
Use inline asm instead of _mm256_broadcastsi128_si256 to work around issues:

 - gcc 4.7 is missing _mm256_broadcastsi128_si256 declaration in immintrin.h.
 - gcc 4.8 generates vmovdqu+vinserti128 instead of a single vbroadcasti128.
 - clang up until 4.0 generates vmovdqu+vinserti128 or worse.
2021-10-25 01:34:56 +03:00
Andrey Semashev
63325283f5 Improved performance of SSSE3/AVX2 implementations of dump manipulator.
Use byte shuffle instead of arithmetics and masking to convert half-bytes
to characters.

Since the new algorithm more heavilly relies on pshufb, and it is slow
on some older Intel Atom CPUs, retain the old implementation and use it
when we know pshufb is slow. We might drop it eventually.
2021-10-24 21:18:10 +03:00
Andrey Semashev
1d6a8d9a50 Added a dummy export from boost_log_setup if settings parsers are disabled.
When settings parsers were disabled by a config macro, boost_log_setup would
be empty, and MSVC linker would produce no library at all. This broke
installing Boost.Log, as Boost.Build would expect a library file to be present.

We're adding a dummy export from the library as a workaround, so that the
library is always created, even if empty. This workaround should be considered
temporary, until we can disable the library proper after a Boost.Build bug
is fixed:

https://github.com/bfgroup/b2/issues/104

Closes https://github.com/boostorg/log/issues/164.
Closes https://github.com/boostorg/log/pull/165.
2021-10-24 16:09:04 +03:00
Andrey Semashev
6d4021209d Moved is_debugger_present predicate implementation to a compiled source file.
This allows to avoid including windows.h in public headers and defining an
arbitraty target Windows version to make IsDebuggerPresent API available.
2021-09-18 00:09:46 +03:00
Andrey Semashev
124abd34d7 Ported WinAPI-based event to use Boost.Atomic. 2021-09-17 22:53:14 +03:00
Andrey Semashev
a3adc2cf33 Updated copyright years. 2021-09-16 23:15:48 +03:00
Andrey Semashev
28822babfe Ported futex-based event implementation to Boost.Atomic.
This allows to reuse the futex abstraction layer from Boost.Atomic and
also use futex-like APIs available on other systems.

Closes https://github.com/boostorg/log/issues/161.
2021-09-16 23:05:23 +03:00
Andrey Semashev
24117c7a0c Fixed a race in reliable_message_queue::open_or_create on POSIX systems.
The open_or_create implementation assumed that the created shared memory
size of 0 meant that the shared memory segment was freshly created. This
is not the case if multiple threads call open_or_create and check the
segment size before one of them resizes it. This could result in
initializing the shared memory multiple times and even corrupting it
if other threads were sending or receiving messages in the mean time.

While at it, converted the use of atomics in shared memory to ipc_atomic.

Fixes https://github.com/boostorg/log/issues/162.
2021-09-15 16:33:25 +03:00
Andrey Semashev
5c6f3f9ddc Added asserts to IPC queue impl to enforce preconditions. 2021-09-13 19:37: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
Fabrice Fontaine
d206141950 src/event.cpp: fix build on riscv32
riscv32 fails to build because __NR_futex is not defined on this
architecture:

libs/log/src/event.cpp: In member function 'void boost::log::v2_mt_posix::aux::futex_based_event::wait()':
libs/log/src/event.cpp:38:29: error: '__NR_futex' was not declared in this scope
   38 | #define BOOST_LOG_SYS_FUTEX __NR_futex
      |                             ^~~~~~~~~~

Fixes:
 - http://autobuild.buildroot.org/results/8c8135fd7c0517c66c9b3975c494da6d7934cc1b

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2021-05-29 17:06:02 +03:00
Andrey Semashev
d99d9891dd Removed the use of virtual functions from threadsafe_queue implementation.
This should amount to a more efficient code and smaller binaries.
2021-01-28 02:42:39 +03:00
Andrey Semashev
a75c4f45c4 Corrected a formal race in the threadsafe_queue implementation.
The pointer to the next node can be read and written concurrently
by push and try_pop methods. This does not impose a real problem
as long as pointer-sized loads and stores generated by the compiler
are atomic on a given target platform, which it typically is.
No memory ordering constraints are needed in this context.

To guarantee atomicity, use Boost.Atomic for these pointers.

Fixes https://github.com/boostorg/log/issues/139.
2021-01-28 01:55:20 +03:00
Andrey Semashev
84b82a4de4 Removed BOOST_LOG_ASSUME postulating that a reference is not null.
Normally, this should be inferred by compiler, as references are not
allowed to be null. This silences a clang-cl warning.
2020-09-08 18:28:06 +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
e7d4fd2d13 Include config.hpp before checking BOOST_LOG_WITHOUT_SYSLOG.
Boost.Log's config.hpp may define BOOST_LOG_WITHOUT_SYSLOG if no native
syslog API or Boost.ASIO is available, so we need to include the header
before checking the macro.

Closes https://github.com/boostorg/log/pull/123.
2020-08-01 21:59:33 +03:00
Andrey Semashev
9a85efde08 Added noexcept specifiers. Made logger move ctors more noexcept-friendly.
Logger move constructors don't need to add the attributes to the logger
attributes since the latter are moved from the source logger, just as the
attributes. This allows move constructors to be noexcept, provided that
they are non-noexcept for other reasons.

Closes https://github.com/boostorg/log/issues/121.
2020-05-07 20:35:14 +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
Andrey Semashev
1e92e84b80 Added checking for IP version in addresses in syslog backend.
The syslog sink backend now verifies the IP version of the local and target
addresses set by user. The addresses must have the same IP version as was
specified in the ip_version named parameter on the sink backend construction.
When an address is obtained as a result of host name resolution, only addresses
with matching IP version are considered.

This should protect against using local and target addresses with mismatching
IP versions, which results in errors on sending datagrams.

Fixes https://github.com/boostorg/log/issues/119.
2020-04-27 21:47:41 +03:00
Andrey Semashev
c068c2a5aa Add explicit markup of fallthrough between switch/case labels.
Silences some compiler warnings.

Closes https://github.com/boostorg/log/issues/115.
2020-04-14 00:29:14 +03: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
60cf554ee9 Ported to use newer API of Boost.Atomic. 2020-03-04 00:32:52 +03:00
Andrey Semashev
a7b4a140d9 Use atomic to implement logging_enabled flag. 2020-02-29 16:01:00 +03:00
Andrey Semashev
9474c57264 Perform automatic flush in default sink.
Closes https://github.com/boostorg/log/issues/103.
2020-02-29 15:44:41 +03:00
Andrey Semashev
e5f305a8a5 Make core::flush call flush on the default sink.
When trivial logging is used and no sinks are registered, allow
users to manually flush the default sink.

Related to https://github.com/boostorg/log/issues/103.
2020-02-29 15:43:34 +03:00
Andrey Semashev
4d9ce5cdba Check for feature test macros after including config.hpp.
This avoids possible inconsistency when the BOOST_LOG_WITHOUT_DEBUG_OUTPUT
and BOOST_LOG_WITHOUT_EVENT_LOG macros are defined in config.hpp but not
in command line.

Related to https://github.com/boostorg/log/issues/102.
2020-02-21 18:44:48 +03:00
Andrey Semashev
2f15b44dc1 Converted some uses of Boost.MPL to Boost.TypeTraits. 2020-02-17 18:41:29 +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
c721453aeb Ported named_scope_list and pool_allocator to allocator_traits.
This fixes compilation problems with C++20 std::allocator, which removed
deprecated typedefs and member functions.

Closes https://github.com/boostorg/log/pull/100.
2020-02-17 15:49:58 +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
10a63204b3 Added a workaround for openlog not saving ident string.
Some syslog implementations (e.g. glibc) do not save the ident string
in openlog and instead only save a pointer to the user-provided string.
This requires the caller to preserve the passed string for the whole
duration of logging.

Fixes https://github.com/boostorg/log/issues/97.
2020-01-22 21:37:56 +03:00
Andrey Semashev
e80dce7fec Removed unused local typedefs. 2019-10-22 20:06:26 +03:00
Andrey Semashev
08bd1fb809 Added support for trivial::severity_level to filter/formatter parsers.
The default filter/formatter factories will now be able to extract severity
level values of type boost::log::trivial::severity_level. For filters, this
is only supported for attributes with the "Severity" name.
2019-06-25 18:54: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
46560ff9fb Removed unnecessary optimization in the check for an operator keyword.
Modern compilers are able to optimize memcmp to a single cmp instruction
with a constant, which was the intention of the optimization. This should
fix UBSan errors.
2019-01-05 15:04:26 +03:00