-
Notifications
You must be signed in to change notification settings - Fork 234
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
Improve logging #316
Improve logging #316
Conversation
There are two breaking changes:
|
Makefile
Outdated
@@ -34,7 +34,7 @@ pytest: | |||
.PHONY: black | |||
black: | |||
${DOCKER_COMPOSE} \ | |||
run nornir black --check . |
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.
why these changes?
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.
The current dockerfile is built in such a way that, it is mapping the whole project dir to the container, which causes the problems for my setup when I run tests... Decided to change to include directories explicitly when black should run.
I can change it back, but I'd strongly advocate to change volume mounting in docker-compose then.
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 that's the case let's discuss it in a separate PR to avoid noise
description="Logging format", | ||
) | ||
to_console: bool = Schema( | ||
default=False, description="Whether to log to console or not" | ||
) | ||
loggers: List[str] = Schema(default=["nornir"], description="Loggers to configure") |
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 don't think it was a widely used feature but the idea was to allow users to enable debugging in paramiko/netmiko/others without having to change the code. How do you envision that being done now and why was it removed?
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 remove it, because I didn't really understand what problem it solves. If you want to enable logging for other modules, you can do it with standard python logging (basicConfig, dictConfig or programmatically). I can put it back if you want, but I'd vote against it.
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.
Well, the point is that a developer builds a tool, deploys it in a management server and then the neteng folks (or other people) consume that tool, which is installed in the $PATH and don't have access to modify it, how would you enable netmiko's debug then because something is not going as expected? You could have the developer bake it in into its own application, and that'd be a valid answer, however, if there isn't a good reason to remove it at this point (like introducing an insurmountable amount of complexity) I'd gate it until nornir 3.0.0.
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.
You are saying that a neteng would change env var in this case? I don't think it will work for lists (may be I wrong here). Or you are saying that a neteng would need to change config.yaml
? If that is the case, how different it is from changing the logging setup in the entrypoint script, if both config.yaml
and the application code will be in VCS?
I do think you are onto something here and may be it is a valid use-case, however it needs to be described in our docs, because until you told it, I didn't even think about it.
format: str = Schema( | ||
default="%(asctime)s - %(name)12s - %(levelname)8s - %(funcName)10s() - %(message)s", | ||
default="[%(asctime)s] %(levelname)-8s {%(name)s:%(lineno)d} %(message)s", |
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.
breaking change, might break people's logging system
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.
How is it breaking? It's just the format of logs.
which best practices? Mostly want to look at them to remove my f-string comments or not :) There is a third breaking change, which is the format of the log. |
I am a bit concerned about this PR introducing so many breaking changes. I think we need to either have very good reasons for them, revert them or delay this to 3.0.0. @ktbyers thoughts? |
Ok, read a bit more about it and looks like the "recommended" method is just because it's a lazy evaluator for the string. I don't think we should be concerned about that as that's going to save us 0.0000000001us of execution time and I'd rather have readable strings but to avoid bikeshedding I will let ktbyers chime in and break the tie :) P.S: Removing the f-string comments for the sake of brevity |
I vote f-strings versus the % strings. I also vote if they are backwards incompatible that we defer until Nornir 3.0 (or maybe some way to specify new-logging format in Nornir-config that then becomes the default in Nornir 3.0)? Disclaimer: I have mostly been out of the loop on this and only loosely following it. |
Those are not really % strings as % strings are interpolated at declaration time, the syntax is I am honestly not sure about "breaking changes" and 3.0:
|
Okay, so it really just arguments that are passed to the logging subsystem. Here is more discussion on pylint doing this (which wasn't very well received): Looks like we can just disable that warning in Pylint. |
Why that change?
I still think readability wins over this supposedly perf improvement, specially when the perf improvements is going to be measured in microseconds while nornir's application are mostly going to be bound by IO and measured in ms. So whatever kirk says as he is the one breaking the tie :)
I already commented on the reasoning, and I am fine deprecating it in nornir 3 if we decide the benefits don't overweight the complexity but without a very good reason we shouldn't introduce breaking changes as per semver rules
I agree, notice it's not nornir who is doing that, it's
For people sending logs to a logging system and parsing the logs to build dashboards it's going to be breaking change. |
requirements.txt
Outdated
@@ -7,4 +7,4 @@ future | |||
requests | |||
ruamel.yaml | |||
mypy_extensions | |||
pydantic | |||
pydantic==0.16.1 |
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.
don't forget to rebase as new develop uses poetry :)
To make it clear that it is not filename it is a path. I will return it back.
We have every single example with
The current setup does not add Syslog handler at all... Do you want me to remove it back anyway? Something that I didn't see in your comments so far. Could you please go through 4 conditions when nornir logging is not configured and confirm that they are all right? I think first two completely make sense, but for the last two where I decide based on the root logger config there can be some disagreement. |
Yeah, sorry, I was meant to comment on that and lost my train of thought. I don't want to add any logic here. I don't want to have to document under which circumstances the logging subsystem is configured automagically or have to answer support questions about that. So let's recover the old |
I can find a way to convert it to a non-breaking change
If I remove that, what does this PR solve? One of my problems with |
My understanding is that, besides the breaking changes, you are doing some general cleaning and improvements as well. For instance, getting rid of the duplicates.
I don't see that as a problem. You have the option today of using either way, we are not forcing anyone to use nornir's logging helper function.
If it's not properly documented let's fix that.
In general, instead of taking arbitrary decisions (which the user may or may not want), I'd suggest logging warning. |
Does this PR also address the duplicate log entries in the logfile that are poduced?? |
@bradh11 yes |
@dmfigol let us know when this is ready for review again. If we get this one sorted out this week I will release 2.1. |
c59a927
to
52b7cd4
Compare
I will try to find some time during the weekend. Thanks for the work :) |
@@ -73,34 +73,9 @@ | |||
}, |
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.
did this break?
Ok, this looks awesome to me. The only comment is related to the notebook that seems to have lost the output. Can you confirm that's expected? Feels broken to me. Once we clear that out I will merge this :) Awesome work. |
Fix nornir-automation#302, nornir-automation#230 * Nornir logging is configured only when no changes have been done to Python logging * No more duplicate logs * Replace format and f-strings in logs to % strings according to best practices * Improved messages for some logs
* Add .ipynb_checkpoints to sphinx ignored list * Run black and pylama on specific folders * Pin pydantic until 0.19.0 is released pydantic/pydantic#254
@dbarrosop |
Good catch :) |
Fix #302, #230
InitNornir
configure_logging
parameter is deprecated, replaced withconfig.logging.enabled
TODO: