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
impl LoggerConfig
Sourcepub fn new(crate_name: impl Into<String>) -> Self
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.
Sourcepub fn add_sink(self, sink: Box<dyn Sink>) -> Self
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.
Sourcepub fn compress_archives(self, yes: bool) -> Self
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).
Sourcepub fn from_env(self) -> Self
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 var | Equivalent 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.
Sourcepub fn directory(self, path: impl Into<PathBuf>) -> Self
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.
Sourcepub fn filename(self, name: impl Into<String>) -> Self
pub fn filename(self, name: impl Into<String>) -> Self
Filename inside directory. Default: {crate-name}.log.
Sourcepub fn prefix(self, prefix: impl Into<String>) -> Self
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.
Sourcepub fn level(self, level: LevelFilter) -> Self
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.
Sourcepub fn also_to_server(self, enabled: bool) -> Self
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.
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.
Shorthand for banner(BannerMode::Off).
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.
Sourcepub fn file_format(self, format: impl Into<String>) -> Self
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}".
Sourcepub fn server_format(self, format: impl Into<String>) -> Self
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}".
Sourcepub fn no_rotation(self) -> Self
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.
Sourcepub fn rotation_size_mb(self, mb: u64) -> Self
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.
Sourcepub fn rotation_keep(self, keep: u32) -> Self
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.
Sourcepub fn rotation_no_cleanup(self) -> Self
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).