From c1c457c69986a5c821b568e6d9ffe799107053c4 Mon Sep 17 00:00:00 2001 From: Robby klein Gunnewiek Date: Sun, 15 Dec 2024 20:41:07 +0100 Subject: [PATCH] Release slog-google version 0.1.0 (#201) --- Cargo.lock | 28 ++++++++++++++-------------- Cargo.toml | 2 +- crates/googlelog/Cargo.toml | 8 +++++++- crates/googlelog/Makefile | 33 +++++++++++++++++++++++++++++++++ crates/googlelog/src/lib.rs | 4 ++-- crates/googlelog/src/logger.rs | 6 +++--- src/logging.rs | 6 +++--- 7 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 crates/googlelog/Makefile diff --git a/Cargo.lock b/Cargo.lock index 2a5d149..e9bf6d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1021,19 +1021,6 @@ dependencies = [ "url 1.7.2", ] -[[package]] -name = "googlelog" -version = "0.1.0" -dependencies = [ - "chrono", - "google-logging2", - "reqwest", - "serde_json", - "slog", - "thiserror 1.0.69", - "tokio", -] - [[package]] name = "h2" version = "0.3.26" @@ -2993,6 +2980,19 @@ dependencies = [ "thread_local", ] +[[package]] +name = "slog-google" +version = "0.1.0" +dependencies = [ + "chrono", + "google-logging2", + "reqwest", + "serde_json", + "slog", + "thiserror 1.0.69", + "tokio", +] + [[package]] name = "slog-redis" version = "0.1.2" @@ -3617,7 +3617,6 @@ dependencies = [ "console-subscriber", "flate2", "futures", - "googlelog", "http 0.2.12", "hyper 0.14.31", "hyper-rustls 0.23.2", @@ -3630,6 +3629,7 @@ dependencies = [ "serde_json", "slog", "slog-async", + "slog-google", "slog-redis", "slog-term", "strum", diff --git a/Cargo.toml b/Cargo.toml index 31afae5..2f1caad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ documentation = "https://github.com/bolcom/unFTP" path = "crates/redislog" version = "0.1.2" -[dependencies.googlelog] +[dependencies.slog-google] path = "crates/googlelog" features = ["shipper"] version = "0.1.0" diff --git a/crates/googlelog/Cargo.toml b/crates/googlelog/Cargo.toml index edb6fb8..06dc41a 100644 --- a/crates/googlelog/Cargo.toml +++ b/crates/googlelog/Cargo.toml @@ -1,10 +1,16 @@ [package] -name = "googlelog" +name = "slog-google" +description = "Google Logging drain for slog-rs" version = "0.1.0" edition = "2021" +license = "Apache-2.0" authors = [ "Rob klein Gunnewiek " ] +keywords = ["slog", "logging", "log", "google", "gcp"] +categories = ["development-tools::debugging"] +homepage = "https://github.com/bolcom/unFTP/tree/master/crates/googlelog" +repository = "https://github.com/bolcom/unFTP/tree/master/crates/googlelog" [features] shipper = [] diff --git a/crates/googlelog/Makefile b/crates/googlelog/Makefile new file mode 100644 index 0000000..d790807 --- /dev/null +++ b/crates/googlelog/Makefile @@ -0,0 +1,33 @@ +.PHONY: help +help: # Show available `make` commands + @awk -F'#' '\ + BEGIN{n=split("$(DOCKER_IMAGES)", docker_images, " ")} \ + /^[%a-z][.A-Za-z0-9]+/ { \ + if (NF > 1) { \ + sub(/:[^#]*/, ""); \ + if ($$1 ~ /%/ && $$1 ~ /[Dd]ocker/) { \ + line=$$0; \ + for (i=1; i<=n; ++i) { \ + $$0 = line; \ + gsub(/%/, docker_images[i]); \ + printf("%-25s %s\n", $$1, $$2) \ + } \ + } else { \ + printf("%-25s %s\n", $$1, $$2) \ + } \ + } \ + }\ + /^##/ { printf("\n") }' Makefile + +## +.PHONY: pr-prep +pr-prep: # Runs checks to ensure you're ready for a pull request + cargo fmt --all -- --check + cargo clippy -- -D warnings + cargo test + cargo test --doc + cargo build + cargo doc --no-deps --features shipper + +publish: + cargo publish --verbose diff --git a/crates/googlelog/src/lib.rs b/crates/googlelog/src/lib.rs index 61e291a..9478161 100644 --- a/crates/googlelog/src/lib.rs +++ b/crates/googlelog/src/lib.rs @@ -4,7 +4,7 @@ //! //! Warning: Currently, this library only works in the context of [workload identity](https://cloud.google.com/iam/docs/workload-identity-federation). //! -//! The `googlelog` drain creates log entries compatible with [Google Cloud Logging](https://cloud.google.com/logging). +//! The `slog_google` drain creates log entries compatible with [Google Cloud Logging](https://cloud.google.com/logging). //! Depending on how you want to ship these logs to the Google Logging API, you can choose from one of the available build methods. //! //! Start by configuring the Logger with the builder ([`Builder`](logger::Builder::new)) and selecting the appropriate build method based on your shipping requirements: @@ -16,7 +16,7 @@ //! The [`builder`](struct@logger::Builder) supports several `with_*` methods to customize the log message format, //! particularly the default labels attached to [log entries](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry). //! -/// Googlelog Error types +/// slog-google Error types pub mod error; /// The [`slog::Drain`](https://slog-rs.github.io/slog/slog/trait.Drain.html) Implementation of the slog Drain for [Google Cloud Logging](https://cloud.google.com/logging) diff --git a/crates/googlelog/src/logger.rs b/crates/googlelog/src/logger.rs index d17e396..d2693ba 100644 --- a/crates/googlelog/src/logger.rs +++ b/crates/googlelog/src/logger.rs @@ -45,7 +45,7 @@ impl Builder { /// # Example /// /// ``` - /// use googlelog::logger::Builder; + /// use slog_google::logger::Builder; /// let (drain, _) = Builder::new( /// "projects/my-gcp-project/logs/my-log-id", /// "k8s_container", @@ -81,7 +81,7 @@ impl Builder { /// "namespace_name": "my-gke-namespace" /// }); /// - /// use googlelog::logger::Builder; + /// use slog_google::logger::Builder; /// let (drain, _) = Builder::new( /// "projects/my-gcp-project/logs/my-log-id", /// "k8s_container", @@ -195,7 +195,7 @@ impl Builder { /// "namespace_name": "my-gke-namespace" /// }); /// - /// use googlelog::logger::Builder; + /// use slog_google::logger::Builder; /// let (drain, mut shipper) = Builder::new( /// "projects/my-gcp-project/logs/my-log-id", /// "k8s_container", diff --git a/src/logging.rs b/src/logging.rs index 3553403..e62de8c 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -40,7 +40,7 @@ where pub fn create_logger( arg_matches: &ArgMatches, -) -> Result<(slog::Logger, Option), String> { +) -> Result<(slog::Logger, Option), String> { let min_log_level = match arg_matches.occurrences_of(VERBOSITY) { 0 => Level::Warning, 1 => Level::Info, @@ -140,7 +140,7 @@ fn load_labels_file(file_path: &str, hostname: &str) -> Result Result, String> { +) -> Result, String> { match (m.value_of(GLOG_LOGNAME), m.value_of(GLOG_RESOURCE_TYPE)) { (Some(logname), Some(resource_type)) => { @@ -150,7 +150,7 @@ fn google_logger( let (labels_file, level_label) = (m.value_of(GLOG_LABELS_FILE), m.value_of(GLOG_LEVEL_LABEL)); - let mut builder = googlelog::logger::Builder::new( + let mut builder = slog_google::logger::Builder::new( logname, resource_type, );