Skip to content

Conversation

@machshev
Copy link
Collaborator

@machshev machshev commented Sep 25, 2025

The purpose of this PR is twofold:

  • Move the logging setup out of the cli main - this will simplify the main function and help later refactoring.
  • Standardise logging over the codebase - there is a lot of default logger use which is bad.

Python programs and especially libraries should not use the default logger but create a logger instance. If you use the default logger, then setting the log level for example would set the log level for any 3rd party libraries used (polluting the logs and making them difficult to read). Typically a logger instance would would be crated at module level with something like logger = logging.getLogger(__name__). For the moment though, lets start with something simpler and make it more complicated later if desired.

The LOG015 lint rule checks for default logger use instances. In the DVSim codebase that accounts for 129 instances (out of 1128 lint fails). With this PR the total lint fails is reduced to a mere 968 ;)

Simplify the cli main function by pulling out the logging setup. The cli
function is more difficualt to test, the more we can full out the easier
it is to test.

Signed-off-by: James McCorrie <[email protected]>
@machshev
Copy link
Collaborator Author

It looks like later versions of ruff have introduced some extra linting rules that now fail. I've added a commit that resolves the failed lints, although not directly related to this PR.

Copy link
Contributor

@rswarbrick rswarbrick left a comment

Choose a reason for hiding this comment

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

These look like nice cleanups! It's lovely to see things getting more solid.

Simplify logging with a custom logger. There is no need to import
VERBOSE as this is replaced with a `log.verbose(...)` helper.

Now that we have resolved all instances of LOG015, lets enable the rule
in CI.

Signed-off-by: James McCorrie <[email protected]>
It doesn't look like these scripts are used in this version of DVSim.
Instead the versions shipped with OpenTitan are used if they are used at all.

For the moment remove the shebangs and remove the executable flag from
the files. They would not be useable from a package install anyway. When
it comes to reintegrating with OpenTitan, then a new solution will be
required. For the moment this patch resolves new failing linting checks.

Signed-off-by: James McCorrie <[email protected]>
Copy link
Contributor

@hcallahan-lowrisc hcallahan-lowrisc left a comment

Choose a reason for hiding this comment

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

I think a custom logger is fine, but I would love to see us move to module-level loggers in the future. It has always bothered me that we never moved towards something properly idiomatic here.
Anyway, that's a future task. This is a great improvement for now, and long overdue! Thanks @machshev

@machshev machshev merged commit 597c7d5 into lowRISC:master Sep 27, 2025
6 checks passed
@machshev machshev deleted the logging branch September 30, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants