-
Notifications
You must be signed in to change notification settings - Fork 68
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
Allowed custom datadir for loggers #405
Conversation
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.
Ack
src/utill.rs
Outdated
@@ -241,40 +243,12 @@ pub fn setup_directory_logger(filter: LevelFilter) { | |||
/// Setup function that will only run once, even if called multiple times. | |||
/// Takes log level to set the desired logging verbosity | |||
// TODO: Use the above setup logger functions. |
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.
All the todos comments now can be removed.
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.
removed all the todos
@0xEgao there are some test failure. Please look into it. Additionally you can add the git pre-commit hook in your local to always have basic checks covered before committing. https://github.com/citadel-tech/coinswap?tab=readme-ov-file#setting-up-git-hooks |
Hey @mojoX911 thanks for the feedback ,i have ran the neccessary tests as u suggested.You can review it now |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #405 +/- ##
==========================================
+ Coverage 70.26% 70.43% +0.17%
==========================================
Files 34 34
Lines 4261 4245 -16
==========================================
- Hits 2994 2990 -4
+ Misses 1267 1255 -12 ☔ View full report in Codecov by Sentry. |
src/bin/directory-cli.rs
Outdated
@@ -10,6 +10,7 @@ use coinswap::{ | |||
}, | |||
utill::{read_message, send_message, setup_directory_logger}, | |||
}; | |||
//use dirs::data_dir; |
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.
Commented lines like these are left in some places. Please remove them.
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 have made the changes, please review it.
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.
Looks good, few more fixes needed.
src/bin/directoryd.rs
Outdated
@@ -35,9 +35,9 @@ struct Cli { | |||
} | |||
|
|||
fn main() -> Result<(), DirectoryServerError> { | |||
setup_directory_logger(log::LevelFilter::Info); | |||
|
|||
setup_directory_logger(log::LevelFilter::Info, None); |
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.
Pass the args.data_dir
value here. This will make the log dir always fixed to default. Same for all other apps.
src/bin/directory-cli.rs
Outdated
@@ -43,7 +43,7 @@ fn send_rpc_req(mut stream: TcpStream, req: RpcMsgReq) -> Result<(), DirectorySe | |||
} | |||
|
|||
fn main() -> Result<(), DirectoryServerError> { | |||
setup_directory_logger(log::LevelFilter::Info); | |||
setup_directory_logger(log::LevelFilter::Info, None); |
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 think we can remove the setup logger functions from the cli apps.
src/bin/maker-cli.rs
Outdated
@@ -76,7 +76,7 @@ enum Commands { | |||
} | |||
|
|||
fn main() -> Result<(), MakerError> { | |||
setup_maker_logger(log::LevelFilter::Info); | |||
setup_maker_logger(log::LevelFilter::Info, None); |
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.
Same. Remove and check if anything fails in tests. It should not.
src/bin/makerd.rs
Outdated
@@ -49,8 +49,7 @@ struct Cli { | |||
} | |||
|
|||
fn main() -> Result<(), MakerError> { | |||
setup_maker_logger(log::LevelFilter::Info); | |||
|
|||
setup_maker_logger(log::LevelFilter::Info, None); |
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.
pass on args.data_dir
.
src/bin/taker.rs
Outdated
@@ -114,6 +114,7 @@ fn main() -> Result<(), TakerError> { | |||
args.command, | |||
Commands::Recover | Commands::FetchOffers | Commands::Coinswap { .. } | |||
), | |||
None, //default path handled inside the function. |
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.
pass the args value.
tests/test_framework/mod.rs
Outdated
@@ -533,7 +532,7 @@ impl TestFramework { | |||
Arc<DirectoryServer>, | |||
JoinHandle<()>, | |||
) { | |||
setup_logger(log::LevelFilter::Info); | |||
setup_logger(log::LevelFilter::Info, None); |
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 be called after creating the temp folder in the line below. Then pass the temp folder.
src/utill.rs
Outdated
setup_taker_logger(filter, true, data_dir.clone()); | ||
setup_maker_logger(filter, data_dir.clone()); | ||
setup_directory_logger(filter, data_dir.clone()); |
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 will merge all the logs into one file as data_dir value is same for all. You need to pass different subfolder for each logger. Just do data_dir.join)("maker")
etc for each case.
This is still not perfect as it will merge all the maker logs together. but its test only, doesn't matter much.
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.
Hey @mojoX911 is this supposed to be like this
pub fn setup_logger(filter: LevelFilter, data_dir: Option<PathBuf>) {
Once::new().call_once(|| {
env::set_var("RUST_LOG", "coinswap=info");
setup_taker_logger(
filter,
true,
Some(data_dir.clone().unwrap_or_else(get_taker_dir).join("taker")),
);
setup_maker_logger(
filter,
Some(data_dir.clone().unwrap_or_else(get_maker_dir).join("maker")),
);
setup_directory_logger(
filter,
Some(
data_dir
.clone()
.unwrap_or_else(get_dns_dir)
.join("directory"),
),
);
});
}
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.
No. You need to do data_dir.and_then(|d| Some(d.join("taker")))
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.
Hey @mojoX911 i have committed all the changes you requested,you can review them now
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.
ACK. Just one last question.
src/utill.rs
Outdated
if let Err(e) = log4rs::init_config(config) { | ||
eprintln!("Failed to initialize logger: {}", e); | ||
} |
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.
any reason why we are suppressing the 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.
I was getting my local branch specific error,so i tried to handle a particular error case,thanks for asking this,i have revert it back to unwrap()
. You can review it.
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.
Few nits and its good to go.
src/utill.rs
Outdated
if let Err(e) = log4rs::init_config(config) { | ||
eprintln!("Failed to initialize logger: {}", e); | ||
} |
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 suppress the error. unwrap.
src/utill.rs
Outdated
if let Err(e) = log4rs::init_config(config) { | ||
eprintln!("Failed to initialize logger: {}", e); | ||
} |
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.
Same.
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.
Have removed all suppressing error now.
src/utill.rs
Outdated
setup_taker_logger(filter, true, data_dir.clone().map(|d| d.join("taker"))); | ||
setup_maker_logger(filter, data_dir.clone().map(|d| d.join("maker"))); | ||
setup_directory_logger(filter, data_dir.clone().map(|d| d.join("directory"))); |
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 think clone is not needed.
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.
Thanks for the suggestion,instead of clone()
i have used as_ref()
for better memory efficiency.
@@ -79,8 +79,7 @@ impl Wallet { | |||
/// ### Behavior | |||
/// - If [SendAmount::Max] is used, the function creates a transaction for the maximum possible | |||
/// value to the specified destination. | |||
/// - If [SendAmount::Amount] is used, a custom value is sent, and any remaining funds | |||
/// are held in a change address, if applicable. | |||
/// - If [SendAmount::Amount] is used, a custom value is sent, and any remaining funds are held in a change address, if applicable. |
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.
No contextual change. Remove.
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 was recieving an error while doing cargo clippy... in this line so i changed the comment to fit into one line.
@@ -52,10 +52,10 @@ impl TakerCli { | |||
args.push(arg); | |||
} | |||
|
|||
let output = Command::new("./target/debug/taker") | |||
let output = Command::new(env!("CARGO_BIN_EXE_taker")) |
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 is a good change. Can you add this to all places in the lib where we are using ./target/debug/...
stuffs? This was another fix not listed in the issues, but we can get it done here.
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.
Thanks for the complement,i have changed all the ./target/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.
Ack. Awaiting CI.
hey @mojoX911 the test is failing because the logging framework only allows one global logger to be set,and an attempt to create more logger result to this test failure,for that i did earlier was suppressing the error, i.e checking if logger was already initialized,do you suggest to go back to this,or any other way? |
Ah right. Probably thats the reason why we had the repeated function. Suppressing the error won't work, as they will silently fail the log setup. lets revert back the original global setup logger, and just pass in custom datadirs into that. |
Reverting back is an option ,but i think the issue is with |
We need to initiate 3 loggers for 3 systems, can we do it with OnceLock with the new design? |
Hey @mojoX911 now i have implemented the |
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.
Ack
Please let me know if you'd like me to make any changes, this pr tries to solve the issue #402