Skip to main content

Module logger

Module logger 

Source
Expand description

Turnkey logging for plugins.

Provides a high-level install entry point (wrapped by the enable_logger! and enable_logger_with! macros at the crate root) that wires up:

  • A per-plugin file under logs/{crate}.log with size-based rotation
  • A dual sink to the server’s own log (SA-MP logprintf / open.mp ICore::logLn)
  • A prefix derived from the caller’s CARGO_PKG_NAME (overridable)
  • A runtime-adjustable log level so the plugin can expose its own Pawn-side knob (SetLogLevel, etc.)
  • A startup banner that introspects CARGO_PKG_* at the caller’s site

Plain log::info! / log::warn! / log::error! calls inside the plugin route through this implementation once installed; there is no parallel set of helper macros to remember.

Structs§

BannerMetadata
Manifest fields fed by the macro from the caller’s env! values.
LoggerConfig
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!).
SinkRecord
Single log record handed to a Sink. Borrows from the active log::Record and the SDK’s per-record context — do not retain references past the emit call.

Enums§

BannerMode
What install does when the configuration’s banner is reached.
InstallError
Errors returned by install.

Traits§

Sink
Receiver of formatted log records for forwarding to an external destination chosen by the plugin author — Sentry, an OTLP collector, an in-house HTTP endpoint, a database, anything.

Functions§

flush
Forces the active log file to flush to disk.
install
Installs the SDK logger as the global log implementation.
level
Current threshold — useful for diagnostic natives that want to report the active level back to scripts.
print_banner
Re-emits the default banner after installation. Rarely useful at runtime; kept public so plugins can re-print on demand (for instance, after a Pawn-driven reload). Honours BannerMode::Default regardless of what was supplied to install — custom banners are not memoised, so plugins that need their own format should call log::info! themselves.
set_level
Adjusts the global threshold without reinstalling. Intended for plugin natives that expose a runtime knob — bind it to a Pawn-callable helper such as MyPlugin_SetLogLevel(level).

Type Aliases§

BannerBuilder
Type alias for the custom banner builder — receives the metadata captured by the macro and returns the lines to render.