diff --git a/package/action/Cargo.lock b/package/action/Cargo.lock index 78896ae..557cc5d 100644 --- a/package/action/Cargo.lock +++ b/package/action/Cargo.lock @@ -9,11 +9,13 @@ dependencies = [ "actions-core", "anyhow", "better-panic", + "colored", "directories", "home", "serde", "serde_json", "tracing", + "tracing-core", "tracing-subscriber", "tracing-unwrap", "ureq", @@ -105,6 +107,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "block-buffer" version = "0.10.4" @@ -173,6 +181,17 @@ dependencies = [ "inout", ] +[[package]] +name = "colored" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +dependencies = [ + "is-terminal", + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "console" version = "0.15.7" @@ -272,6 +291,27 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +[[package]] +name = "errno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "flate2" version = "1.0.27" @@ -318,6 +358,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "hmac" version = "0.12.1" @@ -355,6 +401,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "itoa" version = "1.0.9" @@ -391,6 +448,12 @@ version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + [[package]] name = "log" version = "0.4.20" @@ -520,7 +583,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -555,6 +618,19 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.38.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + [[package]] name = "rustls" version = "0.21.7" diff --git a/package/action/Cargo.toml b/package/action/Cargo.toml index 0148305..4f28487 100644 --- a/package/action/Cargo.toml +++ b/package/action/Cargo.toml @@ -9,11 +9,13 @@ edition = "2021" actions-core = "0.0.2" anyhow = "1.0.75" better-panic = "0.3.0" +colored = "2.0.4" directories = "5.0.1" home = "0.5.5" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" tracing = "0.1.37" +tracing-core = "0.1.31" tracing-subscriber = "0.3.17" tracing-unwrap = "0.10.0" ureq = "2.7.1" diff --git a/package/action/src/fmt.rs b/package/action/src/fmt.rs new file mode 100644 index 0000000..e92b572 --- /dev/null +++ b/package/action/src/fmt.rs @@ -0,0 +1,66 @@ +use std::fmt; +use tracing_core::{Subscriber, Event, Level}; +use tracing_subscriber::fmt::{ + format::{self, FormatEvent, FormatFields}, + FmtContext, + FormattedFields, +}; +use tracing_subscriber::registry::LookupSpan; +use colored::Colorize; + +pub struct LogFormatter; + +impl FormatEvent for LogFormatter +where + S: Subscriber + for<'a> LookupSpan<'a>, + N: for<'a> FormatFields<'a> + 'static, +{ + fn format_event( + &self, + ctx: &FmtContext<'_, S, N>, + mut writer: format::Writer<'_>, + event: &Event<'_>, + ) -> fmt::Result { + + let meta = event.metadata(); + + let scope = match meta.level() { + &Level::DEBUG => "?".purple().bold(), + &Level::ERROR => "!".red().bold(), + &Level::INFO => "*".green().bold(), + &Level::TRACE => ".".white().bold(), + &Level::WARN => "#".yellow().bold(), + }; + + let target = if meta.level() != &Level::INFO { + let mut sep = "::".to_owned(); + sep.push_str(&meta.target().italic().underline()); + + sep + } else { + "::main".to_string() + }; + + write!(&mut writer, "[{}][{}] ", scope, target)?; + + if let Some(scope) = ctx.event_scope() { + for span in scope.from_root() { + write!(writer, "{}", span.name())?; + let ext = span.extensions(); + let fields = &ext + .get::>() + .unwrap(); + + + if !fields.is_empty() { + write!(writer, "{{{}}}", fields)?; + } + write!(writer, " ")?; + } + } + + ctx.field_format().format_fields(writer.by_ref(), event)?; + + writeln!(writer) + } +} \ No newline at end of file diff --git a/package/action/src/lib.rs b/package/action/src/lib.rs index f5e919b..7c5e7f6 100644 --- a/package/action/src/lib.rs +++ b/package/action/src/lib.rs @@ -1,3 +1,4 @@ pub mod types; pub mod github; -pub mod download; \ No newline at end of file +pub mod download; +pub mod fmt; \ No newline at end of file diff --git a/package/action/src/main.rs b/package/action/src/main.rs index 50021dc..de037c6 100644 --- a/package/action/src/main.rs +++ b/package/action/src/main.rs @@ -1,6 +1,6 @@ use std::fs::File; -use action::download::{download_release, install_lune}; +use action::{download::{download_release, install_lune}, fmt::LogFormatter}; use actions_core as core; use tracing::Level; use tracing_unwrap::ResultExt; @@ -14,6 +14,7 @@ fn main() { true => Level::DEBUG, false => Level::INFO, }) + .event_format(LogFormatter) .init(); }