Skip to content

Commit c0dbf4c

Browse files
authored
--[BE Week] Minimize logging spam (#2140)
* --change default level to warning instead of debug * --demote inappropriate warning messages to debug level. * --fix test * --address faulty error message when attempting to get default light setup. * --make scene instance load messages more lucid and at appropriate level * --add message level/type to message In decreasing severity order : 'Error', 'Warning', 'Debug', 'Verbose' * --"Message" -> "Verbose"
1 parent 30cf309 commit c0dbf4c

15 files changed

Lines changed: 383 additions & 266 deletions

src/esp/core/Logging.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ LoggingLevel levelFromName(const Corrade::Containers::StringView name) {
5555
CASE(VeryVerbose, veryverbose);
5656
CASE(Verbose, verbose);
5757
CASE(Debug, debug);
58+
CASE(Default, default);
5859
CASE(Warning, warning);
5960
CASE(Quiet, quiet);
6061
CASE(Error, error);
@@ -137,6 +138,7 @@ bool isLevelEnabled(Subsystem subsystem, LoggingLevel level) {
137138
}
138139

139140
Cr::Containers::String buildMessagePrefix(Subsystem subsystem,
141+
const std::string& msgLevel,
140142
const std::string& filename,
141143
const std::string& function,
142144
int line) {
@@ -154,9 +156,10 @@ Cr::Containers::String buildMessagePrefix(Subsystem subsystem,
154156
std::tm timeNow = *std::localtime(&t);
155157

156158
return Cr::Utility::formatString(
157-
"[{:.02d}:{:.02d}:{:.02d}:{:.06d}]:[{}] {}({})::{} : ", timeNow.tm_hour,
158-
timeNow.tm_min, timeNow.tm_sec, nowMicros.count(),
159-
subsystemNames[uint8_t(subsystem)], baseFileName, line, function);
159+
"[{:.02d}:{:.02d}:{:.02d}:{:.06d}]:[{}]:[{}] {}({})::{} : ",
160+
timeNow.tm_hour, timeNow.tm_min, timeNow.tm_sec, nowMicros.count(),
161+
msgLevel, subsystemNames[uint8_t(subsystem)], baseFileName, line,
162+
function);
160163
}
161164

162165
} // namespace logging

src/esp/core/Logging.h

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,43 @@ namespace logging {
122122
* greater than or equal to the logging level within that subsystem, the log
123123
* will be printed.
124124
*
125-
* The convience levels, @ref Verbose and @ref Quiet are the primary user facing
126-
* options. @ref Quiet turns off logging and @ref Verbose is the default and
127-
* shows things that are generally useful. These names exist such that logging
128-
* levels can be added and removed without users needed to change what they set
129-
* logging to.
125+
* The convenience levels, @ref Verbose, @ref Default and @ref Quiet are the primary user facing
126+
* options. @ref Quiet turns off logging for all but errors, @ref Default is the default and
127+
* shows warnings and errors, while @ref Verbose gives debug messages along with warnings and
128+
* errors. These names exist such that logging levels can be added and removed
129+
* without users needing to change what they set logging to.
130130
*/
131131
enum class LoggingLevel : uint8_t {
132+
/**
133+
* Logging level to be used to provide in depth information about a process
134+
* and its result.
135+
*/
132136
VeryVerbose,
137+
138+
/**
139+
* Logging level to be used to specify the result of some process.
140+
*/
133141
Debug,
142+
/**
143+
* Logging level to be used to denote that some process has yielded a result
144+
* that may not be appropriate or expected.
145+
*/
134146
Warning,
147+
/**
148+
* Logging level to be used to denote that some process has failed.
149+
*/
135150
Error,
136151

137152
/**
138-
* The default logging level. Enables all logging except for the most verbose
139-
* statements. Habitat-Sim will be fairly verbose in this setting, but not
140-
* overly so.
141-
*
142-
* Note: If you add another level that is lower priority than Debug but should
143-
* be on by default or Debug is removed/renamed, this will need to be updated.
153+
* Enables all logging except for the most verbose statements. Habitat-Sim
154+
* will be fairly verbose in this setting, but not overly so.
144155
*/
145156
Verbose = Debug,
157+
/**
158+
* The default logging level. Enables all warning and error messages but hides
159+
* debug and verbose messages.
160+
*/
161+
Default = Warning,
146162
/**
147163
* Turns of all non-critical logging messages, i.e. those that indicate that
148164
* something has gone wrong.
@@ -165,7 +181,7 @@ LoggingLevel levelFromName(Corrade::Containers::StringView name);
165181
class LoggingContext {
166182
public:
167183
constexpr static const char* LOGGING_ENV_VAR_NAME = "HABITAT_SIM_LOG";
168-
constexpr static LoggingLevel DEFAULT_LEVEL = LoggingLevel::Verbose;
184+
constexpr static LoggingLevel DEFAULT_LEVEL = LoggingLevel::Default;
169185

170186
/**
171187
* @brief Convenience constructor that grabs the configuration string from the
@@ -246,6 +262,7 @@ bool isLevelEnabled(Subsystem subsystem, LoggingLevel level);
246262
* subsystem/namespace, file, line number and function name
247263
*/
248264
Corrade::Containers::String buildMessagePrefix(Subsystem subsystem,
265+
const std::string& msgLevel,
249266
const std::string& filename,
250267
const std::string& function,
251268
int line);
@@ -304,10 +321,10 @@ class LogMessageVoidify {
304321

305322
// This ends with a nospace since the space is baked in to subsystemPrefix for
306323
// the case that the logger was created with a nospace flag.
307-
#define ESP_SUBSYS_LOG_IF(subsystem, level, output) \
308-
ESP_LOG_IF(esp::logging::isLevelEnabled((subsystem), (level)), (output)) \
309-
<< esp::logging::buildMessagePrefix((subsystem), (__FILE__), \
310-
(__FUNCTION__), (__LINE__)) \
324+
#define ESP_SUBSYS_LOG_IF(subsystem, level, output, levelMsg) \
325+
ESP_LOG_IF(esp::logging::isLevelEnabled((subsystem), (level)), (output)) \
326+
<< esp::logging::buildMessagePrefix((subsystem), (levelMsg), (__FILE__), \
327+
(__FUNCTION__), (__LINE__)) \
311328
<< Corrade::Utility::Debug::nospace
312329

313330
#define ESP_LOG_LEVEL_ENABLED(level) \
@@ -320,25 +337,26 @@ class LogMessageVoidify {
320337
ESP_SUBSYS_LOG_IF( \
321338
espLoggingSubsystem(), esp::logging::LoggingLevel::VeryVerbose, \
322339
(Corrade::Utility::Debug{Corrade::Utility::Debug::defaultOutput(), \
323-
__VA_ARGS__}))
340+
__VA_ARGS__}), \
341+
"Verbose")
324342
/**
325343
* @brief Debug level logging macro.
326344
*/
327345
#define ESP_DEBUG(...) \
328346
ESP_SUBSYS_LOG_IF(espLoggingSubsystem(), esp::logging::LoggingLevel::Debug, \
329-
Corrade::Utility::Debug{__VA_ARGS__})
347+
Corrade::Utility::Debug{__VA_ARGS__}, "Debug")
330348
/**
331349
* @brief Warning level logging macro.
332350
*/
333351
#define ESP_WARNING(...) \
334352
ESP_SUBSYS_LOG_IF(espLoggingSubsystem(), \
335353
esp::logging::LoggingLevel::Warning, \
336-
Corrade::Utility::Warning{__VA_ARGS__})
354+
Corrade::Utility::Warning{__VA_ARGS__}, "Warning")
337355
/**
338356
* @brief Error level logging macro.
339357
*/
340358
#define ESP_ERROR(...) \
341359
ESP_SUBSYS_LOG_IF(espLoggingSubsystem(), esp::logging::LoggingLevel::Error, \
342-
Corrade::Utility::Error{__VA_ARGS__})
360+
Corrade::Utility::Error{__VA_ARGS__}, "Error")
343361

