Skip to content
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

Merged
merged 5 commits into from
Aug 11, 2021

Conversation

jturner65
Copy link
Contributor

@jturner65 jturner65 commented Aug 10, 2021

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

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Aug 10, 2021
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(),
Copy link
Contributor

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() + "' : ");
Copy link
Contributor

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

Copy link
Contributor

@erikwijmans erikwijmans left a 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.

Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jturner65 jturner65 merged commit 0f1aaeb into facebookresearch:master Aug 11, 2021
@jturner65 jturner65 deleted the LOG_ExpandLogging branch August 11, 2021 01:21
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});
Copy link
Collaborator

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:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants