-
Notifications
You must be signed in to change notification settings - Fork 3
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: APIs for reporting activity to Station #124
Conversation
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
What do you think about using another fd (3) for communication to Station? This way we can keep stdout/stderr for the module, which is nicer for when Zinnia is used independently of Station |
I see what you mean. If we want to use Zinnia for building something else than a Station module, then yes, it makes sense to provide On the other hand, while building Zinnia modules, I find it useful to be able to discard debug logs and see only the activity that will be reported to the station.
There are different ways how to meet both requirements. For the Station, I will be building a different reporter in Using fd 3 is possible, although I don't know if that's supported on Windows. If we decide we want to make Building on top of my example above:
What do you think, @juliangruber? BTW it's common for applications to log to stderr, e.g. Node.js debug module and Go's built-in log module. |
See https://rustsec.org/advisories/RUSTSEC-2020-0071 Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
I guess you can still do that, just not as accessible: $ zinnia run file >/dev/null 2>/dev/null 3>&1 But good point, the consumability of the station events does become a problem then. Another option: By default log $ zinnia run file --station-fd 3 Whether this works on Windows is another question, I didn't find an obvious answer with a quick google search. To me it's just very unexpected that I'd still suggest to keep this as is currently, and iterate if it becomes an issue. |
|
||
/// Reporter that collects all recorded events, useful for testing. | ||
pub struct RecordingReporter { | ||
pub events: RefCell<Vec<String>>, |
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.
We want the recorder to be immutable so that we can pass it around and have multiple immutable references. However, our inner state is mutable. The solution is called "interior mutability", see https://doc.rust-lang.org/book/ch15-05-interior-mutability.html
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Just to clarify, it's
The Station will launch a different Zinnia binary (
This is a valid point. Let me think about this more. |
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
I decided to make the following changes: (1)
This way, Zinnia CLI can be used as a replacement for Node.js or Deno with additional APIs for easier interaction with libp2p, IPFS and Filecoin. (2) This affects only people using Zinnia to build Station Modules. Code not invoking activity/job-completion reporting APIs will never trigger these coloured logs. Note that these two changes affect only Zinnia CLI for local development. We can implement different logic for handling logs & activities in I consider this PR ready for final review and merging. @juliangruber PTAL 🙏🏻 |
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize_repr)] | ||
#[repr(u8)] | ||
pub enum LogLevel { | ||
Debug, | ||
Info, | ||
Warn, | ||
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.
Deserialize_repr
allows us to parse numeric levels provided by Deno Console implementation and treat them as an enum in the rest of our codebase.
runtime/console_reporter.rs
Outdated
fn report(&self, scope: &str, msg: &str, color: Color) -> Result<()> { | ||
if use_color() { | ||
let mut spec = ColorSpec::new(); | ||
spec.set_fg(Some(color)).set_bold(true); |
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.
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
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 skipped over some parts that went above my head (for now). Lgtm, great work Miro!
Implement the following new APIs:
Rework the implementation of
Console
APIs to call our internal printer so that we can intercept these logs and potentially handle them in different ways.Example output:
See #75 and #121.