344362
#endif // ESP_CORE_LOGGING_H_

src/esp/metadata/MetadataMediator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ MetadataMediator::makeSceneAndReferenceStage(
328328
ESP_CHECK(datasetAttr != nullptr && stageAttributes != nullptr &&
329329
dsSceneAttrMgr != nullptr,
330330
"Missing (at least) one of scene dataset attributes, stage "
331-
"attributes, or dataset scene attributes for scene '"
331+
"attributes, or scene instance attributes for scene '"
332332
<< Mn::Debug::nospace << sceneName << Mn::Debug::nospace
333333
<< "'. Likely an invalid scene name.");
334334
// create scene attributes with passed name

src/esp/metadata/attributes/SceneDatasetAttributes.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool SceneDatasetAttributes::addNewSceneInstanceToDataset(
7474
// should only be empty if not specified in scene instance config, or if scene
7575
// instance config is synthesized (i.e. when Simulator::reconfigure is called
7676
// with SimulatorConfiguration::activeSceneName being a stage)
77-
if (lightHandle.length() == 0) {
77+
if (lightHandle.empty()) {
7878
lightHandle = sceneInstanceName;
7979
}
8080

@@ -132,16 +132,15 @@ std::pair<std::string, std::string> SceneDatasetAttributes::addNewValToMap(
132132
} while (map.count(newKey) > 0);
133133
ESP_WARNING(Mn::Debug::Flag::NoSpace)
134134
<< descString << " : Provided key '" << key
135-
136-
<< "' already references a different value in "
137-
"map. Modifying key to be"
135+
<< "' already references a different value in map. Modifying key "
136+
"to be '"
138137
<< newKey
139-
<< ". Set overwrite to true to overwrite existing entries.";
138+
<< "'. Set overwrite to true to overwrite existing entries.";
140139
} else { // overwrite entry
141-
ESP_WARNING() << descString
142-
<< ": Warning : Overwriting existing map entry"
143-
<< map.at(newKey) << "at key" << newKey << "with value"
144-
<< path << ".";
140+
ESP_WARNING(Mn::Debug::Flag::NoSpace)
141+
<< descString << " : Overwriting existing map entry "
142+
<< map.at(newKey) << " at key '" << newKey << "' with value'"
143+
<< path << "'.";
145144
} // overwrite or not
146145
} // found entry is desired or not
147146
} // key is found

