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

Adding console output methods to some classes #872

Closed
wants to merge 9 commits into from

Conversation

pshriwise
Copy link
Member

This is a step toward improved console logging in some of our classes. As described in #856, DAGMC and other classes in MOAB always write some output, which can conflict with output in downstream applications and cause confusion.

message, warning, and err_msg methods have been added to the dagmcMetaData and DagMC classes. Warnings and errors will always be written to screen. The message method allows a verbosity level to be associated with the message. The message will either be written to screen or not depending on the verbosity level set on the class instance. I've specified two levels of verbosity for now, but I'm open to a more fine grain set of verbosity levels down the line.

There's some duplicated code here, which could be improved. I'll look into abstracting these capabilieis into an object that both of the affected classes can inherit from perhaps.

Another thing I don't love about this is that a std::stringstream object needs to be created for messages where conversion of non-char/string types occurs via the streaming operator. There are other libraries like fmt that handle this more gracefully, but I'll leave that for an improvement in the future.

@@ -290,7 +288,7 @@ ErrorCode DagMC::remove_graveyard() {
// get the implicit complement, it's children will need updating
EntityHandle implicit_complement = 0;
rval = geom_tool()->get_implicit_complement(implicit_complement);
if (rval != MB_ENTITY_NOT_FOUND || rval != MB_SUCCESS) {
Copy link
Member

Choose a reason for hiding this comment

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

how did this ever work?

@gonuke
Copy link
Member

gonuke commented Mar 21, 2023

Did you mean this to be extended from #855 (which we should get back to)?

@pshriwise
Copy link
Member Author

Did you mean this to be extended from #855 (which we should get back to)?

Ugh no. Accidentally combined some stashed changes I think. Fixing...

@gonuke
Copy link
Member

gonuke commented Mar 21, 2023

I've merged #855, so maybe it will be easy to just rebase on that?

@gonuke
Copy link
Member

gonuke commented Mar 23, 2023

If you rebase we can probably more forward on this @pshriwise

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

A few attempts to tidy... can't help but feel that there is some other external solution we can import

return verbosity = val;
}

int get_verbosity(int val) { return verbosity; }
Copy link
Member

Choose a reason for hiding this comment

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

Why does this take an argument- seems confusing

Comment on lines 473 to 480
int set_verbosity(int val) {
int verbosity_max = 0;
int verbosity_min = 1;
if (val < verbosity_min || val > verbosity_max)
warning("Invalid verbosity value " + std::to_string(val) +
" will be set to nearest valid value.");
val = std::min(std::max(verbosity_min, val), verbosity_max);
return verbosity = val;
Copy link
Member

Choose a reason for hiding this comment

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

Unless my brain is missing something, this will always result in 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mm yeah mentally bit-flipped the initializer values at the beginning of this function.

if (lvl > verbosity) return;
// otherwise, display message
if (newline)
std::cout << msg << "\n";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::cout << msg << "\n";
std::cout << msg << std::endl;

Copy link
Member Author

@pshriwise pshriwise Apr 4, 2023

Choose a reason for hiding this comment

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

I think it's preferred to use a newline literal these days. Using std::endl will force the output buffer to flush and is more likely to cause garbled messages in concurrent applications, so I thought I'd start taking us in that direction.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could do it all in one go in a separate changeset though.

Copy link
Member

Choose a reason for hiding this comment

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

I thought it was preferred because it is platform independent (e.g. Windows carriage returns...). That's the only reason I suggested it.

src/dagmc/dagmcmetadata.cpp Outdated Show resolved Hide resolved
src/dagmc/dagmcmetadata.cpp Outdated Show resolved Hide resolved
@pshriwise
Copy link
Member Author

Thanks for the review @gonuke! Not sure why the Housekeeping/Linux tests are failing at this point. Something about git permissions in the CI image. Made an attempt at addressing it, but no luck yet. I'll try to revisit it later if I have time.

@gonuke
Copy link
Member

gonuke commented Apr 4, 2023

The failing the linux builds is something annoying that I was sure we had resolved many months ago. Not sure why it's coming up again.

@gonuke
Copy link
Member

gonuke commented Apr 4, 2023

I made a quick scan for logging libraries and didn't find anything compelling - all a little heavier weight than I'd like.

Do you think we could write a header-only small class that would do this and include it in the relevant places?

@pshriwise
Copy link
Member Author

We certainly could! I don't have the cycles to do so at the moment though

@gonuke
Copy link
Member

gonuke commented Apr 4, 2023

We certainly could! I don't have the cycles to do so at the moment though

Let me see how I might adapt what you have done in that way

@gonuke gonuke mentioned this pull request Apr 5, 2023
@gonuke
Copy link
Member

gonuke commented May 1, 2023

I think this was superseded by #876

@@ -49,7 +49,7 @@ jobs:
- name: Checkout repository

Choose a reason for hiding this comment

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

I think this may fix the linux build test failure

Suggested change
- name: Checkout repository
- name: Add exception for dubious ownership
run: git config --global --add safe.directory /__w/DAGMC/DAGMC
- name: Checkout repository

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, but I think this PR has been replaced by another ( #876 ), so will be close by @pshriwise soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct! Closing now.

@pshriwise
Copy link
Member Author

Closing in favor of #876. @ahnaf-tahmid-chowdhury, if the changes you've suggested above apply in that PR as well would you mind adding them there also?

@pshriwise pshriwise closed this May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants