Add custom rust log callback param

This commit is contained in:
Caelan Sayler
2025-03-12 23:16:24 +00:00
committed by Caelan
parent 267a09f456
commit 0cd6c3db3f
5 changed files with 9 additions and 4 deletions

1
Cargo.lock generated
View File

@@ -2309,6 +2309,7 @@ dependencies = [
"neon",
"semver",
"serde_json",
"simplelog",
"ts-rs",
"velopack",
]

View File

@@ -79,7 +79,7 @@ fn main_inner() -> Result<()> {
let verbose = matches.get_flag("verbose");
let logfile = matches.get_one::<PathBuf>("log");
velopack::logging::init_logging("setup", logfile, true, verbose);
velopack::logging::init_logging("setup", logfile, true, verbose, None);
let debug = matches.get_one::<PathBuf>("debug");
let install_to = matches.get_one::<PathBuf>("installto");

View File

@@ -19,7 +19,7 @@ fn main() -> ExitCode {
my_dir.join("Velopack.log")
};
let _ = velopack::logging::init_logging("stub", Some(&default_log_file), false, false);
let _ = velopack::logging::init_logging("stub", Some(&default_log_file), false, false, None);
info!("--");
info!("Starting Velopack Stub (at {:?})", my_path);

View File

@@ -134,7 +134,7 @@ fn main() -> Result<()> {
let verbose = get_flag_or_false(&matches, "verbose");
let log_file = matches.get_one("log");
let desired_log_file = log_file.cloned().unwrap_or(default_logfile_path(LocationContext::IAmUpdateExe));
init_logging("update", Some(&desired_log_file), true, verbose);
init_logging("update", Some(&desired_log_file), true, verbose, None);
// change working directory to the parent directory of the exe
let mut containing_dir = env::current_exe()?;

View File

@@ -76,8 +76,12 @@ pub fn default_logfile_path<L: TryInto<VelopackLocator>>(locator: L) -> PathBuf
/// It can only be called once per process, and should be called early in the process lifecycle.
/// Future calls to this function will fail.
#[cfg(feature = "file-logging")]
pub fn init_logging(process_name: &str, file: Option<&PathBuf>, console: bool, verbose: bool) {
pub fn init_logging(process_name: &str, file: Option<&PathBuf>, console: bool, verbose: bool, custom_log_cb: Option<Box<dyn SharedLogger>>) {
let mut loggers: Vec<Box<dyn SharedLogger>> = Vec::new();
if let Some(cb) = custom_log_cb {
loggers.push(cb);
}
let color_choice = ColorChoice::Never;
if console {
let console_level = if verbose { LevelFilter::Debug } else { LevelFilter::Info };