@@ -73,19 +73,41 @@ namespace p2c
73
73
using namespace pmon ::util;
74
74
using namespace pmon ::util::log;
75
75
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
+
76
102
void ConfigureLogging () noexcept
77
103
{
78
104
try {
79
105
auto pChan = GetDefaultChannel ();
106
+ // setup CRT assert handler
107
+ pOriginalInvalidParameterHandler_ = _set_invalid_parameter_handler (InvalidParameterHandler_);
80
108
// shortcut for command line
81
109
const auto & opt = cli::Options::Get ();
82
110
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
- }
89
111
90
112
// determine log folder path
91
113
std::filesystem::path logFolder;
@@ -103,6 +125,12 @@ namespace p2c
103
125
pChan->AttachComponent (std::make_shared<BasicFileDriver>(std::make_shared<TextFormatter>(),
104
126
std::make_shared<SimpleFileStrategy>(logfilePathClient)), " drv:file" );
105
127
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
+ }
106
134
// set the global policy settings
107
135
if (opt.logLevel ) {
108
136
pol.SetLogLevel (*opt.logLevel );
0 commit comments