-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: add logging macro #196
feat: add logging macro #196
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/macros/src/logging.rs
Outdated
.collect(); | ||
|
||
// Generate the log statement with feature checks | ||
let log_statement = match level.as_str() { |
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.
Is it really necessary to have separate versions for each log level?
@@ -11,3 +11,4 @@ license-file = "LICENSE" | |||
|
|||
[workspace.dependencies] | |||
cairo_test = "2.8.0" | |||
|
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.
?
@@ -44,6 +43,18 @@ pub fn validate_timestamp(prev_timestamps: Span<u32>, block_time: u32) -> Result | |||
} | |||
} | |||
|
|||
#[cfg(feature: 'log_level_debug')] |
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.
What are we testing here? No conditions are checked.
// Generate the log statement | ||
let log_statement = generate_log_statement(&level, &format_string, &log_args); | ||
|
||
println!("Log statement: {}", log_statement); |
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.
Not necessary?
packages/macros/src/logging.rs
Outdated
if matches!(node.kind(&db), SyntaxKind::Arg) { | ||
Some(node.get_text(&db)) | ||
} else { | ||
println!("Invalid argument: {:?} {:?}", node.get_text(&db), node.kind(&db)); |
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 should return an error?
@@ -0,0 +1,14 @@ | |||
# Cargo.toml |
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.
Package should be called logging not macros.
packages/consensus/src/logging.cairo
Outdated
@@ -0,0 +1,17 @@ | |||
#[cfg(feature: 'log_level_trace')] |
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 file should go to macros(or rather logging) package.
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 can't find a way to import the logging constant to the desired package to use the constants. seems that the procedural macros package(logging package) behaves differently.
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.
Maybe try to make package with macros a dependency of loggin package(which would be cairo only)?
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.
very weird even the compiler is happy after the feature is enabled, maybe this is cairo bug @maciejka
error: Identifier not found.
--> //raito/packages/consensus/src/codec.cairo:14:30
if logging::logging::LOG_LEVEL_DEBUG { println!("{}: {}", format!("DEBUG"), format!("tx_encoded: {}", dest)) }
^*************^
error: could not compile `consensus` due to previous error
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.
@maciejka i previously rename the file then logging::logging::LOG_LEVEL_DEBUG
. also logging::log::LOG_LEVEL_DEBUG
also not work even though the language server recognize when the feature is enabled.
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 asked in scarb group: https://t.me/c/1788692421/1887
packages/logging/src/logging.rs
Outdated
// Generate the log statement | ||
let log_statement = generate_log_statement(&level, &format_string, &log_args); | ||
|
||
println!("Log statement: {}", log_statement); |
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.
Remove the trace
packages/logging/Cargo.toml
Outdated
[dependencies] | ||
bigdecimal = "0.4.5" | ||
cairo-lang-macro = "0.1" | ||
cairo-lang-parser = "2.7.0" |
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.
don't we want 2.8.0?
packages/consensus/src/logging.cairo
Outdated
@@ -0,0 +1,17 @@ | |||
#[cfg(feature: 'log_level_trace')] |
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.
How is it going @TropicalDog17? It seems like this one is close to be finished. |
Yeah @maciejka I think these feature-based constants cannot be imported from an external package, I tried some workaround but it's no luck, maybe the language hasn't supported that feature yet. It appears that for the logging feature to work correctly, the constant file needs to be placed within the specific package where we want to enable logging. |
Please check: #224. I had to try it myself. Indeed there is a problem with conditional compilation in a multipackage project. Waiting for scarb developers response. |
|
Which means we might need to wait until they implement it. |
yeah I see, and very weird that the language server still recognize that feature. |
true |
I am closing it for now. We will need to revisit this issue once feature support in Scarb is more mature. The work with my small fixes is parked in branch: feat/logging-macro |
@TropicalDog17 please contact me on tg: @aundumla |
log!
macro #187Guide to be added in README.md of the logging package
Prequiste for using
log!
macro for a package:Scarb.toml
logging.cairo
(must be this name) file to the package root, like thepackage/consensus