onnxruntime/include
Edward Chen 5a5fec0452
Fix logs getting skipped in single-line conditionals. (#7589)
Fix an issue where a log message got skipped.

A log call like this:
```
LOGS(...) << "message";
```
expands to something like this:
```
if (<output enabled>)
  logging::Capture(...).Stream() << "message";
```

This if statement without brackets is handy for logging arbitrary arguments with the `<<` operator. However, it has other drawbacks like possibly associating with a subsequent `else`.

```
if (cond)
  LOGS(...) << "a";
else
  <do something> // not run when !cond

// equivalently:
if (cond)
  if (<output enabled>)
    logging::Capture(...).Stream() << "a";
  else
    <do something> // not run when !cond
```

Updated the logging macros to handle this case by replacing `if (<enabled>) logging::Capture(...).Stream()` with `if (!<enabled>) {} else logging::Capture(...).Stream()`.

Thanks @tlh20 for the idea for the fix!
2021-05-07 15:40:47 -07:00
..
onnxruntime/core Fix logs getting skipped in single-line conditionals. (#7589) 2021-05-07 15:40:47 -07:00