Skip to content

Adding console output methods to some classes#872

Closed
pshriwise wants to merge 9 commits into
svalinn:developfrom
pshriwise:verbosity
Closed

Adding console output methods to some classes#872
pshriwise wants to merge 9 commits into
svalinn:developfrom
pshriwise:verbosity

Conversation

@pshriwise

Copy link
Copy Markdown
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.

Comment thread src/dagmc/DagMC.cpp Outdated
// 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
Copy Markdown
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

gonuke commented Mar 21, 2023

Copy link
Copy Markdown
Member

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

@pshriwise

Copy link
Copy Markdown
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

gonuke commented Mar 21, 2023

Copy link
Copy Markdown
Member

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

@gonuke

gonuke commented Mar 23, 2023

Copy link
Copy Markdown
Member

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

@gonuke gonuke left a comment

Copy link
Copy Markdown
Member

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

Comment thread src/dagmc/DagMC.hpp Outdated
return verbosity = val;
}

int get_verbosity(int val) { return verbosity; }

Copy link
Copy Markdown
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 thread src/dagmc/DagMC.hpp
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/dagmc/DagMC.hpp
if (lvl > verbosity) return;
// otherwise, display message
if (newline)
std::cout << msg << "\n";

Copy link
Copy Markdown
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;

@pshriwise pshriwise Apr 4, 2023

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/dagmc/dagmcmetadata.cpp Outdated
Comment thread src/dagmc/dagmcmetadata.cpp Outdated
@pshriwise

Copy link
Copy Markdown
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

gonuke commented Apr 4, 2023

Copy link
Copy Markdown
Member

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

gonuke commented Apr 4, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

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

@gonuke

gonuke commented Apr 4, 2023

Copy link
Copy Markdown
Member

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

gonuke commented May 1, 2023

Copy link
Copy Markdown
Member

I think this was superseded by #876

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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