use crate::{
common::{
error::Result,
log::{init, proxy::LogProxy, tee_file::TeeFile, Log, LogRecord},
},
host::configuration::PluginLogConfiguration,
};
use ipc_channel::ipc::IpcSender;
pub fn setup_logging(
configuration: &PluginLogConfiguration,
log_channel: IpcSender<LogRecord>,
) -> Result<()> {
let mut loggers = Vec::with_capacity(1 + configuration.tee_files.len());
loggers.push(LogProxy::boxed(
configuration.name.as_str(),
configuration.verbosity,
log_channel,
) as Box<dyn Log>);
let tee_files: Result<Vec<_>> = configuration
.tee_files
.clone()
.into_iter()
.map(TeeFile::new)
.collect();
loggers.extend(tee_files?.into_iter().map(|l| Box::new(l) as Box<dyn Log>));
init(loggers)?;
Ok(())
}