Skip to content

Add dependency name in the logs #676

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

miry
Copy link
Contributor

@miry miry commented May 19, 2025

In certain cases, it's unclear which package causes an error during shard installation. These changes improves log messages by adding explicit package context.
The log will now indicate which package triggered the event.

Tophat

Fetching https://github.com/sija/retriable.cr.git
[retriable] git config --get remote.origin.mirror
[nbchannel] git fetch --all --quiet
[splay_tree_map] git fetch --all --quie
grafik

@miry miry force-pushed the logging-context-package-name branch from ba3b6ce to 43c1fca Compare May 19, 2025 14:15
@miry miry changed the title Add package name in the logs Add dependency name in the logs May 19, 2025
In certain cases, it can be unclear which debug log message is associated with which dependency,
where logs for multiple dependencies may appear in different order.
These changes improve log clarity by explicitly including the package name in relevant messages.
@miry miry force-pushed the logging-context-package-name branch from 43c1fca to 0e745bf Compare May 19, 2025 14:16
@miry miry marked this pull request as ready for review May 19, 2025 14:24
src/package.cr Outdated
cleanup_install_directory
Log.with_context do
Log.context.set package: name
Log.context.set version: report_version
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this for debugging purposes. I haven’t identified a use case for regular users yet, but I plan to use it to detect discrepancies between the expected and installed versions.

Let me know if I should keep it or not.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it's relevant.
But if we keep it, we should merge both into a single context assignment for efficiency.

Also, is there any reason you're using explicit set calls instead of passing the data to with_context? That'd be more concise.

Copy link
Contributor Author

@miry miry May 20, 2025

Choose a reason for hiding this comment

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

Also, is there any reason you're using explicit set calls instead of passing the data to with_context? That'd be more concise.

Good call - because the with_context(**kwargs) was introduced after crystal 1.0.0. I found there are still tests are runing against Crystal 1.0.0 that are failing. matrix

I thought to introduce patch for older version to support with_context(**kwargs).

crystal-lang/crystal#11517

Example of the failing step: https://github.com/miry/shards/actions/runs/15099018619/job/42437500620

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that's a good reason 😆
I like the idea of adding a polyfill for Crystal < 1.3.
However, it would be fine to keep a separate set call either.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

Some of these context assignment locations look odd.

The package context should be set when entering the scope of a specific package (e.g. in each interaction when iterating over some packages).
But often they're just an instance method on a resolver. I figure we should perhaps move some of these to the caller scopes.

@miry
Copy link
Contributor Author

miry commented May 20, 2025

Yeah, I have introduced some with_context for cases where there are currently no Log.debug statements in place, but those helped me debug using my custom Log statements.

It made me wonder whether I should introduce more logging steps for debugging purposes or remove those extra context statements.

@miry
Copy link
Contributor Author

miry commented May 20, 2025

@straight-shoota I have updated code a bit. It should have less context calls.

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.

2 participants