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.
Β
Β
- Automatic data protection - PII and sensitive data masked by default
- Elegant API -
emit.Info.Msg()
for simplicity,emit.Info.Field()
for structure
Β
// 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
Β
// Crystal clear intent - no cryptic function names
emit.Info.Field("User authenticated",
emit.NewFields().
String("user_id", "12345").
String("email", "[email protected]"). // 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
Β
Automatic protection of sensitive data without any configuration:
emit.Info.Field("User registration",
emit.NewFields().
String("email", "[email protected]"). // β "***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
Β
go get github.com/cloudresty/emit
π back to top
Β
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", "[email protected]"). // 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):
{"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
Β
Every logging level (Info
, Error
, Warn
, Debug
) provides the same clean, consistent interface:
// 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
Β
- 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
Β
- 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
Β
- 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
Β
Β
- API Reference - Complete examples for all logging methods
- Security Guide - Security features and compliance examples
- Performance Guide - Benchmarks and optimization strategies
- Migration Guide - Migrate from other logging libraries
- Benchmark Results - Detailed performance comparisons
π back to top
Β
# 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
Β
// 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
Β
// 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
Β
// 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
Β
// 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
Β
// 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
Β
// 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
Β
// 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
Β
- β 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
Β
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
Β
- β Manual data protection required
- β Easy to accidentally log sensitive data
- β Complex setup for production security
- β Risk of compliance violations
Β
- β 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
Β
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
Β
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.
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
Β
- Write logging code
- Manually identify sensitive fields
- Implement custom masking functions
- Review code for security issues
- Test masking implementations
- Monitor for data leaks in production
- Risk: One missed field = potential breach
π back to top
Β
- Write logging code
- Done - Security is automatic and guaranteed
π back to top
Β
Medium-sized application (10 developers, 2-year development cycle):
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
Β
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
Β
- Install:
go get github.com/cloudresty/emit
- Basic usage:
emit.Info.Msg("Hello, secure world!")
- Add structure:
emit.Info.KeyValue("User action", "user_id", 123)
- Go advanced:
emit.Info.Field("Complex event", emit.NewFields()...)
- 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 achieves what was previously thought impossible in Go logging - zero heap allocations for structured field logging while maintaining full compatibility with Zap-style APIs.
// 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", "[email protected]"), // β "***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", "[email protected]"), // β "[email protected]" (exposed!)
zap.Bool("success", true))
π back to top
Β
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
Β
MIT License - see LICENSE file for details.
Β
Β
An open source project brought to you by the Cloudresty team.
Website Β |Β LinkedIn Β |Β BlueSky Β |Β GitHub
Β