-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Logging] Expand logging output information #1431
[Logging] Expand logging output information #1431
Conversation
src/esp/core/logging.cpp
Outdated
int line) { | ||
auto baseFileName = Cr::Utility::Directory::filename(filename); | ||
return ""_s.join({"["_s, subsystemNames[uint8_t(subsystem)], "] "_s, | ||
baseFileName.c_str(), "("_s, std::to_string(line).c_str(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you include #include <Corrade/Containers/StringStl.h>
you can get rid of the c_str()
calls which will avoid a std::strlen
call.
@@ -25,8 +25,7 @@ SceneDatasetAttributes::SceneDatasetAttributes( | |||
bool SceneDatasetAttributes::addNewSceneInstanceToDataset( | |||
const attributes::SceneAttributes::ptr& sceneInstance) { | |||
// info display message prefix | |||
const std::string infoPrefix("::addNewSceneInstanceToDataset : Dataset : '" + | |||
getSimplifiedHandle() + "' : "); | |||
const std::string infoPrefix("Dataset : '" + getSimplifiedHandle() + "' : "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This is going to require 3 reallocations of the prefix in the constructor of the String. Should all be std::string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable to me. Adding this extra detail should be worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
auto baseFileName = Cr::Utility::Directory::filename(filename); | ||
return ""_s.join({"["_s, subsystemNames[uint8_t(subsystem)], "] "_s, | ||
baseFileName, "("_s, std::to_string(line), ")::"_s, | ||
function, " : "_s}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jturner65 I was just browsing through some code and came across this -- the following should be significantly more performant, without temporary string allocations for filename
, function
and line
(it returns a std::string
now instead of a String
, yes, making that consistent is on my tech debt task pile):
std::string buildMessagePrefix(Subsystem subsystem,
const char* filename,
const char* function,
int line) {
auto baseFileName = Cr::Utility::Directory::filename(filename);
return Utility::formatString("[{}] {}({})::{} : ", subsystemNames[uint8_t(subsystem)],
baseFileName, line, function);
}
FYI there's also CORRADE_FUNCTION and CORRADE_LINE_STRING, in case you'd ever need a portable function name or stringified line number.
Also, certain terminals and IDEs (KDE's Konsole, VS Code, ...) allow you to click on the filename if you include a reasonable part of the path, and even can jump directly to given line number if you format it as <filename>:<line>
(which is the format used by GCC messages, GDB, CMake and other tools). So if you want an extra bit of convenience you might want to keep the path and reformat the output slightly. For example this I have in TestSuite, the failure location leads me directly to the line in the editor if I click on it:
Motivation and Context
The new logging functionality printed log messages that were somewhat arcane, lacking source information outside of what subsystem/namespace the log was being printed from (forcing the consumer call to include information like source method) :
[Metadata] <Dataset>::createFromJsonOrDefaultInternal : Proposing JSON name : default.scene_dataset_config.json from original name : default | This file does not exist.
This PR improves this by adding the source file (without path), the line number and the source function within which the logging macro call was executed :
[Metadata] AttributesManagerBase.h(360)::createFromJsonOrDefaultInternal : <Dataset>: Proposing JSON name : default.scene_dataset_config.json from original name : default | This file does not exist.
The majority of the other file changes are just removing the now redundant references to calling function names that were ubiquitous in the logging calls, particularly in the metadata subsystem, having been added to provide this functionality that was lacking in glog also.
How Has This Been Tested
Existing C++ and python tests pass locally. Logging test was modified to match new output format.
Types of changes
Checklist