chore: add pre-commit hook to enforce llama_stack.log logger#2868
chore: add pre-commit hook to enforce llama_stack.log logger#2868Elbehery wants to merge 1 commit intollamastack:mainfrom
Conversation
@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
mattf
left a comment
There was a problem hiding this comment.
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
5b18f85 to
63f8408
Compare
63f8408 to
e5400d1
Compare
f2df8a1 to
ea2ec81
Compare
|
@leseb ptal 👍🏽 |
d18f45c to
f24d136
Compare
llama_stack/core/build.py
Outdated
| "opentelemetry-exporter-otlp-proto-http", | ||
| ] | ||
|
|
||
| logger = get_logger(name=__name__, category="core") |
There was a problem hiding this comment.
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.
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.
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.
This is still unresolved. Please do not resolve if not addressed.
f24d136 to
918a494
Compare
| 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.
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.
There was a problem hiding this comment.
i am preserving this commit here for your ref.
This commit was using logger
There was a problem hiding this comment.
@Elbehery let me rephrase myself and be extremely clear.
This PR should only have changes which look like this:
- Change
import loggingtofrom 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.
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 <nweinber@redhat.com>
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.
@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.
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
| args: | ||
| - -c | ||
| - | | ||
| matches=$(grep -EnH '^[^#]*\b(import logging|from logging\b)' "$@" | grep -v '# allow-direct-logging' || true) |
There was a problem hiding this comment.
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')
|
/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 <melbeher@redhat.com>
) # 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 <melbeher@redhat.com>
What does this PR do?
This PR adds enforce using
llama_stack.logonly.It creates
scripts/check-logger-usage.pyto enforce usingllama_stack.log.- id: check-logger-usagein .pre-commit-config.yaml.Fixes #2865
Test Plan