pub struct Builder { /* private fields */ }Implementations§
Source§impl Builder
impl Builder
pub fn new() -> Self
Sourcepub fn rotation_strategy(self, rotation_strategy: RotationStrategy) -> Self
pub fn rotation_strategy(self, rotation_strategy: RotationStrategy) -> Self
Sets the RotationStrategy.
Default is RotationStrategy::KeepOne
Sourcepub fn timezone_strategy(self, timezone_strategy: TimezoneStrategy) -> Self
pub fn timezone_strategy(self, timezone_strategy: TimezoneStrategy) -> Self
Sets the TimezoneStrategy.
Calling this method overrides the format set in Self::format.
Default is TimezoneStrategy::UseUtc
Sourcepub fn file_open_strategy(self, file_open_strategy: FileOpenStrategy) -> Self
pub fn file_open_strategy(self, file_open_strategy: FileOpenStrategy) -> Self
Sets the strategy to open the log file.
The default is FileOpenStrategy::Append.
Sourcepub fn max_file_size(self, max_file_size: u128) -> Self
pub fn max_file_size(self, max_file_size: u128) -> Self
Sourcepub fn clear_format(self) -> Self
pub fn clear_format(self) -> Self
Clears the format so that only the message is logged.
e.g. log::info!("message") will log out message
Sourcepub fn format<F>(self, formatter: F) -> Self
pub fn format<F>(self, formatter: F) -> Self
Sets the formatter of this dispatch. The closure should accept a callback, a message and a log record, and write the resulting format to the writer.
The log record is passed for completeness, but the args() method of
the record should be ignored, and the std::fmt::Arguments given
should be used instead. record.args() may be used to retrieve the
original log message, but in order to allow for true log
chaining, formatters should use the given message instead whenever
including the message in the output.
To avoid all allocation of intermediate results, the formatter is
“completed” by calling a callback, which then calls the rest of the
logging chain with the new formatted message. The callback object keeps
track of if it was called or not via a stack boolean as well, so if
you don’t use out.finish the log message will continue down
the logger chain unformatted.
Example usage:
tauri_plugin_log::Builder::new()
.format(|out, message, record| {
out.finish(format_args!(
"[{} {}] {}",
record.level(),
record.target(),
message
))
});Sourcepub fn level(self, level_filter: impl Into<LevelFilter>) -> Self
pub fn level(self, level_filter: impl Into<LevelFilter>) -> Self
Sets the overarching level filter for this logger.
All messages not already filtered by something set by Self::level_for will be affected.
All messages filtered will be discarded if less severe than the given level.
Default level is log::LevelFilter::Trace.
Sourcepub fn level_for(
self,
module: impl Into<Cow<'static, str>>,
level: LevelFilter,
) -> Self
pub fn level_for( self, module: impl Into<Cow<'static, str>>, level: LevelFilter, ) -> Self
Sets a per-target log level filter. Default target for log messages is
crate_name::module_name or
crate_name for logs in the crate root. Targets can also be set with
info!(target: "target-name", ...).
For each log record fern will first try to match the most specific level_for, and then progressively more general ones until either a matching level is found, or the default level is used.
For example, a log for the target hyper::http::h1 will first test a
level_for for hyper::http::h1, then for hyper::http, then for
hyper, then use the default level.
Examples:
A program wants to include a lot of debugging output, but the library “hyper” is known to work well, so debug output from it should be excluded:
tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Trace)
.level_for("hyper", log::LevelFilter::Info)Sourcepub fn filter<F>(self, filter: F) -> Self
pub fn filter<F>(self, filter: F) -> Self
Adds a custom filter which can reject messages passing through this logger.
Self::level and Self::level_for are preferred if applicable.
Example usage:
tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Info)
.filter(|metadata| {
// Reject messages with the `Error` log level.
metadata.level() != log::LevelFilter::Error
})Sourcepub fn clear_targets(self) -> Self
pub fn clear_targets(self) -> Self
Removes all targets. Useful to ignore the default targets and reconfigure them.
Sourcepub fn target(self, target: Target) -> Self
pub fn target(self, target: Target) -> Self
Adds a log target to the logger.
use tauri_plugin_log::{Target, TargetKind};
tauri_plugin_log::Builder::new()
.target(Target::new(TargetKind::Webview));The default targets are
[
Target::new(TargetKind::Stdout),
Target::new(TargetKind::LogDir { file_name: None }),
]Sourcepub fn skip_logger(self) -> Self
pub fn skip_logger(self) -> Self
Skip the creation and global registration of a logger
If you wish to use your own global logger, you must call skip_logger so that the plugin does not attempt to set a second global logger. In this configuration, no logger will be created and the plugin’s log command will rely on the result of log::logger(). You will be responsible for configuring the logger yourself and any included targets will be ignored. If ever initializing the plugin multiple times, such as if registering the plugin while testing, call this method to avoid panicking when registering multiple loggers. For interacting with tracing, you can leverage the tracing-log logger to forward logs to tracing or enable the tracing feature for this plugin to emit events directly to the tracing system. Both scenarios require calling this method.
static LOGGER: SimpleLogger = SimpleLogger;
log::set_logger(&SimpleLogger)?;
log::set_max_level(LevelFilter::Info);
tauri_plugin_log::Builder::new()
.skip_logger();Sourcepub fn targets(self, targets: impl IntoIterator<Item = Target>) -> Self
pub fn targets(self, targets: impl IntoIterator<Item = Target>) -> Self
Replaces the targets of the logger.
use tauri_plugin_log::{Target, TargetKind, WEBVIEW_TARGET};
tauri_plugin_log::Builder::new()
.targets([
Target::new(TargetKind::Webview),
Target::new(TargetKind::LogDir { file_name: Some("webview".into()) }).filter(|metadata| metadata.target().starts_with(WEBVIEW_TARGET)),
Target::new(TargetKind::LogDir { file_name: Some("rust".into()) }).filter(|metadata| !metadata.target().starts_with(WEBVIEW_TARGET)),
]);The default targets are
[
Target::new(TargetKind::Stdout),
Target::new(TargetKind::LogDir { file_name: None }),
]