summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-11-16 16:08:13 +0200
committerLars Wirzenius <liw@liw.fi>2023-11-16 16:08:13 +0200
commitccc24583da0af07a626d889a0e63976a9405285e (patch)
tree076fd81c529e178546a4b4bf36758d0bfe890a51
parent2bb33d6e9913bd0c50e97b3be6eab5a86e7607fd (diff)
downloadci-broker-prototype-ccc24583da0af07a626d889a0e63976a9405285e.tar.gz
use logging instead of print macros
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--Cargo.lock98
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs12
3 files changed, 109 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2109de1..ac212bf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -29,6 +29,15 @@ dependencies = [
]
[[package]]
+name = "aho-corasick"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "amplify"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -291,6 +300,8 @@ version = "0.1.0"
dependencies = [
"anyhow",
"axum",
+ "log",
+ "pretty_env_logger",
"radicle",
"radicle-term",
"reqwest",
@@ -579,6 +590,19 @@ dependencies = [
]
[[package]]
+name = "env_logger"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece"
+dependencies = [
+ "humantime",
+ "is-terminal",
+ "log",
+ "regex",
+ "termcolor",
+]
+
+[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -863,6 +887,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
+[[package]]
name = "hyper"
version = "0.14.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -962,6 +992,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[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",
+]
+
+[[package]]
name = "itoa"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1422,6 +1463,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
+name = "pretty_env_logger"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c"
+dependencies = [
+ "env_logger",
+ "log",
+]
+
+[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1672,6 +1723,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb"
[[package]]
+name = "regex"
+version = "1.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
+
+[[package]]
name = "reqwest"
version = "0.11.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2129,6 +2209,15 @@ dependencies = [
]
[[package]]
+name = "termcolor"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
name = "termion"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2471,6 +2560,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
+name = "winapi-util"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index dab51fb..dbbd440 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,6 +11,8 @@ tokio = { version = "1.34.0", features = ["full"] }
radicle = { path = "/home/liw/radicle/heartwood/radicle" }
anyhow = "1.0.75"
reqwest = { version = "0.11.22", features = ["blocking"] }
+log = "0.4.20"
+pretty_env_logger = "0.5.0"
[dependencies.radicle-term]
version = "0"
diff --git a/src/main.rs b/src/main.rs
index d5d5564..fa083cf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@
use std::{thread::spawn, time};
use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::get, Router};
+use log::{debug, info};
use radicle::node::Handle;
// use radicle::storage::RefUpdate;
@@ -14,8 +15,12 @@ use radicle::Profile;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
+ pretty_env_logger::init();
+ info!("ci-broker-prototype starts");
+
let profile = Profile::load()?;
spawn(move || subscribe_to_node_events(profile).expect("node events"));
+ debug!("started thread for receiving events from node");
let app = Router::new()
.route("/", get(go_away))
@@ -31,16 +36,17 @@ async fn main() -> anyhow::Result<()> {
}
async fn go_away() -> (StatusCode, impl IntoResponse) {
+ info!("bad request");
(StatusCode::FORBIDDEN, ())
}
async fn succeeded(Path(id): Path<String>) -> (StatusCode, impl IntoResponse) {
- println!("CI success: {}", id);
+ info!("CI success: {}", id);
(StatusCode::OK, ())
}
async fn failed(Path(id): Path<String>) -> (StatusCode, impl IntoResponse) {
- println!("CI FAIL: {}", id);
+ info!("CI FAIL: {}", id);
(StatusCode::OK, ())
}
@@ -50,7 +56,7 @@ fn subscribe_to_node_events(profile: Profile) -> anyhow::Result<()> {
for event in events {
let event = event?;
- println!("{:#?}", event);
+ debug!("{:#?}", event);
// #[allow(clippy::single_match)]
// match event {