Skip to main content

Crate rustlavel_audit

Crate rustlavel_audit 

Source
Expand description

Audit logging: who did what, to which record, from where, and when.

Different from the application log on purpose. A log line is for whoever is debugging; an audit entry is a record somebody may be asked about a year later — “who deleted that account?” — and it therefore lives in the database, beside the data it describes, rather than in a file that rotates.

ⓘ
App::new().plugin(Audit::new(db.clone()))
// and in the registry the CLI generates:
registry.extend(rustlavel_audit::migrations());

Then, from anywhere with a request:

ⓘ
use rustlavel_audit::AuditExt;

req.audit("users.deleted")
    .on("User", user.id)
    .describe(format!("{} deleted {}", actor, user.name))
    .with("email", Json::from(user.email.as_str()))
    .save()
    .await?;

What the builder does not let you do is forget the context. The actor, the address and the user agent are read off the request rather than passed in, because an entry that says “someone updated the settings” answers nothing, and a caller in a hurry is exactly who writes that entry.

Re-exports§

pub use entry::Builder;
pub use entry::Entry;
pub use plugin::Audit;
pub use plugin::AuditExt;
pub use store::Filter;
pub use store::Page;
pub use store::Trail;
pub use tables::TABLE;
pub use tables::migrations;

Modules§

entry
One audit entry, and the builder that fills it in.
plugin
Attaching the package to an application, and reaching it from a handler.
prelude
What an application file usually needs from this package.
store
Reading and writing the trail.
tables
The one table, and its migration.