agentsclimarketplace

Rust logging

Skill longzhi/rust-coding-standards/skills/rust-logging

Use when setting up tracing, configuring log levels, writing structured logs, using spans and instrument, or handling sensitive data in Rust logs.From its SKILL.md

Install
npx -y skills add longzhi/rust-coding-standards --skill rust-logging

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.7 KB, as published. Nobody here has run it

Rust Logging Standards

Core Rules

  • Framework: tracing + tracing-subscriber
  • Format: pretty print in dev, JSON in production
  • Output: stdout
  • Language: all log messages in English

Log Levels

LevelPurposeExample
ERRORRequires alerting and human interventionDatabase connection failed
WARNNeeds attention but system can self-healRetry succeeded after transient failure
INFOBusiness events, visible in productionOrder created/completed
DEBUGDevelopment debugging, disabled in prodSQL queries, intermediate values
TRACEExtreme detail, only for hard-to-diagnose issuesFunction entry/exit
# Production
RUST_LOG=info,my_app=debug

# Development
RUST_LOG=debug,my_app=trace,sqlx=warn

Structured Logging

Use snake_case field names:

tracing::info!(
    request_id = %request_id,
    user_id = %user_id,
    order_id = %order.id,
    duration_ms = elapsed.as_millis() as u64,
    "order completed"
);

Common fields: request_id, user_id, order_id, duration_ms, error, path, method, status

Span Usage

#[tracing::instrument(
    name = "create_order",
    skip(self, cmd),
    fields(user_id = %cmd.user_id, product_id = %cmd.product_id)
)]
pub async fn create_order(&self, cmd: CreateOrderCommand) -> Result<Order, AppError> {
    // ...
}
  • Always skip large or non-Display arguments (self, request bodies, DB pools).
  • Use fields(...) to attach key context to the span.

Sensitive Data

Never log: passwords, API keys, tokens, credit card numbers, personal IDs.

// Use the secrecy crate
use secrecy::Secret;

pub struct Config {
    pub api_key: Secret<String>,  // Displays as [REDACTED] in logs
}

Error Logging

// ERROR: requires alerting
tracing::error!(error = ?err, "database connection failed");

// WARN: needs attention
tracing::warn!(error = ?err, attempt = attempt, "retry after failure");

// INFO: expected business error
tracing::info!(error = %err, "validation failed");
  • ?err — preserves the full error chain (Debug format)
  • %err — logs only the Display message

Checklist

  • Use tracing macros, never println! or log
  • All log messages in English
  • Key business operations logged at INFO level
  • Errors use the correct severity level
  • Include request_id for distributed tracing
  • Sensitive data is redacted
  • Use structured fields instead of string concatenation

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.