Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod product_config_utils;
pub mod reconcile;
pub mod role_utils;
pub mod status;
pub mod utils;
pub mod validation;

pub use crate::crd::CustomResourceExt;
47 changes: 47 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use tracing::info;

/// Prints helpful and standardized diagnostic messages.
///
/// This method is meant to be called first thing in the `main` method of an Operator.
///
/// # Usage
///
/// Use the [`built`](https://crates.io/crates/built) crate and include it in your `main.rs` like this:
///
/// ```text
/// mod built_info {
/// // The file has been placed there by the build script.
/// include!(concat!(env!("OUT_DIR"), "/built.rs"));
/// }
/// ```
///
/// Then call this method in your `main` method:
///
/// ```text
/// stackable_operator::utils::print_startup_string(
/// built_info::PKG_DESCRIPTION,
/// built_info::PKG_VERSION,
/// built_info::GIT_VERSION,
/// built_info::TARGET,
/// built_info::BUILT_TIME_UTC,
/// built_info::RUSTC_VERSION,
/// );
/// ```
pub fn print_startup_string(
pkg_description: &str,
pkg_version: &str,
git_version: Option<&str>,
target: &str,
built_time: &str,
rustc_version: &str,
) {
let git_information = match git_version {
None => "".to_string(),
Some(git) => format!(" (Git information: {})", git),
};
info!("Starting {}", pkg_description);
info!(
"This is version {}{}, built for {} by {} at {}",
pkg_version, git_information, target, rustc_version, built_time
)
}