src/esp/metadata/managers/AbstractObjectAttributesManagerBase.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,18 @@ auto AbstractObjectAttributesManager<T, Access>::createObject(
174174
// this is a primitive-based object we are building
175175
attrs = this->createPrimBasedAttributesTemplate(attributesTemplateHandle,
176176
registerTemplate);
177-
msg = "Primitive Asset (" + attributesTemplateHandle + ") Based";
177+
if (ESP_LOG_LEVEL_ENABLED(logging::LoggingLevel::Debug)) {
178+
msg = "Primitive Asset (" + attributesTemplateHandle + ") Based";
179+
}
178180
} else {
179181
attrs = this->createFromJsonOrDefaultInternal(attributesTemplateHandle, msg,
180182
registerTemplate);
181183

182184
} // if this is prim else
183185
if (nullptr != attrs) {
184-
ESP_DEBUG() << msg << this->objectType_ << "attributes created"
185-
<< (registerTemplate ? "and registered." : ".");
186+
ESP_DEBUG(Mn::Debug::Flag::NoSpace)
187+
<< msg << " " << this->objectType_ << " attributes created"
188+
<< (registerTemplate ? " and registered." : ".");
186189
}
187190
return attrs;
188191

src/esp/metadata/managers/AssetAttributesManager.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ AssetAttributesManager::AssetAttributesManager()
110110
}
111111

112112
ESP_DEBUG() << "Built default primitive asset templates :"
113-
<< std::to_string(defaultPrimAttributeHandles_.size());
113+
<< defaultPrimAttributeHandles_.size();
114114
} // AssetAttributesManager::ctor
115115

