audit-logging

A set of Java rules for recording important business operations with a dedicated audit logger. Audit logs are separate from ordinary application logs and support security or compliance reviews.

In plain words
What is it for?
Use it when service code performs significant operations that need a structured record of the action, actor, time, and related details.
Why use it?
It prevents audit records from being formatted inconsistently or mixed with debug and error messages.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/e-gov/cursor-prompts/audit-logging
Clone the repo
git clone --depth 1 https://github.com/e-gov/cursor-prompts
Per session 1,298 This file is loaded in full into every session.
When invoked 1,298 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01298 $0.01298
Opus 5 $0.00649 $0.00649
Sonnet 5 $0.00260 $0.00260
Haiku 4.5 $0.00130 $0.00130

Measured 3d ago against content hash fba726cc26c3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

audit-logging scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/java-common/audit-logging.mdc · 161 lines

How it starts

The opening of the file, as written. The whole thing — 161 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Audit Logging Conventions

Context

  • Apply when implementing significant business operations within service classes (src/main/java/**/service/**/*.java) that require an audit trail.
  • This application uses a dedicated AuditLogger utility to ensure consistent, structured logging of important events for security and compliance.
  • Audit logs are separate from regular application/debug logs.
  • For comprehensive security best practices, see [security.mdc](mdc:rules/common/security.mdc).

Standard Log Structure

Using the AuditLogger utility ensures logs are generated in the following standard JSON format. Developers do not construct this JSON manually.

{
  "correlationId": "550e8400-e29b-41d4-a716-446655440000",
  "time": "2023-04-04T12:34:56.123456Z",
  "application": {
    "name": "bookstore-service",
    "extraInfo": {
      "environment": "dev"
    }
  },
  "activity": {
    "action": "BOOK_UPDATED", // Example action
    "extraInfo": { // Action-specific details
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "oldTitle": "The Old Title",
      "newTitle": "The New Title"
      // ... other relevant fields ...
    }
  },
  "actor": {
    "name": "system" // Or user identifier
  },
  "client": {
    "id": "bookstore-app",
    "source": "INTERNAL"
  },
  "result": {
    "code": "SUCCESS",
    "message": "Operation completed successfully"
  }
}

Requirements

  • Use AuditLogger: ALL audit log entries MUST be generated using the static methods provided by the AuditLogger utility class.
  • Log Significant Business Events: Only log high-level, meaningful business operations (e.g., resource creation, update, deletion, key access), not low-level implementation details.
  • Log After Success: Audit log entries for successful operations MUST be created after the core business logic (e.g., database commit) has completed successfully within the same transaction context.
  • Do Not Log Sensitive Data: Avoid including sensitive personal information (e.g., passwords, detailed financial data, PII unless strictly necessary and compliant with regulations) in audit log messages or extraInfo fields. Redact or omit if necessary.
  • Use Correct Methods: Use the appropriate AuditLogger method for the event type.
  • Log All Authentication Attempts: ALL authentication attempts MUST be logged regardless of outcome (login, logout, failed authentication, session timeout).
  • Log All User-Initiated Activities: ALL user-initiated activities MUST be logged (CRUD operations, searches, file uploads, exports).

Read the full file on GitHub · 161 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 161 lines · 1,298 tokens per session scan A fba726cc26c3

Subscribe to this mod's changes

audit-logging is a cursor rule published in the GitHub repository e-gov/cursor-prompts (34 stars, last pushed 4mo ago), licensed MIT. It adds 1,298 tokens to every session, about $0.0065 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.