generated from PlexSheep/baserepo
fix: let logger use the crate name of the end-crate #91
cargo devel CI / cargo CI (push) Has been cancelled
Details
cargo devel CI / cargo CI (push) Has been cancelled
Details
This commit is contained in:
parent
687fd94870
commit
442e17f9a8
|
@ -8,3 +8,16 @@
|
||||||
|
|
||||||
/// macros to make things faster in your code
|
/// macros to make things faster in your code
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
|
|
||||||
|
/// ## Get the name of the crate that uses your library
|
||||||
|
///
|
||||||
|
/// Let's say you're writing the library `foo` and need the name of the crate that uses `foo`. With
|
||||||
|
/// this function, you can get the name of the crate that uses `foo`.
|
||||||
|
///
|
||||||
|
/// Will return [None] if [`std::env::current_exe()`] errors or if conversion to [String] from [std::ffi::OsStr] fails.
|
||||||
|
pub fn get_crate_name() -> Option<String> {
|
||||||
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
|
return Some(exe.file_stem()?.to_str()?.to_string());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
|
@ -480,5 +480,11 @@ impl Default for Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_file_appender(log_dir: PathBuf) -> tracing_appender::rolling::RollingFileAppender {
|
fn new_file_appender(log_dir: PathBuf) -> tracing_appender::rolling::RollingFileAppender {
|
||||||
tracing_appender::rolling::daily(log_dir, format!("{}.log", env!("CARGO_CRATE_NAME")))
|
tracing_appender::rolling::daily(
|
||||||
|
log_dir,
|
||||||
|
format!(
|
||||||
|
"{}.log",
|
||||||
|
libpt_core::get_crate_name().unwrap_or_else(|| "logfile".to_string())
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue