plog
plog copied to clipboard
[Question] How to use Chained for multiple Classes within many DLL's
scenario I want use DI / IoC style creation in Several Exported Classes from several DLL's
For DLL that has several classes I am using chaining:
CDoMagic::CDoMagic(plog::Severity severity, plog::IAppender* appender)
{
plog::init(severity, appender); // Initialize the shared library logger.
PLOGI << "CDoMagic Created";
}
CDoMgic2::CDoMgic2(plog::Severity severity, plog::IAppender* appender)
{
plog::init(severity, appender); // Initialize the shared library logger.
PLOGI << "CDoMgic2 Created";
}
Each time an instance of the classes are constructed a new static instance is created behind the scenes; So when PLOG## is called it will log out several times, because there are several instance of the logger e.g. in the following CDoMgic2 has been created twice, but the 2nd instance is logging out 3 times.
2023-08-17 14:28:48.507 INFO [21584] [CDoMagic::CDoMagic@9] CDoMagic Created
2023-08-17 14:28:48.509 INFO [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.509 INFO [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.511 INFO [21584] [CDoMgic2::~CDoMgic2@14] CDoMgic2 Destroyed
2023-08-17 14:28:48.511 INFO [21584] [CDoMgic2::~CDoMgic2@14] CDoMgic2 Destroyed
2023-08-17 14:28:48.513 INFO [21584] [CDoMagic::~CDoMagic@14] CDoMagic Destroyed
2023-08-17 14:28:48.513 INFO [21584] [CDoMagic::~CDoMagic@14] CDoMagic Destroyed
2023-08-17 14:28:48.518 INFO [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.518 INFO [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.518 INFO [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
code to demonstrate above:
{
CDoMagic DoMagic(plog::get()->getMaxSeverity(), plog::get() );
CDoMgic2 DoMagic2(plog::get()->getMaxSeverity(), plog::get());
}
CDoMgic2 DoMagic2(plog::get()->getMaxSeverity(), plog::get());