@@ -73,19 +73,41 @@ namespace p2c
7373 using namespace pmon ::util;
7474 using namespace pmon ::util::log;
7575
76+ _invalid_parameter_handler pOriginalInvalidParameterHandler_ = nullptr ;
77+
78+ namespace {
79+ void InvalidParameterHandler_ (
80+ const wchar_t * expression,
81+ const wchar_t * function,
82+ const wchar_t * file,
83+ unsigned int line,
84+ uintptr_t pReserved)
85+ {
86+ // convert to narrow and log the assertion content
87+ const auto narrowFunction = str::ToNarrow (function);
88+ const auto narrowFile = str::ToNarrow (file);
89+ pmlog_from_ (Level::Fatal, narrowFile.c_str (), narrowFunction.c_str (), (int )line)
90+ .note (std::format (" CRT assertion: {}" , str::ToNarrow (expression)));
91+ // flush the default channel
92+ if (auto pChan = GetDefaultChannel ()) {
93+ pChan->Flush ();
94+ }
95+ // invoke the original handler
96+ if (pOriginalInvalidParameterHandler_) {
97+ pOriginalInvalidParameterHandler_ (expression, function, file, line, pReserved);
98+ }
99+ }
100+ }
101+
76102 void ConfigureLogging () noexcept
77103 {
78104 try {
79105 auto pChan = GetDefaultChannel ();
106+ // setup CRT assert handler
107+ pOriginalInvalidParameterHandler_ = _set_invalid_parameter_handler (InvalidParameterHandler_);
80108 // shortcut for command line
81109 const auto & opt = cli::Options::Get ();
82110 const auto render = opt.cefType && *opt.cefType == " renderer" ;
83- // connect dll channel and id table to exe, get access to global settings in dll
84- LoggingSingletons getters;
85- if (render && opt.logMiddlewareCopy ) {
86- getters = pmLinkLogging_ (pChan, []() -> IdentificationTable& {
87- return IdentificationTable::Get_ (); });
88- }
89111
90112 // determine log folder path
91113 std::filesystem::path logFolder;
@@ -103,6 +125,12 @@ namespace p2c
103125 pChan->AttachComponent (std::make_shared<BasicFileDriver>(std::make_shared<TextFormatter>(),
104126 std::make_shared<SimpleFileStrategy>(logfilePathClient)), " drv:file" );
105127 auto && pol = GlobalPolicy::Get ();
128+ // connect dll channel and id table to exe, get access to global settings in dll
129+ LoggingSingletons getters;
130+ if (render && opt.logMiddlewareCopy ) {
131+ getters = pmLinkLogging_ (pChan, []() -> IdentificationTable& {
132+ return IdentificationTable::Get_ (); });
133+ }
106134 // set the global policy settings
107135 if (opt.logLevel ) {
108136 pol.SetLogLevel (*opt.logLevel );
0 commit comments