|
|
@ -58,6 +58,8 @@ pub enum Error {
|
|
|
|
TimeFormat(#[from] time::error::Format),
|
|
|
|
TimeFormat(#[from] time::error::Format),
|
|
|
|
#[error(transparent)]
|
|
|
|
#[error(transparent)]
|
|
|
|
InvalidFormatDescription(#[from] time::error::InvalidFormatDescription),
|
|
|
|
InvalidFormatDescription(#[from] time::error::InvalidFormatDescription),
|
|
|
|
|
|
|
|
#[error("Internal logger disabled and cannot be acquired or attached")]
|
|
|
|
|
|
|
|
LoggerNotInitialized,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// An enum representing the available verbosity levels of the logger.
|
|
|
|
/// An enum representing the available verbosity levels of the logger.
|
|
|
@ -230,6 +232,7 @@ pub struct Builder {
|
|
|
|
timezone_strategy: TimezoneStrategy,
|
|
|
|
timezone_strategy: TimezoneStrategy,
|
|
|
|
max_file_size: u128,
|
|
|
|
max_file_size: u128,
|
|
|
|
targets: Vec<Target>,
|
|
|
|
targets: Vec<Target>,
|
|
|
|
|
|
|
|
is_skip_logger: bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for Builder {
|
|
|
|
impl Default for Builder {
|
|
|
@ -258,6 +261,7 @@ impl Default for Builder {
|
|
|
|
timezone_strategy: DEFAULT_TIMEZONE_STRATEGY,
|
|
|
|
timezone_strategy: DEFAULT_TIMEZONE_STRATEGY,
|
|
|
|
max_file_size: DEFAULT_MAX_FILE_SIZE,
|
|
|
|
max_file_size: DEFAULT_MAX_FILE_SIZE,
|
|
|
|
targets: DEFAULT_LOG_TARGETS.into(),
|
|
|
|
targets: DEFAULT_LOG_TARGETS.into(),
|
|
|
|
|
|
|
|
is_skip_logger: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -339,6 +343,16 @@ impl Builder {
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Skips logger acquisition and attachment. Certain functions such as split will be unusable.
|
|
|
|
|
|
|
|
/// ```rust
|
|
|
|
|
|
|
|
/// tauri_plugin_log::Builder::new()
|
|
|
|
|
|
|
|
/// .skip_logger();
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn skip_logger(mut self) -> Self {
|
|
|
|
|
|
|
|
self.is_skip_logger = true;
|
|
|
|
|
|
|
|
self
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds a collection of targets to the logger.
|
|
|
|
/// Adds a collection of targets to the logger.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// ```rust
|
|
|
@ -481,6 +495,9 @@ impl Builder {
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|
app_handle: &AppHandle<R>,
|
|
|
|
app_handle: &AppHandle<R>,
|
|
|
|
) -> Result<(TauriPlugin<R>, log::LevelFilter, Box<dyn log::Log>), Error> {
|
|
|
|
) -> Result<(TauriPlugin<R>, log::LevelFilter, Box<dyn log::Log>), Error> {
|
|
|
|
|
|
|
|
if self.is_skip_logger {
|
|
|
|
|
|
|
|
return Err(Error::LoggerNotInitialized);
|
|
|
|
|
|
|
|
}
|
|
|
|
let plugin = Self::plugin_builder();
|
|
|
|
let plugin = Self::plugin_builder();
|
|
|
|
let (max_level, log) = Self::acquire_logger(
|
|
|
|
let (max_level, log) = Self::acquire_logger(
|
|
|
|
app_handle,
|
|
|
|
app_handle,
|
|
|
@ -497,17 +514,17 @@ impl Builder {
|
|
|
|
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
|
|
|
|
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
|
|
|
|
Self::plugin_builder()
|
|
|
|
Self::plugin_builder()
|
|
|
|
.setup(move |app_handle, _api| {
|
|
|
|
.setup(move |app_handle, _api| {
|
|
|
|
let (max_level, log) = Self::acquire_logger(
|
|
|
|
if !self.is_skip_logger {
|
|
|
|
app_handle,
|
|
|
|
let (max_level, log) = Self::acquire_logger(
|
|
|
|
self.dispatch,
|
|
|
|
app_handle,
|
|
|
|
self.rotation_strategy,
|
|
|
|
self.dispatch,
|
|
|
|
self.timezone_strategy,
|
|
|
|
self.rotation_strategy,
|
|
|
|
self.max_file_size,
|
|
|
|
self.timezone_strategy,
|
|
|
|
self.targets,
|
|
|
|
self.max_file_size,
|
|
|
|
)?;
|
|
|
|
self.targets,
|
|
|
|
|
|
|
|
)?;
|
|
|
|
attach_logger(max_level, log)?;
|
|
|
|
attach_logger(max_level, log)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.build()
|
|
|
|
.build()
|
|
|
|