Skip to content

Conversation

@c-morley
Copy link
Collaborator

@c-morley c-morley commented Feb 4, 2023

This will allow the user to control the many debug messages sent to the terminal.
It uses qtvcp's logging library so no reinventing the wheel.
Other files should probably be converted to use logging too.

Resolves #2273

@c-morley c-morley requested a review from hansu February 4, 2023 05:39
@hansu
Copy link
Member

hansu commented Feb 4, 2023

Really great Chris, thank you! 👍 👍 👍
I also had in mind to use qtvcp's logger for gmoccapy, but I just didn't find the time to implement it.
Can you target the PR to this branch: https://github.com/LinuxCNC/linuxcnc/tree/gmoccapy-3-4-2 ?
Then I can add info to the change log and docs and merge to 2.9.

Copy link
Member

@hansu hansu left a comment

Choose a reason for hiding this comment

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

Great job in assigning the log levels! I agree in almost most of the cases, however, I have still some suggestions.

And the correct order of log levels is DEBUG, INFO, VERBOSE, WARNING, ERROR, CRITICAL, is that right?

And they can be only set like this, right?

[DISPLAY]
DISPLAY = gmoccapy -q

Maybe it would be good to have a LOG_LEVEL in the DISPLAY section as well.

logger.setGlobalLevel(logger.DEBUG)
LOG.debug('DEBUGGING logging on')
elif '-i' in sys.argv:
# Log level defaults to INFO, so set lower if in debug mode
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
# Log level defaults to INFO, so set lower if in debug mode
# Log level defaults to WARNING, so set lower if in debug mode

defaults to WARNING if I get it right?

What about a flag for CRITICAL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes i se the comments are wrong - copied from qtvcp and i changed the default level recently.
I'll need to fix them on qtvcp too. thanks

my opinion:
critical - in my mind if you have critical errors you should pretty much be logging then shutting down.
Having a critical log setting would block errors from showing. can't think of any reason you would want to hide errors.

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 4, 2023

Great job in assigning the log levels! I agree in almost most of the cases, however, I have still some suggestions.

And the correct order of log levels is DEBUG, INFO, VERBOSE, WARNING, ERROR, CRITICAL, is that right?

And they can be only set like this, right?

[DISPLAY]
DISPLAY = gmoccapy -q

Maybe it would be good to have a LOG_LEVEL in the DISPLAY section as well.

verbose, debug, info, warning, error, critical
unfortunately at the moment verbose works but does not say 'verbose' it says 'debug' and is the same color as debug.

LOG_LEVEL is more difficult because the log levels must be set before loading some libraries and before instantiating gmoccapy . Not impossible -just have to add code to parse the INI.
In the current suggestion it is consistent with qtvcp which is nice too.

i don;t know how to change the base branch - could you instruct me?

@hansu
Copy link
Member

hansu commented Feb 4, 2023

LOG_LEVEL is more difficult because the log levels must be set before loading some libraries and before instantiating gmoccapy . Not impossible -just have to add code to parse the INI. In the current suggestion it is consistent with qtvcp which is nice too.

Yeah but it's fine so. No problem if documented properly.

i don;t know how to change the base branch - could you instruct me?

You'll find the edit button for that at the top of this page:
grafik

@c-morley c-morley changed the base branch from 2.9 to gmoccapy-3-4-2 February 4, 2023 18:55
@c-morley
Copy link
Collaborator Author

c-morley commented Feb 4, 2023

Base has been changed, thanks !

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 4, 2023

I could squash together if you would prefer.

@hansu
Copy link
Member

hansu commented Feb 4, 2023

I could squash together if you would prefer.

Yeah would be nice. Have you any thoughts on my other comments?

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 4, 2023

I thin I have answered all comments - if I have missed one please ask me again or point them out.
If you are referring to some code changes, say changing from error to warning or such - I have no strong opinion - I just set them to what seemed reasonable in a 10 second look.
Feel free to change them to what ever you feel is best.
I'll squish the branch in a couple minutes.

This will allow the user to control the many debug messages sent to the terminal.
It uses qtvcp's logging library so no reinventing the wheel.
Other files should probably be converted to use logging too.
Ultimately it would be nice if gmoccapy and qtvcp used the same INI parsing code too.
@hansu hansu merged commit e8a2e2d into gmoccapy-3-4-2 Feb 4, 2023
@c-morley c-morley deleted the gmoccapy_logging branch February 4, 2023 22:09
@hansu
Copy link
Member

hansu commented Feb 6, 2023

@c-morley What does this mean?
[Gmoccapy][INFO] Base log level set to: 20 (logger.py:68)

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 7, 2023

That is the integer representation of the global log level.
It is in qtvcp/logger.py
I think we should remove it. Opinion?

@hansu
Copy link
Member

hansu commented Feb 7, 2023

Then it feels a bit redundant, because it says first "INFO logging on" and then this. (Didn't remember if what it prints for default - WARNING).
And using "Base" confused me a bit as well as switching to an integer representation.
So if really redundant, it can be removed. Otherwise use the log level name.

Another thing came into my mind while I had a look at the multi-line log messages. It would be nice if the output can be look like this:

[Gmoccapy][INFO] A long long long long long long long
                 long long message that goes over several lines.

Currently, it's only possible either so

[Gmoccapy][INFO] A long long long long long long long
long long message that goes over several lines.

or so

[Gmoccapy][INFO] A long long long long long long long
[Gmoccapy][INFO] long long message that goes over several lines.

First would be no problem if there were no other messages. For the second it's hard so see how many errors/warning there are actually.
(I mean, yes you can add the correct number of spaces - the logging domain would probably not change, so that would work, but inconvenient and a bit ugly 🙃)
I thought about something like this, so a function "newline" that adds as many spaces as the last prefix needed:

LOG.info("A long long long long long long long")
LOG.newline("long long message that goes over several lines.")

Dou you think that is a reasonable feature?

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 8, 2023

for LOG.newline()to be useful one would need LOG.info_newline() plus all the other log levels.
I am still having trouble with getting extra log levels to work properly.
you could use:
LOG.info("A long long long long long long long line\n and the rest of the long line line.")

@c-morley
Copy link
Collaborator Author

c-morley commented Feb 8, 2023

should be 8 spaces between \n and the 'and'

@hansu
Copy link
Member

hansu commented Feb 8, 2023

for LOG.newline()to be useful one would need LOG.info_newline() plus all the other log levels.

I thought about a static class variable that "remembers" the last used log level.

you could use:
LOG.info("A long long long long long long long line\n and the rest of the long line line.")
should be 8 spaces between \n and the 'and'

Yeah that's what I was meaning in the sentence inside the parantheses.

@hansu hansu mentioned this pull request Feb 9, 2023
@hansu
Copy link
Member

hansu commented Feb 9, 2023

Let's skip this. This seems to be too much work for a bit improvement in readability. Because in the log file there has to be added number of spaces...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants