Skip to content
Back to skills

Usage Logging

ASecurity

Implements structured usage logging and audit trails for cost and session tracking. Use when adding audit trails, usage analytics, or cost tracking to a skill.

  • 342 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added December 19, 2025
devopspythongobashrailsdebugging

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 20, 2026

npx -y skills add athola/claude-night-market --skill usage-logging --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Usage Logging?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Usage Logging
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/athola-usage-logging/badge)](https://www.skillsdirectory.com/skills/athola-usage-logging)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: usage-logging
description: Implements structured usage logging and audit trails for cost and session tracking. Use when adding audit trails, usage analytics, or cost tracking to a skill.
alwaysApply: false
category: infrastructure
tags:
- logging
- usage
- audit
- metrics
- sessions
- analytics
dependencies: []
tools: []
provides:
  infrastructure:
  - usage-logging
  - session-management
  - audit-trails
  patterns:
  - structured-logging
  - metrics-collection
  - cost-tracking
usage_patterns:
- audit-logging
- cost-tracking
- usage-analytics
- session-management
complexity: beginner
model_hint: fast
estimated_tokens: 450
progressive_loading: true
modules:
- modules/session-patterns.md
- modules/log-formats.md
---

# Usage Logging

## Overview

Records individual call costs and usage events. For aggregate budget
enforcement, use quota-management.

Session-aware logging infrastructure for tracking operations across plugins.
Provides structured JSONL logging with automatic session management for
audit trails and analytics.

## When To Use

- Need audit trails for operations
- Tracking costs across sessions
- Building usage analytics
- Debugging with operation history

## When NOT To Use

- Simple operations without logging needs

## Core Concepts

### Session Management

Sessions group related operations:
- Auto-created on first operation
- Timeout after 1 hour of inactivity
- Unique session IDs for tracking

### Log Entry Structure

```json
{
  "timestamp": "2025-12-05T10:30:00Z",
  "session_id": "session_1733394600",
  "service": "my-service",
  "operation": "analyze_files",
  "tokens": 5000,
  "success": true,
  "duration_seconds": 2.5,
  "metadata": {}
}
```
**Verification:** Run the command with `--help` flag to verify availability.

## Quick Start

### Initialize Logger
```python
from leyline.usage_logger import UsageLogger

logger = UsageLogger(service="my-service")
```
**Verification:** Run the command with `--help` flag to verify availability.

### Log Operations
```python
logger.log_usage(
    operation="analyze_files",
    tokens=5000,
    success=True,
    duration=2.5,
    metadata={"files": 10},
)
```
**Verification:** Run the command with `--help` flag to verify availability.

### Query Usage
```python
# Recent operations
recent = logger.get_recent_operations(hours=24)

# Usage summary
summary = logger.get_usage_summary(days=7)
print(f"Total tokens: {summary['total_tokens']}")
print(f"Total cost: ${summary['estimated_cost']:.2f}")

# Recent errors
errors = logger.get_recent_errors(count=10)
```
**Verification:** Run the command with `--help` flag to verify availability.

## Integration Pattern

```yaml
# In your skill's frontmatter
dependencies: [leyline:usage-logging]
```
**Verification:** Run the command with `--help` flag to verify availability.

Standard integration flow:
1. Initialize logger for your service
2. Log operations after completion
3. Query for analytics and debugging

## Log Storage

Default location: `~/.claude/leyline/usage/{service}.jsonl`

```bash
# View recent logs
tail -20 ~/.claude/leyline/usage/my-service.jsonl | jq .

# Query by date
grep "2025-12-05" ~/.claude/leyline/usage/my-service.jsonl
```
**Verification:** Run the command with `--help` flag to verify availability.

## Detailed Resources

- **Session Patterns**: See `modules/session-patterns.md` for session management
- **Log Formats**: See `modules/log-formats.md` for structured formats

## Exit Criteria

- Operation logged with all required fields
- Session tracked for grouping
- Logs queryable for analytics

Files in this skill

  • SKILL.md2.9 KB
  • modules/log-formats.md1.5 KB
  • modules/session-patterns.md2.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…