diff --git a/Cargo.lock b/Cargo.lock index 74173ff..84cc556 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "rustc-serialize", "serde", "wasm-bindgen", "windows-targets 0.48.5", @@ -301,15 +302,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -1332,6 +1333,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-serialize" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" + [[package]] name = "rustix" version = "0.38.11" @@ -2030,15 +2037,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -2049,18 +2047,12 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.42.2" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.52.4", ] [[package]] @@ -2079,10 +2071,19 @@ dependencies = [ ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" +name = "windows-targets" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] [[package]] name = "windows_aarch64_gnullvm" @@ -2091,10 +2092,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" +name = "windows_aarch64_gnullvm" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -2103,10 +2104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] -name = "windows_i686_gnu" -version = "0.42.2" +name = "windows_aarch64_msvc" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -2115,10 +2116,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] -name = "windows_i686_msvc" -version = "0.42.2" +name = "windows_i686_gnu" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -2127,10 +2128,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" +name = "windows_i686_msvc" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -2139,10 +2140,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" +name = "windows_x86_64_gnu" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -2151,10 +2152,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" +name = "windows_x86_64_gnullvm" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -2162,6 +2163,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "winreg" version = "0.50.0" diff --git a/Cargo.toml b/Cargo.toml index 026bc2b..6f32a51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.75" camino = "1.1.6" -chrono = { version = "0.4.30", features = ["serde"] } +chrono = { version = "0.4.30", features = ["serde", "rustc-serialize"] } clap = { version = "4.4.2", features = ["derive", "env"] } config = "0.13.3" dialoguer = { version = "0.10.4", features = ["fuzzy-select"] } diff --git a/src/api/types.rs b/src/api/types.rs index 93f8e47..3af2810 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -1,6 +1,7 @@ -use std::fmt::{Display, Formatter, Result}; +use chrono::{serde::ts_seconds_option, DateTime, Utc}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; +use std::fmt::{Display, Formatter, Result}; use tabled::Tabled; #[derive(Serialize, Deserialize, Debug, Tabled)] @@ -17,12 +18,12 @@ pub struct ListOrganizationResponse { #[derive(Serialize, Deserialize, Debug, Tabled)] pub struct CreateEnvironmentResponse { - pub name: String + pub name: String, } #[derive(Serialize, Deserialize, Debug)] pub struct ListServicesResponse { - pub services: Vec + pub services: Vec, } #[derive(Serialize, Deserialize, Debug, Tabled, Clone, PartialEq)] @@ -33,12 +34,12 @@ pub struct Service { #[serde(default, skip_serializing_if = "is_default")] pub env: DisplayOption, #[serde(default, skip_serializing_if = "is_default")] - pub secrets: DisplayOption + pub secrets: DisplayOption, } #[derive(Serialize, Deserialize, Debug)] pub struct ListSecretsResponse { - pub secrets: Vec + pub secrets: Vec, } #[derive(Serialize, Deserialize, Debug, Tabled)] @@ -46,6 +47,13 @@ pub struct Secret { pub name: String, } +#[derive(Serialize, Deserialize, Debug)] +pub struct LogLine { + pub data: String, + #[serde(with = "ts_seconds_option")] + pub time: Option>, +} + #[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] pub struct DisplayHashMap(IndexMap); @@ -59,7 +67,7 @@ fn is_default(t: &T) -> bool { impl Display for DisplayOption { fn fmt(&self, f: &mut Formatter<'_>) -> Result { if self.0.is_none() { - return Ok(()) + return Ok(()); } let hashmap = self.0.as_ref().unwrap(); diff --git a/src/commands/services.rs b/src/commands/services.rs index faa81ab..578268c 100644 --- a/src/commands/services.rs +++ b/src/commands/services.rs @@ -13,6 +13,7 @@ use tungstenite::connect; use tungstenite::http::Uri; use tungstenite::ClientRequestBuilder; +use crate::api::types::LogLine; use crate::{ api::types::Service, config::{ @@ -422,8 +423,14 @@ impl Logs { let (mut socket, _) = connect(builder).expect("Could not connect"); loop { - let msg = socket.read().expect("Error reading message"); - println!("{}", msg.to_string().trim_end()); + let rawmsg = socket.read().expect("Error reading message").to_string(); + let msg: LogLine = serde_json::from_str(rawmsg.as_str())?; + + println!( + "time=\"{}\" message=\"{}\"", + msg.time.unwrap().format("%d/%m/%Y %H:%M:%S"), + msg.data + ); } }