Skip to content

Commit 061f942

Browse files
authored
Merge pull request #4009 from opensim-org/fix_object-loading-errors-should-go-to-log
Change std::cerr/std::cout usages to use the log, where appropriate
2 parents c46cc98 + 158e4b0 commit 061f942

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ v4.6
6666
- It will now check for NaNed vectors coming from the underlying expression, skipping emission
6767
if one is detected (previously: it would emit decorations with `NaN`ed transforms).
6868
- `PolynomialPathFitter` now allows fitting paths that depend on more than 6 coordinates, matching recent changes to `MultivariatePolynomialFunction` (#4001).
69+
- If an `Object` cannot be found when loading a list property from XML, a warning will now be emitted to the log (previously: it was emitted to `std::cerr`, #4009).
6970

7071
v4.5.1
7172
======

OpenSim/Common/Object.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ try {
953953

954954
// NOT RECOGNIZED
955955
default :
956-
cout<<"Object.UpdateObject: WARN- unrecognized property type."<<endl;
956+
log_warn("Object.UpdateObject: WARN- unrecognized property type.");
957957
break;
958958
}
959959
}
@@ -1033,7 +1033,7 @@ void Object::updateXMLNode(SimTK::Xml::Element& aParent,
10331033
// If object is not inlined we don't want to generate node in original document
10341034
// Handle not-inlined objects first.
10351035
if (!aParent.isValid()) {
1036-
cout<<"Root node must be inlined"<<*this<<endl;
1036+
log_warn("Root node of an OpenSim::Object must be inlined, skipping XML reading.");
10371037
}
10381038
else {
10391039
// Can we make this more efficient than recreating the node again?
@@ -1211,8 +1211,8 @@ void Object::updateXMLNode(SimTK::Xml::Element& aParent,
12111211
break;
12121212

12131213
// NOT RECOGNIZED
1214-
default :
1215-
cout<<"Object.UpdateObject: WARN- unrecognized property type."<<endl;
1214+
default:
1215+
log_warn("Object.UpdateObject: WARN- unrecognized property type.");
12161216
break;
12171217
}
12181218
}

OpenSim/Common/Object.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,19 +1406,13 @@ ObjectProperty<T>::readFromXMLElement
14061406
Object::getDefaultInstanceOfType(objTypeTag);
14071407

14081408
if (!registeredObj) {
1409-
std::cerr
1410-
<< "Encountered unrecognized Object typename "
1411-
<< objTypeTag << " while reading property " << this->getName()
1412-
<< ". There is no registered Object of this type; ignoring.\n";
1413-
continue;
1409+
log_error("Encountered unrecognized Object typename {} while reading property {}. There is no registered Object of this type. Ignoring.", objTypeTag, this->getName());
1410+
continue;
14141411
}
14151412

14161413
// Check that the object type found is derived from T.
14171414
if (!dynamic_cast<const T*>(registeredObj)) {
1418-
std::cerr << "Object type " << objTypeTag
1419-
<< " wrong for " << objectClassName
1420-
<< " property " << this->getName()
1421-
<< "; ignoring.\n";
1415+
log_error("Object type {} wrong for {} property {}. Ignoring.", objTypeTag, objectClassName, this->getName());
14221416
continue;
14231417
}
14241418
++objectsFound;
@@ -1437,16 +1431,18 @@ ObjectProperty<T>::readFromXMLElement
14371431
}
14381432

14391433
if (objectsFound < this->getMinListSize()) {
1440-
std::cerr << "Got " << objectsFound
1441-
<< " object values for Property "
1442-
<< this->getName() << " but the minimum is "
1443-
<< this->getMinListSize() << ". Continuing anyway.\n";
1434+
log_error("Got {} object values for Property {} but the minimum is {}. Continuing anyway.",
1435+
objectsFound ,
1436+
this->getName() ,
1437+
this->getMinListSize()
1438+
);
14441439
}
14451440
if (objectsFound > this->getMaxListSize()) {
1446-
std::cerr << "Got " << objectsFound
1447-
<< " object values for Property "
1448-
<< this->getName() << " but the maximum is "
1449-
<< this->getMaxListSize() << ". Ignoring the rest.\n";
1441+
log_error("Got {} object values for Property {} but the maximum is {}. Ignoring the rest.",
1442+
objectsFound,
1443+
this->getName(),
1444+
this->getMaxListSize()
1445+
);
14501446
}
14511447
}
14521448

0 commit comments

Comments
 (0)