An open API service indexing awesome lists of open source software.

https://github.com/cloudresty/emit

Structured logging library for Go applications with built-in security features and industry-leading performance
https://github.com/cloudresty/emit

Last synced: about 1 month ago
JSON representation

Structured logging library for Go applications with built-in security features and industry-leading performance

Awesome Lists containing this project

README

          

# Emit

A lightweight, structured logging library for Go applications with **built-in security features** and **industry-leading** performance. Emit provides automatic PII/sensitive data masking while outperforming all major logging libraries.

 

[![Go Reference](https://pkg.go.dev/badge/github.com/cloudresty/emit.svg)](https://pkg.go.dev/github.com/cloudresty/emit)
[![Go Tests](https://github.com/cloudresty/emit/actions/workflows/test.yaml/badge.svg)](https://github.com/cloudresty/emit/actions/workflows/test.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/cloudresty/emit)](https://goreportcard.com/report/github.com/cloudresty/emit)
[![GitHub Tag](https://img.shields.io/github/v/tag/cloudresty/emit?label=Version)](https://github.com/cloudresty/emit/tags)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

 

- **Automatic data protection** - PII and sensitive data masked by default
- **Elegant API** - `emit.Info.Msg()` for simplicity, `emit.Info.Field()` for structure

 

## Why Choose Emit?

### Clean, Simple API

```go
// Payment logging with built-in PCI DSS compliance
emit.Info.Field("Payment processed",
emit.NewFields().
String("transaction_id", "txn_abc123").
String("card_number", "4111-1111-1111-1111"). // Auto-masked
String("cardholder", "John Doe"). // Auto-masked
Float64("amount", 99.99).
String("currency", "USD").
Bool("success", true))
```

 

🔝 [back to top](#emit)

 

```go
// Crystal clear intent - no cryptic function names
emit.Info.Field("User authenticated",
emit.NewFields().
String("user_id", "12345").
String("email", "user@example.com"). // Auto-masked: "***PII***"
Bool("success", true))

// Simple key-value pairs
emit.Error.KeyValue("Payment failed",
"transaction_id", "txn_123",
"amount", 99.99,
"card_number", "4111-1111-1111-1111") // Auto-masked: "***PII***"
```

 

🔝 [back to top](#emit)

 

### Zero-Config Security

Automatic protection of sensitive data without any configuration:

```go
emit.Info.Field("User registration",
emit.NewFields().
String("email", "user@example.com"). // → "***PII***"
String("password", "secret123"). // → "***MASKED***"
String("api_key", "sk-1234567890"). // → "***MASKED***"
String("username", "john_doe"). // → "john_doe" (safe)
Int("user_id", 12345)) // → 12345 (safe)
```

 

🔝 [back to top](#emit)

 

## Installation

```bash
go get github.com/cloudresty/emit
```

 

🔝 [back to top](#emit)

 

## Quick Start

```go
package main

import (
"time"
"github.com/cloudresty/emit"
)

func main() {

// Clean, self-documenting API ✨

// Structured logging with clear intent
emit.Info.Field("User registration",
emit.NewFields().
String("email", "user@example.com"). // Auto-masked
String("username", "john_doe").
Int("user_id", 67890).
Bool("newsletter", true).
Time("created_at", time.Now()))

// Simple key-value pairs
emit.Error.KeyValue("Payment failed",
"transaction_id", "txn_123",
"amount", 29.99,
"currency", "USD")

// Ultra-fast structured field logging
emit.Warn.StructuredFields("High memory usage",
emit.ZString("service", "database"),
emit.ZFloat64("memory_percent", 87.5))

// Memory-pooled high-performance logging
emit.Debug.Pool("Database operation", func(pf *emit.PooledFields) {
pf.String("query", "SELECT * FROM users").
Int("rows", 1234).
Float64("duration_ms", 15.7)
})

// Simple messages
emit.Info.Msg("Application started successfully")
}
```

 

**JSON Output (Production):**

```json
{"timestamp":"2025-06-11T10:30:45.123456789Z","level":"info","message":"User registration","fields":{"email":"***PII***","username":"john_doe","user_id":67890,"newsletter":true,"created_at":"2025-06-11T10:30:45.123456789Z"}}
{"timestamp":"2025-06-11T10:30:45.124567890Z","level":"error","message":"Payment failed","fields":{"transaction_id":"txn_123","amount":29.99,"currency":"USD"}}
```

 

🔝 [back to top](#emit)

 

## Elegant API Overview

Every logging level (`Info`, `Error`, `Warn`, `Debug`) provides the same clean, consistent interface:

```go
// All levels support the same methods
emit.Info.Msg(msg) // Simple message
emit.Info.Field(msg, fields) // Structured fields
emit.Info.StructuredFields(msg, zfields...) // Ultra-fast structured fields (Zap-compatible)
emit.Info.KeyValue(msg, k, v, ...) // Key-value pairs
emit.Info.Pool(msg, func) // Memory-pooled performance

// Same elegant API for all levels
emit.Error.Field(msg, fields) // Error with structured data
emit.Warn.KeyValue(msg, k, v, ...) // Warning with key-values
emit.Debug.StructuredFields(msg, zfields...) // Debug with structured fields
```

 

🔝 [back to top](#emit)

 

## Key Features

### Built-in Security

- **Automatic PII masking** - Emails, phone numbers, addresses protected by default
- **Sensitive data protection** - Passwords, API keys, tokens automatically masked
- **GDPR/CCPA compliant** - Built-in compliance with privacy regulations
- **Zero data leaks** - Impossible to accidentally log sensitive information

 

### Performance Optimized

- **63.0 ns/op simple logging** - 23% faster than Zap
- **96.0 ns/op structured fields** - 33% faster than Zap with zero allocations
- **Zero-allocation API** - `StructuredFields()` methods achieve 0 B/op, 0 allocs/op
- **Memory pooling** - `Pool()` methods for high-throughput scenarios

 

### Developer Friendly

- **Elegant API** - Clear, self-documenting method names
- **IDE-friendly** - Perfect autocomplete with `emit.Info.` discovery
- **Zero dependencies** - Uses only Go standard library
- **Environment-aware** - JSON for production, plain text for development

 

🔝 [back to top](#emit)

 

## Documentation

 

### Complete Guides

- **[API Reference](docs/API_REFERENCE.md)** - Complete examples for all logging methods
- **[Security Guide](docs/SECURITY.md)** - Security features and compliance examples
- **[Performance Guide](docs/PERFORMANCE.md)** - Benchmarks and optimization strategies
- **[Migration Guide](docs/MIGRATION.md)** - Migrate from other logging libraries
- **[Benchmark Results](benchmarks/benchmark-results.md)** - Detailed performance comparisons

 

🔝 [back to top](#emit)

 

### Environment Configuration

```bash
# Production (secure by default)
export EMIT_FORMAT=json
export EMIT_LEVEL=info
# PII and sensitive masking enabled automatically

# Development (show data for debugging)
export EMIT_FORMAT=plain
export EMIT_LEVEL=debug
export EMIT_MASK_SENSITIVE=false
export EMIT_MASK_PII=false
```

 

🔝 [back to top](#emit)

 

### Programmatic Setup

```go
// Quick setup
emit.SetComponent("user-service")
emit.SetVersion("v2.1.0")
emit.SetLevel("info")

// Production mode (secure, JSON, info level)
emit.SetProductionMode()

// Development mode (show data, plain text, debug level)
emit.SetDevelopmentMode()
```

 

🔝 [back to top](#emit)

 

## Real-World Examples

### Microservice Logging

```go
// Service initialization
emit.SetComponent("auth-service")
emit.SetVersion("v1.2.3")

// Request logging with automatic security
emit.Info.Field("API request",
emit.NewFields().
String("method", "POST").
String("endpoint", "/api/login").
String("user_email", userEmail). // Auto-masked
String("client_ip", clientIP). // Auto-masked
Int("status_code", 200).
Duration("response_time", duration))
```

 

🔝 [back to top](#emit)

 

### Payment Processing

```go
// Payment logging with built-in PCI DSS compliance
emit.Info.Field("Payment processed",
emit.NewFields().
String("transaction_id", "txn_abc123").
String("card_number", "4111-1111-1111-1111"). // Auto-masked
String("cardholder", "John Doe"). // Auto-masked
Float64("amount", 99.99).
String("currency", "USD").
Bool("success", true))
```

 

🔝 [back to top](#emit)

 

### High-Performance Logging

```go
// Ultra-fast logging for hot paths
func processRequest() {
start := time.Now()

// ... request processing

emit.Debug.StructuredFields("Request processed",
emit.ZString("endpoint", "/api/data"),
emit.ZInt("status", 200),
emit.ZDuration("duration", time.Since(start)))
}
```

 

🔝 [back to top](#emit)

 

## Migration from Other Loggers

### From Standard Log

```go
// Before (UNSAFE)
log.Printf("User %s with password %s logged in", username, password)

// After (SECURE)
emit.Info.KeyValue("User logged in",
"username", username, // Auto-protected if PII
"password", password) // Auto-masked
```

 

🔝 [back to top](#emit)

 

### From Logrus

```go
// Before (manual security)
logrus.WithFields(logrus.Fields{
"email": maskEmail(email), // Manual masking required!
}).Info("User action")

// After (automatic security)
emit.Info.Field("User action",
emit.NewFields().
String("email", email)) // Auto-masked
```

 

🔝 [back to top](#emit)

 

### From Zap

```go
// Before (complex, manual security)
logger.Info("Payment",
zap.String("email", maskPII(email)), // Manual masking!
zap.String("card", maskSensitive(card))) // Manual masking!

// After (simple, automatic security)
emit.Info.KeyValue("Payment processed",
"email", email, // Auto-masked
"card", card) // Auto-masked
```

 

🔝 [back to top](#emit)

 

## Compliance & Security

### Automatic Compliance

- **✅ GDPR** - EU personal data automatically protected
- **✅ CCPA** - California privacy law compliance
- **✅ HIPAA** - Healthcare data protection (with custom fields)
- **✅ PCI DSS** - Payment card data automatically masked

 

🔝 [back to top](#emit)

 

### Protected Data Types

**PII (Automatically Masked as `***PII***`)**

- Email addresses, phone numbers, names
- Addresses, IP addresses, credit cards
- SSN, passport numbers, driver licenses

**Sensitive Data (Automatically Masked as `***MASKED***`)**

- Passwords, PINs, API keys
- Access tokens, private keys, certificates
- Session IDs, authorization headers

 

🔝 [back to top](#emit)

 

## Why Emit is the Secure Choice

### Traditional Loggers

- ❌ Manual data protection required
- ❌ Easy to accidentally log sensitive data
- ❌ Complex setup for production security
- ❌ Risk of compliance violations

 

### Emit in a Nutshell

- ✅ Automatic data protection out of the box
- ✅ Impossible to accidentally expose PII/sensitive data
- ✅ Zero-config security for production
- ✅ Built-in compliance with privacy regulations
- ✅ Elegant, developer-friendly API
- ✅ Performance optimized for production workloads

 

🔝 [back to top](#emit)

 

## Real-World Impact Summary

### Security: The Hidden Cost of Traditional Loggers

When choosing a logging library, most developers focus solely on performance metrics. However, **security vulnerabilities in logging are among the most common causes of data breaches in production applications**:

- **Data Breach Risk**: Traditional loggers like Zap and Logrus require developers to manually mask sensitive data. A single oversight can expose passwords, API keys, or PII in log files.
- **Compliance Violations**: GDPR fines can reach €20M or 4% of annual revenue. CCPA violations cost up to $7,500 per record. Emit's automatic masking prevents these costly violations.
- **Developer Burden**: Manual masking increases development time and introduces bugs. Emit eliminates this overhead entirely.

 

🔝 [back to top](#emit)

 

### Performance: Security Without Compromise

**Traditional Assumption**: "Security features must sacrifice performance"
**Emit Reality**: Built-in security with industry-leading speed

Our benchmarks demonstrate that Emit's automatic security features add **zero performance overhead** compared to manual implementations: [Benchmark results](benchmarks/benchmark-results.md).

**Key Insight**: Emit with automatic security (213 ns/op) is significantly faster than Logrus without any security protection (2,872 ns/op), and competitive with Zap's unsafe mode (171 ns/op) while providing complete data protection.

 

🔝 [back to top](#emit)

 

### Production Impact: Beyond Benchmarks

#### Traditional Logging Workflow

1. Write logging code
2. Manually identify sensitive fields
3. Implement custom masking functions
4. Review code for security issues
5. Test masking implementations
6. Monitor for data leaks in production
7. **Risk**: One missed field = potential breach

 

🔝 [back to top](#emit)

 

#### Emit Workflow

1. Write logging code
2. **Done** - Security is automatic and guaranteed

 

🔝 [back to top](#emit)

 

#### Cost Analysis

**Medium-sized application (10 developers, 2-year development cycle)**:

```plaintext
Traditional Loggers:
- Security implementation time: 40 hours/developer = 400 hours
- Security review overhead: 20% of logging code reviews = 80 hours
- Bug fixes for missed masking: 20 hours
- Total: 500 hours × $150/hour = $75,000

Emit:
- Security implementation time: 0 hours (automatic)
- Security review overhead: 0 hours (automatic)
- Bug fixes: 0 hours (impossible to leak data)
- Total: $0

ROI: $75,000 saved + zero breach risk
```

 

🔝 [back to top](#emit)

 

### When to Choose Each Approach

**Choose Emit when**:

- Building production applications with sensitive data
- Compliance requirements (GDPR, CCPA, HIPAA, PCI DSS)
- Team includes junior developers
- Performance is critical
- Development speed matters

**Choose traditional loggers when**:

- Working with completely non-sensitive data
- You have dedicated security experts on your team
- You enjoy implementing custom security solutions
- Vendor lock-in concerns outweigh security benefits

**Bottom Line**: Emit delivers the security of enterprise logging solutions with the performance of the fastest libraries and the simplicity of modern APIs.

 

🔝 [back to top](#emit)

 

## Get Started

1. **Install**: `go get github.com/cloudresty/emit`
2. **Basic usage**: `emit.Info.Msg("Hello, secure world!")`
3. **Add structure**: `emit.Info.KeyValue("User action", "user_id", 123)`
4. **Go advanced**: `emit.Info.Field("Complex event", emit.NewFields()...)`
5. **Optimize performance**: `emit.Info.StructuredFields("Hot path", emit.ZString(...))`

**Choose emit for secure, compliant, and elegant logging in your Go applications.**

 

🔝 [back to top](#emit)

 

## Performance Breakthrough: Zero-Allocation Structured Fields

Emit achieves what was previously thought impossible in Go logging - **zero heap allocations** for structured field logging while maintaining full compatibility with Zap-style APIs.

```go
// Zero-allocation structured logging (Zap-compatible API)
emit.Info.StructuredFields("User action", // 96 ns/op, 0 B/op, 0 allocs/op
emit.ZString("user_id", "12345"),
emit.ZString("action", "login"),
emit.ZString("email", "user@example.com"), // → "***MASKED***" (automatic)
emit.ZBool("success", true))

// Compare with Zap (requires heap allocations)
zapLogger.Info("User action", // 143 ns/op, 259 B/op, 1 allocs/op
zap.String("user_id", "12345"),
zap.String("action", "login"),
zap.String("email", "user@example.com"), // → "user@example.com" (exposed!)
zap.Bool("success", true))
```

 

🔝 [back to top](#emit)

 

**Performance Comparison:**

- **33% faster** than Zap's structured logging
- **Zero memory allocations** vs Zap's heap allocations
- **Built-in security** vs manual implementation required

🔝 [back to top](#emit)

 

 

---

### Cloudresty

[Website](https://cloudresty.com)  |  [LinkedIn](https://www.linkedin.com/company/cloudresty)  |  [BlueSky](https://bsky.app/profile/cloudresty.com)  |  [GitHub](https://github.com/cloudresty)  |  [Docker Hub](https://hub.docker.com/u/cloudresty)

© Cloudresty - All rights reserved