feat: nicer contract debug logs + minor related cleanup#19960
Conversation
42dd819 to
30a5a7a
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f5c7c2a to
94de4d8
Compare
56e183f to
1e47bef
Compare
Flakey Tests🤖 says: This CI run detected 3 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
| // We give special treatment to contract logs because we want all the contract logs to be emitted no matter the default | ||
| // log level. This is because we don't want Noir contract developers to have to modify env vars to see logs come out of | ||
| // contracts. This default setting for the contract logs can be explicitly overridden via the LOG_LEVEL (e.g. to | ||
| // silence contract logs export 'info;silent:contract_log'). |
There was a problem hiding this comment.
I'll push back on this. It's going to be annoying for anyone who is not a noir contract dev - if I've set up log level to info, then why am I seeing debug?
I'd look for alternatives, such as bumping the log level of contracts to info (or something that noir contract devs usually run with), or having the TXE manually bump the log level for this module (eg when creating the logger for the utility execution oracle, I'm not sure if we support individual loggers having different log levels, but shouldn't be hard to implement), or only doing this if a certain env var is set (and not by default).
There was a problem hiding this comment.
You have a point. Dropped this in d80da3d
I will instead ensure this is correctly set when running aztec test and will try to figure out how to make people realize they should set this in e2e tests. Will do this in a followup PR.
| const name = await this.contractStore.getDebugContractName(this.contractAddress); | ||
| const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`; | ||
| this.contractLogger = createLogger(module); |
There was a problem hiding this comment.
Since #19959 we have an instanceId that we can attach to a logger. Seems like that would be a perfect fit for this.
There was a problem hiding this comment.
Was not aware of that. Lovely feature. Thanks!
In this PR I refactor how logs emitted from contracts are handled: - ~I register a `contract_log` module that is treated differently in that it has the default log level set to "debug". This ensures that by default Noir contract devs will see their logs printed out no matter the "system-wide" default log level (this was a common source of confusion for devs). Note that this results in dev needing to set `export LOG_LEVEL="silent;silent:contract_log"` to truly silence all logs. This feels controversial but I feel like it's currently the best tradeoff as devs were confused of not seeing their contract logs (contract logs are generally also not that spammy).~ - I make the emitted logs nicer by having them include name and first few bytes of address: <img width="1260" height="470" alt="image" src="https://github.com/user-attachments/assets/b3a14cbe-d55e-44bf-9ae5-e26f3e1f35de" /> ## Followup work - Rename the `utilityDebugLog` handler as `utilityLog` and clean up the `noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr` file that is now in a sad state, - make the nice contract logs work in public as well (this is currently broken).
47f99c2 to
166c4d6
Compare
|
CI failure seems to be an issue with foundry server so I'm re-adding. |
The `debug_log` naming became problematic as different log levels are supported and hence the name collides with the debug log level even though it's a generic util. For this reason I've renamed `debug_log` simply as `log` and I've cleaned up what used to be `debug_log.nr` file (in this PR renamed to `logging.nr`). The cleanup consists of: - dropping the log_slice functions (use of slices is now discouraged), - introducing individual functions for different log levels, - un-exposing the log level constants (the specific functions should be used instead) This is a breaking change as the imports need to get updated. This PR is a followup of #19960
The `debug_log` naming became problematic as different log levels are supported and hence the name collides with the debug log level even though it's a generic util. For this reason I've renamed `debug_log` simply as `log` and I've cleaned up what used to be `debug_log.nr` file (in this PR renamed to `logging.nr`). The cleanup consists of: - dropping the log_slice functions (use of slices is now discouraged), - introducing individual functions for different log levels, - un-exposing the log level constants (the specific functions should be used instead) This is a breaking change as the imports need to get updated. This PR is a followup of #19960
The `debug_log` naming became problematic as different log levels are supported and hence the name collides with the debug log level even though it's a generic util. For this reason I've renamed `debug_log` simply as `log` and I've cleaned up what used to be `debug_log.nr` file (in this PR renamed to `logging.nr`). The cleanup consists of: - dropping the log_slice functions (use of slices is now discouraged), - introducing individual functions for different log levels, - un-exposing the log level constants (the specific functions should be used instead) This is a breaking change as the imports need to get updated. This PR is a followup of #19960

In this PR I refactor how logs emitted from contracts are handled:
I register aUpdate: As mentioned below this is not the way to go and will be handled differnetly.contract_logmodule that is treated differently in that it has the default log level set to "debug". This ensures that by default Noir contract devs will see their logs printed out no matter the "system-wide" default log level (this was a common source of confusion for devs). Note that this results in dev needing to setexport LOG_LEVEL="silent;silent:contract_log"to truly silence all logs. This feels controversial but I feel like it's currently the best tradeoff as devs were confused of not seeing their contract logs (contract logs are generally also not that spammy).Followup work
utilityDebugLoghandler asutilityLogand clean up thenoir-projects/noir-protocol-circuits/crates/types/src/debug_log.nrfile that is now in a sad state,