Skip to main content

LoggerConfig

Struct LoggerConfig 

Source
pub struct LoggerConfig { /* private fields */ }
Expand description

Configuration for install. Built via the fluent setters; defaults are derived from CARGO_PKG_NAME (captured at the caller’s compile time by enable_logger!).

Implementations§

Source§

impl LoggerConfig

Source

pub fn new(crate_name: impl Into<String>) -> Self

Builds a config seeded from the caller’s CARGO_PKG_NAME — the enable_logger! macro is the intended entry point and forwards env!("CARGO_PKG_NAME") here automatically.

Source

pub fn add_sink(self, sink: Box<dyn Sink>) -> Self

Registers an additional Sink that will receive every accepted log record alongside the file and server writes.

The SDK does not install any sink on its own. This builder is the only way a Sink ends up active — calling it is an explicit choice by the plugin author. There is no hidden telemetry, no default destination, no environment variable that flips this on, and no automatic data collection. Server operators auditing what a rust-samp plugin can export only need to grep its source for add_sink( — zero hits means zero external traffic from the logger.

Multiple sinks may be registered; each one receives every record. The order of calls is the order of dispatch.

Sinks run inside the logger’s lock — for HTTP-style backends (Sentry, OTLP, …) forward to a background thread / channel rather than calling the network from emit.

Source

pub fn compress_archives(self, yes: bool) -> Self

Gzip-compresses every rotated archive into {filename}.{N}.gz and removes the uncompressed file. Off by default.

Requires the compression Cargo feature, which pulls in flate2 with the pure-Rust backend. Compression runs synchronously inside the rotation step — for verbose plugins this is a worthwhile trade vs. unbounded disk usage; for low-volume plugins it is usually unnecessary.

Compatible with both rotation strategies (append-style and the rotation_keep(N) shift-style cleanup).

Source

pub fn from_env(self) -> Self

Applies overrides read from environment variables. Lets server operators retune the logger without recompiling the plugin — flip a level, redirect the directory, change the rotation threshold etc. by exporting an env var before starting the server.

The prefix is derived from the crate name passed to LoggerConfig::new (typically CARGO_PKG_NAME) uppercased, with non-alphanumeric characters replaced by _. For a plugin named streamer-rs the prefix is STREAMER_RS_LOG_.

Env varEquivalent builder
<PREFIX>_LOG_LEVEL (off/error/warn/info/debug/trace)level
<PREFIX>_LOG_DIR (path)directory
<PREFIX>_LOG_FILE (filename)filename
<PREFIX>_LOG_ROTATION_MB (u64)rotation_size_mb
<PREFIX>_LOG_ROTATION_KEEP (u32)rotation_keep
<PREFIX>_LOG_NO_ROTATION (1/true)no_rotation
<PREFIX>_LOG_NO_BANNER (1/true)no_banner
<PREFIX>_LOG_SERVER (0/false)also_to_server(false)
<PREFIX>_LOG_COMPRESS (1/true, requires compression feature)compress_archives(true)

Missing env vars leave the existing value untouched, so calling .from_env() at the end of a builder chain treats the env vars as overrides of the code defaults — production wins. Invalid values (unparseable integers, unknown level names) are reported through the server console at startup and the previous value is kept.

Source

pub fn directory(self, path: impl Into<PathBuf>) -> Self

Directory under which the active log file lives. Default: logs/. The path is resolved relative to the server’s working directory. Rotated archives are always placed under {directory}/archive/ — the active log stays directly in directory so the folder root shows only current files.

Source

pub fn filename(self, name: impl Into<String>) -> Self

Filename inside directory. Default: {crate-name}.log.

Source

pub fn prefix(self, prefix: impl Into<String>) -> Self

Prefix prepended to every line written to the server’s log. Default: [{crate-name}]. The plugin’s dedicated file omits the prefix because every line in it already belongs to this plugin.

Source

pub fn level(self, level: LevelFilter) -> Self

Threshold below which log::warn!, log::info! and friends are silently dropped. Default: LevelFilter::Info. Can be adjusted at runtime via set_level.

Source

pub fn also_to_server(self, enabled: bool) -> Self

Whether each log line is also forwarded to the server’s own log (visible in the server console and the server’s main log file). Default: true.

Source

pub fn banner(self, mode: BannerMode) -> Self

Selects the banner strategy. Default: BannerMode::Default (the built-in 5-line banner). Pass BannerMode::Off to suppress every banner line, or BannerMode::Custom to render the lines yourself.

Source

pub fn no_banner(self) -> Self

Shorthand for banner(BannerMode::Off).

Source

pub fn banner_with<F>(self, builder: F) -> Self
where F: Fn(&BannerMetadata) -> Vec<String> + Send + Sync + 'static,

Shorthand for banner(BannerMode::Custom(Box::new(builder))). builder receives the manifest fields captured by the macro and returns the lines to render — each line goes out at Info level through the same pipeline as the rest of the logger.

Source

pub fn file_format(self, format: impl Into<String>) -> Self

Layout for lines written to the plugin’s dedicated log file. Placeholders honoured: {timestamp}, {level}, {message}. Default: "[{timestamp}] [{level}] {message}".

Source

pub fn server_format(self, format: impl Into<String>) -> Self

Layout for lines forwarded to the server console. Placeholders honoured: {prefix}, {level}, {message}. Default: "{prefix} {message}".

Source

pub fn no_rotation(self) -> Self

Disable size-based rotation entirely. The active log file grows indefinitely — only set this if an external rotator (e.g. logrotate) takes over.

Source

pub fn rotation_size_mb(self, mb: u64) -> Self

Threshold at which the active file is rotated, in megabytes. Default: 50 MB. Disables rotation if set to 0.

Whether old archives are deleted is controlled separately by rotation_keep — by default the SDK never deletes; it only renames into the archive directory.

Source

pub fn rotation_keep(self, keep: u32) -> Self

Opts in to size-bounded cleanup: keep the latest keep archives (newest = .log.1, oldest = .log.{keep}) and delete anything older. Total disk footprint becomes (keep + 1) * rotation_size_mb.

Off by default — the SDK never deletes log files unless the dev explicitly requests it.

Source

pub fn rotation_no_cleanup(self) -> Self

Reverts to append-style rotation — every rotated file gets a fresh, never-reused index and the SDK never deletes anything. This is the default; the method exists so a builder chain can undo a previous .rotation_keep(N).

Trait Implementations§

Source§

impl Debug for LoggerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.