feat: add build file and add commit hash and version in debug info
This commit is contained in:
parent
3d0436f18e
commit
e7a2c67998
2 changed files with 40 additions and 2 deletions
35
build.rs
Normal file
35
build.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
|
||||||
|
println!("cargo:rustc-env=GIT_TAG={}", git_tag());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn git_commit_hash() -> String {
|
||||||
|
let commit_command = Command::new("git")
|
||||||
|
.args(&[
|
||||||
|
"rev-parse",
|
||||||
|
"HEAD"
|
||||||
|
])
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match commit_command {
|
||||||
|
Ok(out) => String::from_utf8(out.stdout).unwrap_or(String::from("unknown")),
|
||||||
|
Err(_) => String::from("unknown")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn git_tag() -> String {
|
||||||
|
let tag_command = Command::new("git")
|
||||||
|
.args(&[
|
||||||
|
"describe",
|
||||||
|
"--tags",
|
||||||
|
"--abbrev=0"
|
||||||
|
])
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match tag_command {
|
||||||
|
Ok(out) => String::from_utf8(out.stdout).unwrap_or(String::from("unknown")),
|
||||||
|
Err(_) => String::from("unknown")
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,10 @@ mod error;
|
||||||
fn main() {
|
fn main() {
|
||||||
let config = configuration::Config::from_file(&env::var("CONFIG").unwrap_or(String::from("./config.toml")));
|
let config = configuration::Config::from_file(&env::var("CONFIG").unwrap_or(String::from("./config.toml")));
|
||||||
setup_logger(&config);
|
setup_logger(&config);
|
||||||
debug!("Config: {:#?}", &config);
|
trace!("Config: {:#?}", &config);
|
||||||
|
|
||||||
|
debug!("commit: {}", env!("GIT_COMMIT_HASH"));
|
||||||
|
debug!("version: {}", env!("GIT_TAG"));
|
||||||
|
|
||||||
let input_files = files::get_files(&config.files.input_path)
|
let input_files = files::get_files(&config.files.input_path)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -99,7 +102,7 @@ fn setup_logger(config: &configuration::Config) {
|
||||||
.size(10 * 1000)
|
.size(10 * 1000)
|
||||||
.roll_count(10)
|
.roll_count(10)
|
||||||
.time_format("%Y-%m-%d %H:%M:%S")
|
.time_format("%Y-%m-%d %H:%M:%S")
|
||||||
.level(if config.is_debug() { "debug" } else { "info" })
|
.level(if config.is_debug() { "trace" } else { "info" })
|
||||||
.output_file()
|
.output_file()
|
||||||
.output_console()
|
.output_console()
|
||||||
.build();
|
.build();
|
||||||
|
|
Loading…
Reference in a new issue