116116
AbstractPrimitiveAttributes::ptr AssetAttributesManager::createObject(
@@ -137,16 +137,18 @@ AssetAttributesManager::createTemplateFromHandle(
137137
std::size_t nameEndLoc = templateHandle.find('_');
138138
if (nameEndLoc == std::string::npos) {
139139
// handle is of incorrect format
140-
ESP_ERROR() << "Given template handle :" << templateHandle
141-
<< "is not the correct format for a primitive. Aborting.";
140+
ESP_ERROR(Mn::Debug::Flag::NoSpace)
141+
<< "Given template handle : `" << templateHandle
142+
<< "` is not the correct format for a primitive. Aborting.";
142143
return nullptr;
143144
}
144145
std::string primClassName = templateHandle.substr(0, nameEndLoc);
145146
if (primTypeConstructorMap_.count(primClassName) == 0) {
146147
// handle does not have proper primitive tyep encoded
147-
ESP_ERROR() << "Requested primitive type :" << primClassName
148-
<< "from given template handle :" << templateHandle
149-
<< "is not a valid Magnum::Primitives class. Aborting.";
148+
ESP_ERROR(Mn::Debug::Flag::NoSpace)
149+
<< "Requested primitive type : `" << primClassName
150+
<< "` from given template handle : `" << templateHandle
151+
<< "` is not a valid Magnum::Primitives class. Aborting.";
150152
return nullptr;
151153
}
152154
// create but do not register template for this prim class, since it will be
@@ -156,12 +158,13 @@ AssetAttributesManager::createTemplateFromHandle(
156158
if (templateHandle.length() > 0) {
157159
bool success = primAssetAttributes->parseStringIntoConfig(templateHandle);
158160
if (!success) {
159-
ESP_WARNING() << "Prim Asset Attributes :" << primClassName
160-
<< "failed parsing config string : `" << templateHandle
161-
<< "`. Providing" << primClassName
162-
<< "template configured as closely as possible with "
163-
"requested values, named"
164-
<< primAssetAttributes->getHandle() << ".";
161+
ESP_WARNING(Mn::Debug::Flag::NoSpace)
162+
<< "Prim Asset Attributes : `" << primClassName
163+
<< "` failed parsing config string : `" << templateHandle
164+
<< "`. Providing `" << primClassName
165+
<< "` template configured as closely as possible with requested "
166+
"values, named `"
167+
<< primAssetAttributes->getHandle() << "`.";
165168
}
166169
}
167170
return this->postCreateRegister(std::move(primAssetAttributes),
@@ -175,11 +178,10 @@ int AssetAttributesManager::registerObjectFinalize(
175178
std::string primAttributesHandle = primAttributesTemplate->getHandle();
176179
// verify that attributes has been edited in a legal manner
177180
if (!primAttributesTemplate->isValidTemplate()) {
178-
ESP_ERROR() << "Primitive asset attributes template named"
179-
<< primAttributesHandle
180-
<< "is not configured properly for specified prmitive"
181-
<< primAttributesTemplate->getPrimObjClassName()
182-
<< ". Aborting.";
181+
ESP_ERROR(Mn::Debug::Flag::NoSpace)
182+
<< "Primitive asset attributes template named `" << primAttributesHandle
183+
<< "` is not configured properly for specified prmitive `"
184+
<< primAttributesTemplate->getPrimObjClassName() << "`. Aborting.";
183185
return ID_UNDEFINED;
184186
}
185187

@@ -204,19 +206,21 @@ AbstractPrimitiveAttributes::ptr AssetAttributesManager::buildObjectFromJSONDoc(
204206
// if not legal primitive asset attributes file name, have message and
205207
// return default sphere attributes.
206208
if (defaultPrimAttributeHandles_.count(primClassName) == 0) {
207-
ESP_ERROR() << "Unknown primitive class type :" << primClassName
208-
<< "so returning default attributes for solid uvSphere.";
209+
ESP_ERROR(Mn::Debug::Flag::NoSpace)
210+
<< "Unknown primitive class type : `" << primClassName
211+
<< "` so returning default attributes for solid uvSphere.";
209212
return this->getObjectCopyByHandle<attributes::UVSpherePrimitiveAttributes>(
210213
defaultPrimAttributeHandles_.at("uvSphereSolid"));
211214
}
212215

213216
// create attributes for the primitive described in the JSON file
214217
auto primAssetAttributes = this->initNewObjectInternal(primClassName, true);
215218
if (nullptr == primAssetAttributes) {
216-
ESP_ERROR() << "Unable to create default primitive asset attributes from "
217-
"primClassName"
218-
<< primClassName
219-
<< "so returning default attributes for solid uvSphere.";
219+
ESP_ERROR(Mn::Debug::Flag::NoSpace)
220+
<< "Unable to create default primitive asset attributes from "
221+
"primClassName `"
222+
<< primClassName
223+
<< "` so returning default attributes for solid uvSphere.";
220224
return this->getObjectCopyByHandle<attributes::UVSpherePrimitiveAttributes>(
221225
defaultPrimAttributeHandles_.at("uvSphereSolid"));
222226
}

src/esp/metadata/managers/AttributesManagerBase.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ void AttributesManager<T, Access>::buildAttrSrcPathsFromJSONAndLoad(
339339
const io::JsonGenericValue& filePaths) {
340340
for (rapidjson::SizeType i = 0; i < filePaths.Size(); ++i) {
341341
if (!filePaths[i].IsString()) {
342-
ESP_ERROR() << "Invalid path value in file path array element @ idx" << i
343-
<< ". Skipping.";
342+
ESP_ERROR() << "<" << this->objectType_
343+
<< "> : Invalid path value in file path array element @ idx"
344+
<< i << ". Skipping.";
344345
continue;
345346
}
346347
std::string absolutePath =
@@ -349,12 +350,14 @@ void AttributesManager<T, Access>::buildAttrSrcPathsFromJSONAndLoad(
349350
if (globPaths.size() > 0) {
350351
for (const auto& globPath : globPaths) {
351352
// load all object templates available as configs in absolutePath
352-
ESP_WARNING() << "Glob path result for" << absolutePath << ":"
353-
<< globPath;
353+
ESP_DEBUG() << "<" << this->objectType_ << "> : Glob path result for"
354+
<< absolutePath << ":" << globPath;
354355
this->loadAllTemplatesFromPathAndExt(globPath, extType, true);
355356
}
356357
} else {
357-
ESP_WARNING() << "No Glob path result for" << absolutePath;
358+
ESP_WARNING(Mn::Debug::Flag::NoSpace)
359+
<< "<" << this->objectType_ << "> : No Glob path result for "
360+
<< absolutePath << " so unable to load templates.";
358361
}
359362
}
360363
ESP_DEBUG(Mn::Debug::Flag::NoSpace)
@@ -385,7 +388,9 @@ auto AttributesManager<T, Access>::createFromJsonOrDefaultInternal(
385388
if (jsonFileExists) {
386389
// configuration file exists with requested name, use to build Attributes
387390
attrs = this->createObjectFromJSONFile(jsonAttrFileName, registerObj);
388-
msg = "JSON Configuration File (" + jsonAttrFileName + ") based";
391+
if (ESP_LOG_LEVEL_ENABLED(logging::LoggingLevel::Debug)) {
392+
msg = "JSON Configuration File (" + jsonAttrFileName + ") based";
393+
}
389394
} else {
390395
// An existing, valid configuration file could not be found using the
391396
// passed filename. Currently non-JSON filenames are used to create new,
@@ -395,12 +400,15 @@ auto AttributesManager<T, Access>::createFromJsonOrDefaultInternal(
395400
bool fileExists = Cr::Utility::Path::exists(filename);
396401
// if filename passed is name of some kind of asset, or if it was not
397402
// found
398-
if (fileExists) {
399-
msg = "File (" + filename +
400-
") exists but is not a recognized config filename extension, so "
401-
"new default";
402-
} else {
403-
msg = "File (" + filename + ") not found, so new default";
403+
if (ESP_LOG_LEVEL_ENABLED(logging::LoggingLevel::Debug)) {
404+
// only populate msg if appropriate logging level is enabled
405+
if (fileExists) {
406+
msg = "File (" + filename +
407+
") exists but is not a recognized config filename extension, so "
408+
"new default";
409+
} else {
410+
msg = "File (" + filename + ") not found, so new default";
411+
}
404412
}
405413
}
406414
return attrs;

0 commit comments

Comments
 (0)