Custom CRTLogSystemInterface is impossible to use #2337
Labels
bug
This issue is a bug.
dependencies
This issue is a problem in a dependency.
p2
This is a standard priority issue
Describe the bug
Currently it is impossible to implement custom logging for CRT libraries by creating your own logger derived from the
Aws::Utils::Logging::CRTLogSystemInterface
. This is despite the equivalent functionality being available for the main SDK logging messages via theAws::Utils::Logging::LogSystemInterface
class.The developer guide chapter on logging (https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/logging.html), strongly suggests a custom logger may be installed by overwriting the
crt_logger_create_fn
:This
crt_logger_create_fn
member is a pointer to a function that provides ashared_ptr<CRTLogSystemInterface>
(critically - not aDefaultCRTLogSystem
).However looking at the code for
CRTLogSystemInterface
reveals it provides no usable functions:Instead all of the function that one needs to overwrite are actually part of the
DefaultCRTLogSystem
class.Under the hood, the stored pointer to a
CRTLogSystemInterface
isreinterpret_cast
back to aDefaultCRTLogSystem
when it is used.Expected Behavior
It should be possible to provide a custom implementation of the
CRTLogSystemInterface
just as it is for the mainLogSystemInterface
.Current Behavior
It is impossible to derive a class from
CRTLogSystemInterface
and use it within the logging system.Doing so will result in undefined behaviour.Update: Doing so has no effect since the user would also need to implement the hooks into the CRT libraries themselves, at which point they have gained nothing from the interface class (see below).Reproduction Steps
Possible Solution
The functions that are currently defined within
DefaultCRTLogSystem
should be declared in theCRTLogSystemInterface
as pure virtual functions. Thereinterpret_cast
performed inCRTLogSystem.cpp
as part of the bridge between the CRT logging and the SDK logging mechanisms should be changed to target the correct base class.Update: the top level interface class probably should not be a pure interface and instead provide at least the hookup into the CRT libraries. Then it should provide the pure virtual output function that users can implement when they derive from it.
Additional Information/Context
No response
AWS CPP SDK version used
main, 1.1.11
Compiler and Version used
gcc 12.2.1
Operating System and version
Fedora 37
The text was updated successfully, but these errors were encountered: