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

Changing verboseprint into logger #195

Merged
merged 16 commits into from
Oct 5, 2021

Conversation

Will-Cooper
Copy link
Member

Now the only changes are so when you create a new function have a line saying:

verbose = VerbosePrint(verbose)

then you can use

verbose.print('your', 'message')

@Will-Cooper Will-Cooper self-assigned this Sep 23, 2021
@kelle
Copy link
Collaborator

kelle commented Sep 23, 2021

Sorry, could you be more explicit? Every function needs the 'verbose = VerbosePrint(verbose)' line in it, correct?

And how would I use this for table.pprint_all()? What I was doing before, which stopped working, was:

if verobse:
     table.pprint_all()

@Will-Cooper
Copy link
Member Author

Sorry, could you be more explicit? Every function needs the 'verbose = VerbosePrint(verbose)' line in it, correct?

Yep precisely that, if every function is constructed with the keyword argument verbose=True/False then within that function you create an instance of the class VerbosePrint with verbose = VerbosePrint(verbose), which constructs the class instance (verbose) using the boolean value of verbose from the function keywords.
Then whenever you want to print something just call verbose.print('string') as you would treat print normally -- however it will only actually print if the class instance was initialised with verbose=True.

And how would I use this for table.pprint_all()? What I was doing before, which stopped working, was:

if verobse:
     table.pprint_all()

I've added this in, similarly to verbose.print above, just call verbose.pprint_all(<table_name>) -- that'll only call the astropy table method pprint_all on the provided <table_name> if the instance was initialised with verbose=True.

@dr-rodriguez
Copy link
Collaborator

I don't like us using verbose to both be a variable of type boolean and a class/object name. It's far too easy to get mixed up and think verbose is True/False when it is sometimes an object.
Can one use the old verboseprint and do something like print = verboseprint(verbose=True)? Wouldn't that be easier as it overwrites print to be the new verboseprint function?

@Will-Cooper
Copy link
Member Author

Possibly, and I agree for sure with having a different named variable: one for the Boolean switch, one for the instance.
I also like the idea of having pprint_all as a method so one doesn't have to repeatedly use

if verbose:
    table.pprint_all()

@Will-Cooper
Copy link
Member Author

huh the comment for that last commit is supposed to say:
rename verbose switch to isverbose

@Will-Cooper
Copy link
Member Author

Convert this into a logger function with debug and info levels

@Will-Cooper Will-Cooper changed the title Changing verboseprint into class Changing verboseprint into logger Sep 29, 2021
@Will-Cooper
Copy link
Member Author

I noticed in the tests that the logger messages weren't appearing, not sure what scripts to run to try the different levels e.g.

logger.getLogger().setLevel = <logger.DEBUG/logger.INFO>

Essentially, having someone able to dynamically change the level of the logging whilst pulling in utils functions; ideas @dr-rodriguez?

Related: Any scripts which use the utils functions which change the kwarg verbose will need updating as I removed that from the functions.

@dr-rodriguez
Copy link
Collaborator

I noticed in the tests that the logger messages weren't appearing, not sure what scripts to run to try the different levels e.g.

logger.getLogger().setLevel = <logger.DEBUG/logger.INFO>

Essentially, having someone able to dynamically change the level of the logging whilst pulling in utils functions; ideas @dr-rodriguez?

So, because logging is configured by the user it's something that they get to control and it's likely pytest has some defaults for the logging level and the outputs of them, since it could be it prints info/debug to stdout but warning/error to stderr. We may just need to play around with setting the level in the tests as well.

Copy link
Collaborator

@dr-rodriguez dr-rodriguez left a comment

Choose a reason for hiding this comment

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

While this looks good, I recommend we avoid using ''.join(map(str, [])) We don't need the added complexity for what we're doing and it makes the code far less readable. Stick to using f-strings, which we already had in some cases.

@Will-Cooper Will-Cooper merged commit 630e368 into SIMPLE-AstroDB:main Oct 5, 2021
@Will-Cooper Will-Cooper deleted the verboseprint branch October 5, 2021 17:27
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