-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: add pre-commit hook to enforce llama_stack.log logger #2868
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
chore: add pre-commit hook to enforce llama_stack.log logger #2868
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.
@leseb sorry, where should I use GH output 🤔 |
in the output, when printing the wrong files @mfleader wrote a similar script. |
ah u mean in the CI failure, like this
? |
a4f6d40
to
9ec2d01
Compare
e87d525
to
406e2b2
Compare
CI Failure is not related to this PR .. investigating |
e88db1f
to
5115801
Compare
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.
instead of the script, how about just use grep like forbid-pytest-asyncio.
something like grep -e "import logging" -e "from logging" | grep -v "allow-direct-logging
, then put import logging # allow-direct-logging
where appropriate
|
Agreed I don't see much value in Python here, bash is great for these sorts of simple things (and probably faster too). |
5115801
to
225f6e6
Compare
225f6e6
to
5837094
Compare
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.
lgtm
5b18f85
to
63f8408
Compare
63f8408
to
e5400d1
Compare
f2df8a1
to
ea2ec81
Compare
@leseb ptal 👍🏽 |
d18f45c
to
f24d136
Compare
llama_stack/core/build.py
Outdated
@@ -33,6 +31,8 @@ | |||
"opentelemetry-exporter-otlp-proto-http", | |||
] | |||
|
|||
logger = get_logger(name=__name__, category="core") |
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.
Please do not change the name of the variable; either log or logger is fine, I don't think the naming of the logger variable is something we want to enforce. This will also help reduce the size of the changes. Thanks!
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.
thanks for your review :)
either log or logger is fine,
lets keep logger
for now, we need to use get_logger(name=__name__, category="core")
anyways to use the new logger :)
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.
ah u meant to use log
instead of logger
where the logger
is being used to reduce the changes 👍🏽
make sense 👍🏽
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.
ptal 👍🏽
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 is still unresolved. Please do not resolve if not addressed.
f24d136
to
918a494
Compare
@@ -15,7 +15,7 @@ | |||
|
|||
REPO_ROOT = Path(__file__).parent.parent.parent.parent | |||
|
|||
logger = get_logger(name=__name__, category="server") | |||
log = get_logger(name=__name__, category="server") |
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.
yeah why this spurious change? please move it back to logger
as the variable name please.
It is extremely important that you don't add gratuitous changes when making PRs. Stick to the core thesis of the PR.
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.
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 am preserving this commit here for your ref.
This commit was using logger
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.
@Elbehery let me rephrase myself and be extremely clear.
This PR should only have changes which look like this:
- Change
import logging
tofrom llama_stack.log import get_logger
- Change a
X = logging.get_logger()
toX = get_logger(name=..., category=...)
There should be no other changes in the PR.
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.
lgtm 👍🏽
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.
raised #3060 👍🏽
918a494
to
bca65e6
Compare
…#2890) Our CI is entirely undocumented, this commit adds a README.md file with a table of the current CI and what is does --------- Signed-off-by: Nathan Weinberg <[email protected]>
bca65e6
to
b381ed6
Compare
if [ -n "$matches" ]; then | ||
# GitHub Actions annotation format | ||
while IFS=: read -r file line_num rest; do | ||
echo "::error file=$file,line=$line_num::Do not use 'import logging' or 'from logging import' in $file. Use the custom log instead: from llama_stack.log import get_logger; logger = get_logger(). If direct logging is truly needed, add: # allow-direct-logging" |
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.
@Elbehery Can you please also use log
here instead of logger
? Or some more neutral wording.
If you want to rename all instances from log
to logger
, please do this in a separate PR. It would be nice to reason about the benefits of such a cosmetic change that touches 92 files (and increases quite a bit the likelihood of rebase conflicts for other open PRs). There needs to be a very good reason for doing this. Personal taste is not one of these.
IMO, one should always assess the value of a change to the size of the change, which needs to be in balance. This is not the case here IMO as the value (logger
instead of log
) is negligible compared to the size of the change and the efforts for other to adapt to this change (it's not only open PR, but also people actively working right now on new feature who would need to rebase as well).
But if you detangle both concerns (add a recommit check vs. _rename all log
to logger
) into two separate PRs, then it makes it easier to get at least one of those included.
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.
thanks so much for your review 🙏🏽
makes perfect sense to me 👍🏽
I actually initally made the pre-commit
change in a separate commit than changing the logging
in the code base :)
I am fine with the renaming, and I can do it in a separate PR as you suggested
just could we agree on a name (i.e. log
or logger
)
thanks in advance
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.
raised #3060 👍🏽
args: | ||
- -c | ||
- | | ||
matches=$(grep -EnH '^[^#]*\b(import logging|from logging\b)' "$@" | grep -v '# allow-direct-logging' || true) |
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 could make the regexp more robust by allowing an arbitrary amount of spaces like with \s+
. Also you might want allow #allow-direct-logging
and # allow-direct-logging
, too (so maybe grep -v -e '#\s*allow-direct-logging')
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.
lgtm 👍🏽
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.
raised #3061 👍🏽
/hold |
replaced by #3061 |
# What does this PR do? <!-- Provide a short summary of what this PR does and why. Link to relevant issues if applicable. --> This PR renames categories of llama_stack loggers. This PR aligns logging categories as per the package name, as well as reviews from initial #2868. This is a follow up to #3061. <!-- If resolving an issue, uncomment and update the line below --> <!-- Closes #[issue-number] --> Replaces #2868 Part of #2865 cc @leseb @rhuss Signed-off-by: Mustafa Elbehery <[email protected]>
) # What does this PR do? <!-- Provide a short summary of what this PR does and why. Link to relevant issues if applicable. --> This PR renames categories of llama_stack loggers. This PR aligns logging categories as per the package name, as well as reviews from initial llamastack#2868. This is a follow up to llamastack#3061. <!-- If resolving an issue, uncomment and update the line below --> <!-- Closes #[issue-number] --> Replaces llamastack#2868 Part of llamastack#2865 cc @leseb @rhuss Signed-off-by: Mustafa Elbehery <[email protected]>
What does this PR do?
This PR adds enforce using
llama_stack.log
only.It creates
scripts/check-logger-usage.py
to enforce usingllama_stack.log
.- id: check-logger-usage
in .pre-commit-config.yaml.Fixes #2865
Test Plan