Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Tracing logs#432

Merged
cryptoAtwill merged 34 commits intomainfrom
tracing-logs
Nov 15, 2023
Merged

Tracing logs#432
cryptoAtwill merged 34 commits intomainfrom
tracing-logs

Conversation

@cryptoAtwill
Copy link
Copy Markdown
Contributor

Add more logging outputs options so that we still have default info log to console, but also have debug logs with rotation written to file.


RUN useradd ipc && chown -R ipc $FM_HOME_DIR

USER ipc No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need an ipc user instead of root here? Also, I don't think it is the case but I am wondering if this may break the execution of the fendermint container considering the directory structure that we use. Have you tried it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I never quite understood how to use users inside containers properly. I made images where I used add-user to create users with specific IDs and groups, but unless those IDs aligned with what exists on the host, I still had to end up setting the -u option to make sure I can remove files created into mounted volumes without sudo. Since this is a container, I never quite got why we shouldn't use root 🤷 I'm sure I'm just ignorant, but if it works...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed as it's not needed anymore. But I think one day we should not use root to execute docker


tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
create_log(level, &opts.home_dir).expect("cannot create logging");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should add a setting to configure the output path, and if we want the log to be output on std err/std output, or to a file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's right to do both. I had a similar thing in my Scala programs except I was able to configure them through XML, so we can enable the debug level on a package-by-package basis (third parties as well) without recompiling.


// debug level logger
let topdown_logger = config::Logger {
level: config::LevelFilter::DEBUG,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we make this configurable too? Now we want this in debug mode for debugging purpose, but we may want to keep the same level for all in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would say we just keep this top down logs just in case for something unexpected. The logs will be 50mb in total, it's not taking a lot of space. But we always have some logs to refer back to.

Comment on lines +95 to +97
config
.appenders
.insert(AppenderId::from("topdown"), topdown_appender);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need to insert the logger into the config, when it's already set in the topdown_logger?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I havent looked very deep into trace4rs, my guess is when an event is emitted, it checks if there are any Target watching this event, then target has a logger, and logger has an appender.

cryptoAtwill and others added 4 commits November 15, 2023 20:48
* look ahead limit use finalized height

* rename variable

* more comments

* more logs
tracing-subscriber = "0.3"
url = "2.4.1"
zeroize = "1.6"
trace4rs = "0.5.1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if this is available on Github somewhere? I can't find a link at https://crates.io/crates/trace4rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +100 to +105
config
.loggers
.insert(Target::from("fendermint_app"), debug_logger.clone());
config
.loggers
.insert(Target::from("fendermint_vm_interpreter"), debug_logger);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://docs.rs/trace4rs/0.5.1/src/trace4rs/handle/loggers.rs.html#91 suggests that a simple Target::from("fendermint") should work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

funny thing is, with this, all logs are directly to debug and console is empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe because it's set as a "default" which could mean "if nothing else matched"? Perhaps insert it explicitly with the "" target?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"parent block hash at {height} is {:02x?} diff than previous hash: {previous_hash:02x?}",
block_hash_res.parent_block_hash
);
heigit = hex::encode(&block_hash_res.parent_block_hash),
Copy link
Copy Markdown
Contributor

@aakoshh aakoshh Nov 15, 2023

Choose a reason for hiding this comment

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

Suggested change
heigit = hex::encode(&block_hash_res.parent_block_hash),
height,
parent_hash = hex::encode(&block_hash_res.parent_block_hash),

.insert(Target::from("fendermint"), debug_logger);
config
.appenders
.insert(AppenderId::from("debug"), debug_appender);
Copy link
Copy Markdown
Contributor

@aakoshh aakoshh Nov 15, 2023

Choose a reason for hiding this comment

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

Yeah so why don't we insert a clone of the default console logger with an Target::from("") and the INFO level?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, but it seems to me this is a bug or sth, we should not be able to do that though. But I added this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's a bug? Why shouldn't we be able to set a logger that captures everything and logs to the console if we want to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean we need to do this:

        config
            .loggers
            .insert(Target::from("fendermint"), debug_logger);
        config.loggers.insert(Target::from("fendermint"), default);

but ideally we should not need config.loggers.insert(Target::from("fendermint"), default); as we already set default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, okay, so if fendermint* will go to both debug files and console, and everything else will also go to the console because it matches all namespaces, if their log level is at least the selected one 👍

Copy link
Copy Markdown
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Thank you for all the changes!

@cryptoAtwill cryptoAtwill merged commit ded95dd into main Nov 15, 2023
@cryptoAtwill cryptoAtwill deleted the tracing-logs branch November 15, 2023 14:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants