-
Notifications
You must be signed in to change notification settings - Fork 946
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 configurability #1409
Logging configurability #1409
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see an argument for changing the log layout, but we need to secure that the default_format is not overwritten if level=DEBUG. We need a specific format of the log when people open new issues. I have a small script I use on the log (here and e.g. in homeassistant) which help me extract the information I need, with an unknown format I have to that manually.
Thanks for the review! 👍
The
Fwiw, it already says this in the docstring of Would you like me to add a comment on this to the issue template too? |
I am not talking about changing docstrings. It is possible to change the layout of the log, this should not be permitted for level=DEBUG. I suppose you want it configurable to match what you use in the application, this is a fair argument for log levels != DEBUG. It correspond to not calling pymodbus_apply_logging_config(). The main reason for level = DEBUG is to report an issue and for that the format must be fixed, in order for you not to change the program it needs to be done in pymodbus_apply_logging_config(). |
Okay I hear what you're saying. The thing is, I actually use debug logging for a whole instrument ( |
"format": "%(asctime)s %(levelname)-5s %(module)s:%(lineno)s %(message)s", | ||
"datefmt": "%H:%M:%S", | ||
} | ||
config_kwargs = {**default_config, **config_overrides} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still allows to overwrite DEBUG. You are actually a good example, if you overwrite DEBUG, you are not able to submit issues, without somehow changing the overwrite.
In your case it would be a lot simpler, not to call our function, but do
pymodbus.Log.LOG_LEVEL = <what you want>
A small change in the Log class could actually avoid that, by moving that line into build_msg.
have LOG_LEVEL = None
and do:
if not cls.LOG_LEVEL:
cls.LOG_LOVEL = cls…….
IF you do not call our function your basic_config will rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not cls.LOG_LEVEL: cls.LOG_LOVEL = cls…….
I don't quite understand this part. What does the None
sentinel level mean?
Does this go into build_msg
or apply_logging_config
, and where within that method? Why is it mutating the Log.LOG_LEVEL
if cls.LOG_LEVEL = None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you do not call apply_logging_config, cls.LOG_LEVEL still need to be set.
cls.LOG_LEVEL starts of being None, to secure it is set to effective log level, first time build_msg is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cls.LOG_LEVEL
will fail because None
comparisons in checks like this logging.INFO >= cls.LOG_LEVEL
will fail as a TypeError
before we even get to build_msg
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it will not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> logging.INFO >= None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '>=' not supported between instances of 'int' and 'NoneType'
I don't understand what you mean, I am sorry.
Looks like you merged an upstream PR that basically nullifies the core of this PR. @janiversen I am ready to abandon this, up to you. |
your PR so it’s your decision not mine. I merged a PR with some pending cleanup, but it does not have support for overwriting the configuration. |
Closing since upstream no longer uses |
logging.basicConfig
parameters