Agentic-skills structured-json-logging-best-practices
Comprehensive structured JSON logging framework with schema design, implementation patterns, security considerations, and enterprise best practices for observability and monitoring
git clone https://github.com/GNSubrahmanyam/agentic-skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/GNSubrahmanyam/agentic-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/json-logging" ~/.claude/skills/gnsubrahmanyam-agentic-skills-structured-json-logging-best-practices && rm -rf "$T"
skills/json-logging/SKILL.mdStructured JSON Logging Best Practices
Comprehensive framework for implementing structured JSON logging across applications, covering schema design, framework setup, contextual logging, security, performance optimization, and enterprise integration patterns. Enables machine-readable logs for effective monitoring, debugging, and observability in distributed systems.
When to Apply
Reference these guidelines when:
- Implementing logging in new applications or services
- Migrating from unstructured text logging to structured formats
- Setting up centralized logging and monitoring systems
- Designing log schemas for microservices architectures
- Implementing observability and tracing in distributed systems
- Establishing logging standards across development teams
- Optimizing log performance and storage efficiency
- Ensuring log security and compliance requirements
- Integrating logs with monitoring and alerting systems
Rule Categories by Priority
| Priority | Category | Impact | Files | Rules |
|---|---|---|---|---|
| 1 | Schema Design | CRITICAL | 3 | 9 |
| 2 | Framework Setup | CRITICAL | 3 | 9 |
| 3 | Contextual Logging | HIGH | 3 | 8 |
| 4 | Security & Compliance | HIGH | 2 | 7 |
| 5 | Performance Optimization | MEDIUM-HIGH | 2 | 5 |
| 6 | Integration & Monitoring | MEDIUM-HIGH | 2 | 4 |
| 7 | Migration & Adoption | MEDIUM | 1 | 3 |
| Total | 7 Categories | 12 Files | 45 Rules |
Quick Reference
1. Schema Design (CRITICAL)
: Standard fields for all log entriesschema-base-fields
: Consistent field naming patternsschema-naming-conventions
: Appropriate data types for different valuesschema-data-types
: Request and trace correlationschema-contextual-fields
: Application-specific field definitionsschema-custom-fields
: Schema validation and enforcementschema-validation
2. Framework Setup (CRITICAL)
: Python structured logging with structlogpython-structlog
: Python JSON logging with python-json-loggerpython-json-logger
: Node.js structured logging with Winstonjavascript-winston
: Go structured logging with logrusgo-logrus
: Java structured logging with Logbackjava-logback
: .NET structured logging with Serilogdotnet-serilog
: FastAPI structured logging integrationfastapi-logging
: Django structured logging integrationdjango-logging
: Express.js structured logging middlewareexpress-logging
3. Contextual Logging (HIGH)
: Request and trace ID propagationcorrelation-ids
: User and session context logginguser-context
: Business logic context enrichmentbusiness-context
: Error and exception context captureerror-context
: Performance and timing contextperformance-context
4. Security & Compliance (HIGH)
: Preventing sensitive data in logssensitive-data-protection
: Personal identifiable information maskingpii-masking
: Security event and audit trail loggingaudit-logging
: Compliance-required log fieldscompliance-fields
: Log encryption and secure transportencryption-security
: Log access control and permissionsaccess-control
5. Performance Optimization (MEDIUM-HIGH)
: Efficient log buffering and batchinglog-buffering
: Non-blocking asynchronous loggingasync-logging
: Log compression for storage efficiencylog-compression
: Log sampling for high-volume scenariossampling-strategies
: Memory and CPU limits for loggingresource-limits
6. Integration & Monitoring (MEDIUM-HIGH)
: ELK stack structured logging integrationelk-integration
: Log-based metrics and alertingprometheus-metrics
: Distributed tracing integrationopentelemetry-tracing
: Centralized log aggregation patternslog-aggregation
7. Migration & Adoption (MEDIUM)
: Gradual migration from unstructured loggingmigration-strategy
: Integrating with existing logging systemslegacy-integration
: Team training and adoption strategiesteam-adoption
How to Use
Read individual rule files for detailed explanations and code examples:
rules/schema-base-fields.md # Standard log schema rules/python-structlog.md # Python implementation rules/correlation-ids.md # Request correlation rules/sensitive-data-protection.md # Security best practices rules/elk-integration.md # ELK stack integration
Each rule file contains:
- Impact level and category
- Problem description with consequences
- Solution with code examples
- Common mistakes to avoid
- When to apply the rule
Reference Documentation
Detailed guides for complex topics:
references/log-schema-design.md # Complete log schema design references/framework-comparison.md # Logging framework comparison references/enterprise-patterns.md # Enterprise logging patterns
Full Compiled Document
For the complete structured JSON logging guide with all rules expanded:
AGENTS.md
Structured JSON Logging Version: Compatible with modern logging frameworks and ELK stack Focus: Production-ready, enterprise-grade logging for observability and monitoring</content> <parameter name="filePath">skills/structured-json-logging-skill/SKILL.md